Added a ike_name logger option to prefix the IKE_SA name on each line
This commit is contained in:
@@ -46,6 +46,11 @@ struct private_file_logger_t {
|
|||||||
* strftime() format of time prefix, if any
|
* strftime() format of time prefix, if any
|
||||||
*/
|
*/
|
||||||
char *time_format;
|
char *time_format;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print the name/# of the IKE_SA?
|
||||||
|
*/
|
||||||
|
bool ike_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -56,7 +61,7 @@ static bool log_(private_file_logger_t *this, debug_t group, level_t level,
|
|||||||
{
|
{
|
||||||
if (level <= this->levels[group])
|
if (level <= this->levels[group])
|
||||||
{
|
{
|
||||||
char buffer[8192], timestr[128];
|
char buffer[8192], timestr[128], namestr[128] = "";
|
||||||
char *current = buffer, *next;
|
char *current = buffer, *next;
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
time_t t;
|
time_t t;
|
||||||
@@ -67,6 +72,23 @@ static bool log_(private_file_logger_t *this, debug_t group, level_t level,
|
|||||||
localtime_r(&t, &tm);
|
localtime_r(&t, &tm);
|
||||||
strftime(timestr, sizeof(timestr), this->time_format, &tm);
|
strftime(timestr, sizeof(timestr), this->time_format, &tm);
|
||||||
}
|
}
|
||||||
|
if (this->ike_name && ike_sa)
|
||||||
|
{
|
||||||
|
if (ike_sa->get_peer_cfg(ike_sa))
|
||||||
|
{
|
||||||
|
snprintf(namestr, sizeof(namestr), " <%s|%d>",
|
||||||
|
ike_sa->get_name(ike_sa), ike_sa->get_unique_id(ike_sa));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
snprintf(namestr, sizeof(namestr), " <%d>",
|
||||||
|
ike_sa->get_unique_id(ike_sa));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
namestr[0] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
/* write in memory buffer first */
|
/* write in memory buffer first */
|
||||||
vsnprintf(buffer, sizeof(buffer), format, args);
|
vsnprintf(buffer, sizeof(buffer), format, args);
|
||||||
@@ -81,13 +103,13 @@ static bool log_(private_file_logger_t *this, debug_t group, level_t level,
|
|||||||
}
|
}
|
||||||
if (this->time_format)
|
if (this->time_format)
|
||||||
{
|
{
|
||||||
fprintf(this->out, "%s %.2d[%N] %s\n",
|
fprintf(this->out, "%s %.2d[%N]%s %s\n",
|
||||||
timestr, thread, debug_names, group, current);
|
timestr, thread, debug_names, group, namestr, current);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf(this->out, "%.2d[%N] %s\n",
|
fprintf(this->out, "%.2d[%N]%s %s\n",
|
||||||
thread, debug_names, group, current);
|
thread, debug_names, group, namestr, current);
|
||||||
}
|
}
|
||||||
current = next;
|
current = next;
|
||||||
}
|
}
|
||||||
@@ -129,7 +151,7 @@ static void destroy(private_file_logger_t *this)
|
|||||||
/*
|
/*
|
||||||
* Described in header.
|
* Described in header.
|
||||||
*/
|
*/
|
||||||
file_logger_t *file_logger_create(FILE *out, char *time_format)
|
file_logger_t *file_logger_create(FILE *out, char *time_format, bool ike_name)
|
||||||
{
|
{
|
||||||
private_file_logger_t *this = malloc_thing(private_file_logger_t);
|
private_file_logger_t *this = malloc_thing(private_file_logger_t);
|
||||||
|
|
||||||
@@ -142,6 +164,7 @@ file_logger_t *file_logger_create(FILE *out, char *time_format)
|
|||||||
/* private variables */
|
/* private variables */
|
||||||
this->out = out;
|
this->out = out;
|
||||||
this->time_format = time_format;
|
this->time_format = time_format;
|
||||||
|
this->ike_name = ike_name;
|
||||||
set_level(this, DBG_ANY, LEVEL_SILENT);
|
set_level(this, DBG_ANY, LEVEL_SILENT);
|
||||||
|
|
||||||
return &this->public;
|
return &this->public;
|
||||||
|
|||||||
@@ -54,8 +54,9 @@ struct file_logger_t {
|
|||||||
*
|
*
|
||||||
* @param out FILE to write to
|
* @param out FILE to write to
|
||||||
* @param time_format format of timestamp prefix, as in strftime()
|
* @param time_format format of timestamp prefix, as in strftime()
|
||||||
|
* @param ike_name TRUE to prefix the name of the IKE_SA
|
||||||
* @return file_logger_t object
|
* @return file_logger_t object
|
||||||
*/
|
*/
|
||||||
file_logger_t *file_logger_create(FILE *out, char *time_format);
|
file_logger_t *file_logger_create(FILE *out, char *time_format, bool ike_name);
|
||||||
|
|
||||||
#endif /** FILE_LOGGER_H_ @}*/
|
#endif /** FILE_LOGGER_H_ @}*/
|
||||||
|
|||||||
@@ -41,6 +41,11 @@ struct private_sys_logger_t {
|
|||||||
* Maximum level to log, for each group
|
* Maximum level to log, for each group
|
||||||
*/
|
*/
|
||||||
level_t levels[DBG_MAX];
|
level_t levels[DBG_MAX];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print the name/# of the IKE_SA?
|
||||||
|
*/
|
||||||
|
bool ike_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,12 +56,26 @@ static bool log_(private_sys_logger_t *this, debug_t group, level_t level,
|
|||||||
{
|
{
|
||||||
if (level <= this->levels[group])
|
if (level <= this->levels[group])
|
||||||
{
|
{
|
||||||
char buffer[8192];
|
char buffer[8192], namestr[128] = "";
|
||||||
char *current = buffer, *next;
|
char *current = buffer, *next;
|
||||||
|
|
||||||
/* write in memory buffer first */
|
/* write in memory buffer first */
|
||||||
vsnprintf(buffer, sizeof(buffer), format, args);
|
vsnprintf(buffer, sizeof(buffer), format, args);
|
||||||
|
|
||||||
|
if (this->ike_name && ike_sa)
|
||||||
|
{
|
||||||
|
if (ike_sa->get_peer_cfg(ike_sa))
|
||||||
|
{
|
||||||
|
snprintf(namestr, sizeof(namestr), " <%s|%d>",
|
||||||
|
ike_sa->get_name(ike_sa), ike_sa->get_unique_id(ike_sa));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
snprintf(namestr, sizeof(namestr), " <%d>",
|
||||||
|
ike_sa->get_unique_id(ike_sa));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* do a syslog with every line */
|
/* do a syslog with every line */
|
||||||
while (current)
|
while (current)
|
||||||
{
|
{
|
||||||
@@ -65,8 +84,8 @@ static bool log_(private_sys_logger_t *this, debug_t group, level_t level,
|
|||||||
{
|
{
|
||||||
*(next++) = '\0';
|
*(next++) = '\0';
|
||||||
}
|
}
|
||||||
syslog(this->facility|LOG_INFO, "%.2d[%N] %s\n",
|
syslog(this->facility|LOG_INFO, "%.2d[%N]%s %s\n",
|
||||||
thread, debug_names, group, current);
|
thread, debug_names, group, namestr, current);
|
||||||
current = next;
|
current = next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,7 +123,7 @@ static void destroy(private_sys_logger_t *this)
|
|||||||
/*
|
/*
|
||||||
* Described in header.
|
* Described in header.
|
||||||
*/
|
*/
|
||||||
sys_logger_t *sys_logger_create(int facility)
|
sys_logger_t *sys_logger_create(int facility, bool ike_name)
|
||||||
{
|
{
|
||||||
private_sys_logger_t *this = malloc_thing(private_sys_logger_t);
|
private_sys_logger_t *this = malloc_thing(private_sys_logger_t);
|
||||||
|
|
||||||
@@ -116,6 +135,7 @@ sys_logger_t *sys_logger_create(int facility)
|
|||||||
|
|
||||||
/* private variables */
|
/* private variables */
|
||||||
this->facility = facility;
|
this->facility = facility;
|
||||||
|
this->ike_name = ike_name;
|
||||||
set_level(this, DBG_ANY, LEVEL_SILENT);
|
set_level(this, DBG_ANY, LEVEL_SILENT);
|
||||||
|
|
||||||
return &this->public;
|
return &this->public;
|
||||||
|
|||||||
@@ -53,8 +53,9 @@ struct sys_logger_t {
|
|||||||
* Constructor to create a sys_logger_t object.
|
* Constructor to create a sys_logger_t object.
|
||||||
*
|
*
|
||||||
* @param facility syslog facility to use
|
* @param facility syslog facility to use
|
||||||
|
* @param ike_name TRUE to prefix the name of the IKE_SA
|
||||||
* @return sys_logger_t object
|
* @return sys_logger_t object
|
||||||
*/
|
*/
|
||||||
sys_logger_t *sys_logger_create(int facility);
|
sys_logger_t *sys_logger_create(int facility, bool ike_name);
|
||||||
|
|
||||||
#endif /** SYS_LOGGER_H_ @}*/
|
#endif /** SYS_LOGGER_H_ @}*/
|
||||||
|
|||||||
+12
-7
@@ -213,7 +213,7 @@ static void initialize_loggers(private_daemon_t *this, bool use_stderr,
|
|||||||
int loggers_defined = 0;
|
int loggers_defined = 0;
|
||||||
debug_t group;
|
debug_t group;
|
||||||
level_t def;
|
level_t def;
|
||||||
bool append;
|
bool append, ike_name;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
|
||||||
/* setup sysloggers */
|
/* setup sysloggers */
|
||||||
@@ -222,13 +222,16 @@ static void initialize_loggers(private_daemon_t *this, bool use_stderr,
|
|||||||
while (enumerator->enumerate(enumerator, &facility))
|
while (enumerator->enumerate(enumerator, &facility))
|
||||||
{
|
{
|
||||||
loggers_defined++;
|
loggers_defined++;
|
||||||
|
|
||||||
|
ike_name = lib->settings->get_bool(lib->settings,
|
||||||
|
"charon.syslog.%s.ike_name", FALSE, facility);
|
||||||
if (streq(facility, "daemon"))
|
if (streq(facility, "daemon"))
|
||||||
{
|
{
|
||||||
sys_logger = sys_logger_create(LOG_DAEMON);
|
sys_logger = sys_logger_create(LOG_DAEMON, ike_name);
|
||||||
}
|
}
|
||||||
else if (streq(facility, "auth"))
|
else if (streq(facility, "auth"))
|
||||||
{
|
{
|
||||||
sys_logger = sys_logger_create(LOG_AUTHPRIV);
|
sys_logger = sys_logger_create(LOG_AUTHPRIV, ike_name);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -282,7 +285,9 @@ static void initialize_loggers(private_daemon_t *this, bool use_stderr,
|
|||||||
}
|
}
|
||||||
file_logger = file_logger_create(file,
|
file_logger = file_logger_create(file,
|
||||||
lib->settings->get_str(lib->settings,
|
lib->settings->get_str(lib->settings,
|
||||||
"charon.filelog.%s.time_format", NULL, filename));
|
"charon.filelog.%s.time_format", NULL, filename),
|
||||||
|
lib->settings->get_bool(lib->settings,
|
||||||
|
"charon.filelog.%s.ike_name", FALSE, filename));
|
||||||
def = lib->settings->get_int(lib->settings,
|
def = lib->settings->get_int(lib->settings,
|
||||||
"charon.filelog.%s.default", 1, filename);
|
"charon.filelog.%s.default", 1, filename);
|
||||||
for (group = 0; group < DBG_MAX; group++)
|
for (group = 0; group < DBG_MAX; group++)
|
||||||
@@ -303,12 +308,12 @@ static void initialize_loggers(private_daemon_t *this, bool use_stderr,
|
|||||||
if (!loggers_defined)
|
if (!loggers_defined)
|
||||||
{
|
{
|
||||||
/* set up default stdout file_logger */
|
/* set up default stdout file_logger */
|
||||||
file_logger = file_logger_create(stdout, NULL);
|
file_logger = file_logger_create(stdout, NULL, FALSE);
|
||||||
this->public.bus->add_listener(this->public.bus, &file_logger->listener);
|
this->public.bus->add_listener(this->public.bus, &file_logger->listener);
|
||||||
this->public.file_loggers->insert_last(this->public.file_loggers,
|
this->public.file_loggers->insert_last(this->public.file_loggers,
|
||||||
file_logger);
|
file_logger);
|
||||||
/* set up default daemon sys_logger */
|
/* set up default daemon sys_logger */
|
||||||
sys_logger = sys_logger_create(LOG_DAEMON);
|
sys_logger = sys_logger_create(LOG_DAEMON, FALSE);
|
||||||
this->public.bus->add_listener(this->public.bus, &sys_logger->listener);
|
this->public.bus->add_listener(this->public.bus, &sys_logger->listener);
|
||||||
this->public.sys_loggers->insert_last(this->public.sys_loggers,
|
this->public.sys_loggers->insert_last(this->public.sys_loggers,
|
||||||
sys_logger);
|
sys_logger);
|
||||||
@@ -322,7 +327,7 @@ static void initialize_loggers(private_daemon_t *this, bool use_stderr,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* set up default auth sys_logger */
|
/* set up default auth sys_logger */
|
||||||
sys_logger = sys_logger_create(LOG_AUTHPRIV);
|
sys_logger = sys_logger_create(LOG_AUTHPRIV, FALSE);
|
||||||
this->public.bus->add_listener(this->public.bus, &sys_logger->listener);
|
this->public.bus->add_listener(this->public.bus, &sys_logger->listener);
|
||||||
this->public.sys_loggers->insert_last(this->public.sys_loggers,
|
this->public.sys_loggers->insert_last(this->public.sys_loggers,
|
||||||
sys_logger);
|
sys_logger);
|
||||||
|
|||||||
Reference in New Issue
Block a user