* strftime() format of time prefix, if any
*/
char *time_format;
+
+ /**
+ * Print the name/# of the IKE_SA?
+ */
+ bool ike_name;
};
/**
{
if (level <= this->levels[group])
{
- char buffer[8192], timestr[128];
+ char buffer[8192], timestr[128], namestr[128] = "";
char *current = buffer, *next;
struct tm tm;
time_t t;
localtime_r(&t, &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 */
vsnprintf(buffer, sizeof(buffer), format, args);
}
if (this->time_format)
{
- fprintf(this->out, "%s %.2d[%N] %s\n",
- timestr, thread, debug_names, group, current);
+ fprintf(this->out, "%s %.2d[%N]%s %s\n",
+ timestr, thread, debug_names, group, namestr, current);
}
else
{
- fprintf(this->out, "%.2d[%N] %s\n",
- thread, debug_names, group, current);
+ fprintf(this->out, "%.2d[%N]%s %s\n",
+ thread, debug_names, group, namestr, current);
}
current = next;
}
/*
* 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 variables */
this->out = out;
this->time_format = time_format;
+ this->ike_name = ike_name;
set_level(this, DBG_ANY, LEVEL_SILENT);
return &this->public;
*
* @param out FILE to write to
* @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
*/
-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_ @}*/
* Maximum level to log, for each group
*/
level_t levels[DBG_MAX];
+
+ /**
+ * Print the name/# of the IKE_SA?
+ */
+ bool ike_name;
};
/**
{
if (level <= this->levels[group])
{
- char buffer[8192];
+ char buffer[8192], namestr[128] = "";
char *current = buffer, *next;
/* write in memory buffer first */
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 */
while (current)
{
{
*(next++) = '\0';
}
- syslog(this->facility|LOG_INFO, "%.2d[%N] %s\n",
- thread, debug_names, group, current);
+ syslog(this->facility|LOG_INFO, "%.2d[%N]%s %s\n",
+ thread, debug_names, group, namestr, current);
current = next;
}
}
/*
* 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 variables */
this->facility = facility;
+ this->ike_name = ike_name;
set_level(this, DBG_ANY, LEVEL_SILENT);
return &this->public;
* Constructor to create a sys_logger_t object.
*
* @param facility syslog facility to use
+ * @param ike_name TRUE to prefix the name of the IKE_SA
* @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_ @}*/
int loggers_defined = 0;
debug_t group;
level_t def;
- bool append;
+ bool append, ike_name;
FILE *file;
/* setup sysloggers */
while (enumerator->enumerate(enumerator, &facility))
{
loggers_defined++;
+
+ ike_name = lib->settings->get_bool(lib->settings,
+ "charon.syslog.%s.ike_name", FALSE, facility);
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"))
{
- sys_logger = sys_logger_create(LOG_AUTHPRIV);
+ sys_logger = sys_logger_create(LOG_AUTHPRIV, ike_name);
}
else
{
}
file_logger = file_logger_create(file,
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,
"charon.filelog.%s.default", 1, filename);
for (group = 0; group < DBG_MAX; group++)
if (!loggers_defined)
{
/* 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.file_loggers->insert_last(this->public.file_loggers,
file_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.sys_loggers->insert_last(this->public.sys_loggers,
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.sys_loggers->insert_last(this->public.sys_loggers,
sys_logger);