Loggers specify what log messages they want to receive during registration.
This also allows us to generate the log message only once for all loggers that need it (avoids calls to custom printf specifier callbacks). To update the log levels loggers can simply be registered again.
This commit is contained in:
@@ -47,34 +47,36 @@ struct private_android_logger_t {
|
||||
|
||||
|
||||
METHOD(logger_t, log_, void,
|
||||
private_android_logger_t *this, debug_t group, level_t level,
|
||||
int thread, ike_sa_t* ike_sa, char *format, va_list args)
|
||||
private_android_logger_t *this, debug_t group, level_t level,
|
||||
int thread, ike_sa_t* ike_sa, char *message)
|
||||
{
|
||||
if (level <= this->level)
|
||||
{
|
||||
int prio = level > 1 ? ANDROID_LOG_DEBUG : ANDROID_LOG_INFO;
|
||||
char sgroup[16], buffer[8192];
|
||||
char *current = buffer, *next;
|
||||
snprintf(sgroup, sizeof(sgroup), "%N", debug_names, group);
|
||||
vsnprintf(buffer, sizeof(buffer), format, args);
|
||||
this->mutex->lock(this->mutex);
|
||||
while (current)
|
||||
{ /* log each line separately */
|
||||
next = strchr(current, '\n');
|
||||
if (next)
|
||||
{
|
||||
*(next++) = '\0';
|
||||
}
|
||||
__android_log_print(prio, "charon", "%.2d[%s] %s\n",
|
||||
thread, sgroup, current);
|
||||
current = next;
|
||||
int prio = level > 1 ? ANDROID_LOG_DEBUG : ANDROID_LOG_INFO;
|
||||
char sgroup[16];
|
||||
char *current = message, *next;
|
||||
snprintf(sgroup, sizeof(sgroup), "%N", debug_names, group);
|
||||
this->mutex->lock(this->mutex);
|
||||
while (current)
|
||||
{ /* log each line separately */
|
||||
next = strchr(current, '\n');
|
||||
if (next)
|
||||
{
|
||||
*(next++) = '\0';
|
||||
}
|
||||
this->mutex->unlock(this->mutex);
|
||||
__android_log_print(prio, "charon", "%.2d[%s] %s\n",
|
||||
thread, sgroup, current);
|
||||
current = next;
|
||||
}
|
||||
this->mutex->unlock(this->mutex);
|
||||
}
|
||||
|
||||
METHOD(logger_t, get_level, level_t,
|
||||
private_android_logger_t *this, debug_t group)
|
||||
{
|
||||
return this->level;
|
||||
}
|
||||
|
||||
METHOD(android_logger_t, destroy, void,
|
||||
private_android_logger_t *this)
|
||||
private_android_logger_t *this)
|
||||
{
|
||||
this->mutex->destroy(this->mutex);
|
||||
free(this);
|
||||
@@ -91,6 +93,7 @@ android_logger_t *android_logger_create()
|
||||
.public = {
|
||||
.logger = {
|
||||
.log = _log_,
|
||||
.get_level = _get_level,
|
||||
},
|
||||
.destroy = _destroy,
|
||||
},
|
||||
|
||||
@@ -349,7 +349,7 @@ static void request_query_config(xmlTextReaderPtr reader, xmlTextWriterPtr write
|
||||
* callback which logs to a XML writer
|
||||
*/
|
||||
static bool xml_callback(xmlTextWriterPtr writer, debug_t group, level_t level,
|
||||
ike_sa_t* ike_sa, char* format, va_list args)
|
||||
ike_sa_t* ike_sa, char* message)
|
||||
{
|
||||
if (level <= 1)
|
||||
{
|
||||
@@ -358,7 +358,7 @@ static bool xml_callback(xmlTextWriterPtr writer, debug_t group, level_t level,
|
||||
xmlTextWriterWriteFormatAttribute(writer, "level", "%d", level);
|
||||
xmlTextWriterWriteFormatAttribute(writer, "source", "%N", debug_names, group);
|
||||
xmlTextWriterWriteFormatAttribute(writer, "thread", "%u", thread_current_id());
|
||||
xmlTextWriterWriteVFormatString(writer, format, args);
|
||||
xmlTextWriterWriteString(writer, message);
|
||||
xmlTextWriterEndElement(writer);
|
||||
/* </item> */
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ struct private_sql_logger_t {
|
||||
|
||||
METHOD(logger_t, log_, void,
|
||||
private_sql_logger_t *this, debug_t group, level_t level, int thread,
|
||||
ike_sa_t* ike_sa, char *format, va_list args)
|
||||
ike_sa_t* ike_sa, char *message)
|
||||
{
|
||||
if (this->recursive->get(this->recursive))
|
||||
{
|
||||
@@ -58,9 +58,8 @@ METHOD(logger_t, log_, void,
|
||||
}
|
||||
this->recursive->set(this->recursive, this->recursive);
|
||||
|
||||
if (ike_sa && level <= this->level)
|
||||
if (ike_sa)
|
||||
{
|
||||
char buffer[8192];
|
||||
chunk_t local_spi, remote_spi;
|
||||
host_t *local_host, *remote_host;
|
||||
identification_t *local_id, *remote_id;
|
||||
@@ -86,8 +85,6 @@ METHOD(logger_t, log_, void,
|
||||
local_host = ike_sa->get_my_host(ike_sa);
|
||||
remote_host = ike_sa->get_other_host(ike_sa);
|
||||
|
||||
vsnprintf(buffer, sizeof(buffer), format, args);
|
||||
|
||||
this->db->execute(this->db, NULL, "REPLACE INTO ike_sas ("
|
||||
"local_spi, remote_spi, id, initiator, "
|
||||
"local_id_type, local_id_data, "
|
||||
@@ -107,11 +104,18 @@ METHOD(logger_t, log_, void,
|
||||
this->db->execute(this->db, NULL, "INSERT INTO logs ("
|
||||
"local_spi, signal, level, msg) VALUES (?, ?, ?, ?)",
|
||||
DB_BLOB, local_spi, DB_INT, group, DB_INT, level,
|
||||
DB_TEXT, buffer);
|
||||
DB_TEXT, message);
|
||||
}
|
||||
|
||||
this->recursive->set(this->recursive, NULL);
|
||||
}
|
||||
|
||||
METHOD(logger_t, get_level, level_t,
|
||||
private_sql_logger_t *this, debug_t group)
|
||||
{
|
||||
return this->level;
|
||||
}
|
||||
|
||||
METHOD(sql_logger_t, destroy, void,
|
||||
private_sql_logger_t *this)
|
||||
{
|
||||
@@ -129,6 +133,7 @@ sql_logger_t *sql_logger_create(database_t *db)
|
||||
.public = {
|
||||
.logger = {
|
||||
.log = _log_,
|
||||
.get_level = _get_level,
|
||||
},
|
||||
.destroy = _destroy,
|
||||
},
|
||||
|
||||
@@ -58,11 +58,11 @@ struct stroke_log_info_t {
|
||||
* logging to the stroke interface
|
||||
*/
|
||||
static bool stroke_log(stroke_log_info_t *info, debug_t group, level_t level,
|
||||
ike_sa_t *ike_sa, char *format, va_list args)
|
||||
ike_sa_t *ike_sa, char *message)
|
||||
{
|
||||
if (level <= info->level)
|
||||
{
|
||||
if (vfprintf(info->out, format, args) < 0 ||
|
||||
if (fprintf(info->out, message) < 0 ||
|
||||
fprintf(info->out, "\n") < 0 ||
|
||||
fflush(info->out) != 0)
|
||||
{
|
||||
|
||||
@@ -517,12 +517,14 @@ static void stroke_loglevel(private_stroke_socket_t *this,
|
||||
while (enumerator->enumerate(enumerator, &sys_logger))
|
||||
{
|
||||
sys_logger->set_level(sys_logger, group, msg->loglevel.level);
|
||||
charon->bus->add_logger(charon->bus, &sys_logger->logger);
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
enumerator = charon->file_loggers->create_enumerator(charon->file_loggers);
|
||||
while (enumerator->enumerate(enumerator, &file_logger))
|
||||
{
|
||||
file_logger->set_level(file_logger, group, msg->loglevel.level);
|
||||
charon->bus->add_logger(charon->bus, &file_logger->logger);
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user