diff options
author | Tobias Brunner <tobias@strongswan.org> | 2012-01-23 13:51:21 +0100 |
---|---|---|
committer | Tobias Brunner <tobias@strongswan.org> | 2012-05-02 14:45:38 +0200 |
commit | ead92870b8645af72fae75b7f5c0c3475b327380 (patch) | |
tree | 8f4410ee338a64f5e69352513d5aab8fd49c7065 /src/libcharon/plugins/sql/sql_logger.c | |
parent | d724fcd6240b56359fede1ff6ecd7f0c576dbd0d (diff) | |
download | strongswan-ead92870b8645af72fae75b7f5c0c3475b327380.tar.bz2 strongswan-ead92870b8645af72fae75b7f5c0c3475b327380.tar.xz |
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.
Diffstat (limited to 'src/libcharon/plugins/sql/sql_logger.c')
-rw-r--r-- | src/libcharon/plugins/sql/sql_logger.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/libcharon/plugins/sql/sql_logger.c b/src/libcharon/plugins/sql/sql_logger.c index e693bac48..e7267b875 100644 --- a/src/libcharon/plugins/sql/sql_logger.c +++ b/src/libcharon/plugins/sql/sql_logger.c @@ -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, }, |