#include <Log_Msg_UNIX_Syslog.h>
Inheritance diagram for ACE_Log_Msg_UNIX_Syslog:


Public Member Functions | |
| ACE_Log_Msg_UNIX_Syslog (void) | |
| Constructor. | |
| virtual | ~ACE_Log_Msg_UNIX_Syslog (void) |
| Destructor. | |
| virtual int | open (const ACE_TCHAR *logger_key) |
| Open a new event log. | |
| virtual int | reset (void) |
| Reset the backend. | |
| virtual int | close (void) |
| Close the backend completely. | |
| virtual ssize_t | log (ACE_Log_Record &log_record) |
| This is called when we want to log a message. | |
Private Member Functions | |
| int | convert_log_priority (ACE_UINT32 lm_priority) |
| Convert an ACE_Log_Priority value to the corresponding syslog priority. | |
| int | convert_log_mask (int lm_mask) |
| Convert an ACE_Log_Priority mask to the corresponding syslog mask value. | |
Definition at line 35 of file Log_Msg_UNIX_Syslog.h.
|
|
Constructor.
Definition at line 27 of file Log_Msg_UNIX_Syslog.cpp.
00028 {
00029 }
|
|
|
Destructor.
Definition at line 31 of file Log_Msg_UNIX_Syslog.cpp. References close().
00032 {
00033 (void) this->close ();
00034 }
|
|
|
Close the backend completely.
Implements ACE_Log_Msg_Backend. Definition at line 76 of file Log_Msg_UNIX_Syslog.cpp. Referenced by reset(), and ~ACE_Log_Msg_UNIX_Syslog().
00077 {
00078 closelog();
00079 return 0;
00080 }
|
|
|
Convert an ACE_Log_Priority mask to the corresponding syslog mask value.
Definition at line 171 of file Log_Msg_UNIX_Syslog.cpp. References ACE_BIT_ENABLED, ACE_SET_BITS, LM_ALERT, LM_CRITICAL, LM_DEBUG, LM_EMERGENCY, LM_ERROR, LM_INFO, LM_NOTICE, LM_SHUTDOWN, LM_STARTUP, LM_TRACE, and LM_WARNING.
00172 {
00173 int syslog_mask = 0;
00174
00175 if (ACE_BIT_ENABLED (lm_mask, LM_TRACE)
00176 || ACE_BIT_ENABLED (lm_mask, LM_DEBUG))
00177 ACE_SET_BITS (syslog_mask, LOG_MASK(LOG_DEBUG));
00178
00179 if (ACE_BIT_ENABLED (lm_mask, LM_STARTUP)
00180 || ACE_BIT_ENABLED (lm_mask, LM_SHUTDOWN)
00181 || ACE_BIT_ENABLED (lm_mask, LM_INFO))
00182 ACE_SET_BITS (syslog_mask, LOG_MASK(LOG_INFO));
00183
00184 if (ACE_BIT_ENABLED (lm_mask, LM_NOTICE))
00185 ACE_SET_BITS (syslog_mask, LOG_MASK(LOG_NOTICE));
00186
00187 if (ACE_BIT_ENABLED (lm_mask, LM_ERROR))
00188 ACE_SET_BITS (syslog_mask, LOG_MASK(LOG_ERR));
00189
00190 if (ACE_BIT_ENABLED (lm_mask, LM_WARNING))
00191 ACE_SET_BITS (syslog_mask, LOG_MASK(LOG_WARNING));
00192
00193 if (ACE_BIT_ENABLED (lm_mask, LM_CRITICAL))
00194 ACE_SET_BITS (syslog_mask, LOG_MASK(LOG_CRIT));
00195
00196 if (ACE_BIT_ENABLED (lm_mask, LM_ALERT))
00197 ACE_SET_BITS (syslog_mask, LOG_MASK(LOG_ALERT));
00198
00199 if (ACE_BIT_ENABLED (lm_mask, LM_EMERGENCY))
00200 ACE_SET_BITS (syslog_mask, LOG_MASK(LOG_EMERG));
00201
00202 return syslog_mask;
00203 }
|
|
|
Convert an ACE_Log_Priority value to the corresponding syslog priority.
Definition at line 132 of file Log_Msg_UNIX_Syslog.cpp. References LM_ALERT, LM_CRITICAL, LM_DEBUG, LM_EMERGENCY, LM_ERROR, LM_INFO, LM_NOTICE, LM_SHUTDOWN, LM_STARTUP, LM_TRACE, and LM_WARNING. Referenced by log().
00133 {
00134 int syslog_priority;
00135 switch (lm_priority)
00136 {
00137 case LM_TRACE:
00138 case LM_DEBUG:
00139 syslog_priority = LOG_DEBUG;
00140 break;
00141 case LM_STARTUP:
00142 case LM_SHUTDOWN:
00143 case LM_INFO:
00144 syslog_priority = LOG_INFO;
00145 break;
00146 case LM_NOTICE:
00147 syslog_priority = LOG_NOTICE;
00148 break;
00149 case LM_WARNING:
00150 syslog_priority = LOG_WARNING;
00151 break;
00152 case LM_CRITICAL:
00153 syslog_priority = LOG_CRIT;
00154 break;
00155 case LM_ALERT:
00156 syslog_priority = LOG_ALERT;
00157 break;
00158 case LM_EMERGENCY:
00159 syslog_priority = LOG_EMERG;
00160 break;
00161 case LM_ERROR:
00162 default:
00163 syslog_priority = LOG_ERR;
00164 break;
00165 }
00166
00167 return syslog_priority;
00168 }
|
|
|
This is called when we want to log a message.
Implements ACE_Log_Msg_Backend. Definition at line 83 of file Log_Msg_UNIX_Syslog.cpp. References ACE_BIT_ENABLED, ACE_LOG_MSG, ACE_Log_Priority, ACE_TCHAR, ACE_TEXT, ACE_TEXT_ALWAYS_CHAR, convert_log_priority(), ACE_Log_Record::msg_data(), ACE_Log_Record::priority_name(), ACE_OS::strcpy(), ACE_OS::strtok_r(), ACE::timestamp(), and ACE_Log_Record::type().
00084 {
00085 int syslog_priority = this->convert_log_priority (log_record.type ());
00086 u_long flags = ACE_LOG_MSG->flags ();
00087
00088 // The UNIX syslog() facility does not support multi-line messages.
00089 // Break up the message data into separate lines and send each line
00090 // to the syslog daemon.
00091
00092 ACE_TCHAR message[ACE_Log_Record::MAXVERBOSELOGMSGLEN];
00093 ACE_OS::strcpy (message, log_record.msg_data ());
00094 ACE_TCHAR *strtokp = 0;
00095
00096 for (ACE_TCHAR *line = ACE_OS::strtok_r (message,
00097 ACE_TEXT ("\n"),
00098 &strtokp);
00099 line != 0;
00100 line = ACE_OS::strtok_r (0,
00101 ACE_TEXT ("\n"),
00102 &strtokp))
00103 {
00104 // Format the message line. Note that the processing for
00105 // VERBOSE is the same as for VERBOSE_LITE, since syslog()
00106 // already provides us with the hostname and PID. However, the
00107 // timestamp is duplicated (albeit a shortened version) to
00108 // provide a timestamp with greater precision than that provided
00109 // by syslog().
00110 if (ACE_BIT_ENABLED (flags, ACE_Log_Msg::VERBOSE)
00111 || ACE_BIT_ENABLED (flags, ACE_Log_Msg::VERBOSE_LITE))
00112 {
00113 ACE_TCHAR date_and_time[35];
00114 if (0 == ACE::timestamp (date_and_time, sizeof (date_and_time), 1))
00115 ACE_OS::strcpy (date_and_time, ACE_TEXT ("<time error>"));
00116 const ACE_TCHAR *prio_name =
00117 ACE_Log_Record::priority_name(ACE_Log_Priority(log_record.type()));
00118 syslog (syslog_priority,
00119 "%s: %s: %s",
00120 ACE_TEXT_ALWAYS_CHAR (date_and_time),
00121 ACE_TEXT_ALWAYS_CHAR (prio_name),
00122 ACE_TEXT_ALWAYS_CHAR (line));
00123 }
00124 else // No formatting required.
00125 syslog (syslog_priority, "%s", ACE_TEXT_ALWAYS_CHAR (line));
00126 }
00127
00128 return 0;
00129 }
|
|
|
Open a new event log. Initialize the event logging facility.
Implements ACE_Log_Msg_Backend. Definition at line 37 of file Log_Msg_UNIX_Syslog.cpp. References ACE_DEFAULT_SYSLOG_FACILITY, ACE_TCHAR, ACE_TEXT_ALWAYS_CHAR, and ACE_Log_Msg::program_name().
00038 {
00039 if (logger_key == 0)
00040 logger_key = ACE_Log_Msg::program_name ();
00041
00042 // Initialize the UNIX syslog facility. Default the syslog log
00043 // options LOG_CONS and LOG_PID to be set. There really should be a
00044 // logging strategy option to control the syslog log options,
00045 // however, we'll take the easy way out for now.
00046 #if defined (ACE_USES_WCHAR)
00047 openlog (ACE_TEXT_ALWAYS_CHAR (logger_key),
00048 LOG_CONS|LOG_PID,
00049 ACE_DEFAULT_SYSLOG_FACILITY);
00050 #else
00051 openlog (const_cast<char *> (logger_key),
00052 LOG_CONS|LOG_PID,
00053 ACE_DEFAULT_SYSLOG_FACILITY);
00054 #endif /* ACE_USES_WCHAR */
00055
00056 // Enable logging of all syslog priorities. If logging of all
00057 // priorities is not desired, use the ACE_Log_Msg::priority_mask()
00058 // method to control the log output sent to the syslog daemon via
00059 // the log() method, or use the system's syslog.conf file to select
00060 // desired level of information.
00061
00062 #if !defined (ACE_LACKS_SETLOGMASK)
00063 (void) setlogmask (LOG_UPTO (LOG_DEBUG));
00064 #endif /* ACE_LACKS_SETLOGMASK */
00065
00066 return 0;
00067 }
|
|
|
Reset the backend.
Implements ACE_Log_Msg_Backend. Definition at line 70 of file Log_Msg_UNIX_Syslog.cpp. References close().
00071 {
00072 return this->close ();
00073 }
|
1.3.6