diff options
author | Harald Welte <laforge@gnumonks.org> | 2010-08-25 19:10:50 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2010-08-25 19:10:50 +0200 |
commit | 3086c394de1ddae3ca1bf2e8c315b235a4c70321 (patch) | |
tree | 1b3301ae4f0b5d851dbdf01827016cfc69a5e9c6 /src/logging.c | |
parent | 0083cd381c9ad7d65789db612771868d2be22696 (diff) |
logging: add log target logging into text file and log target destroy function
Diffstat (limited to 'src/logging.c')
-rw-r--r-- | src/logging.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/logging.c b/src/logging.c index fe782a67..5be4e58e 100644 --- a/src/logging.c +++ b/src/logging.c @@ -348,6 +348,56 @@ struct log_target *log_target_create_stderr(void) #endif /* stderr */ } +struct log_target *log_target_create_file(const char *fname) +{ + struct log_target *target; + + target = log_target_create(); + if (!target) + return NULL; + + target->tgt_file.out = fopen(fname, "a"); + if (!target->tgt_file.out) + return NULL; + + target->output = _file_output; + + target->tgt_file.fname = talloc_strdup(target, fname); + + return target; +} + +void log_target_destroy(struct log_target *target) +{ + + /* just in case, to make sure we don't have any references */ + log_del_target(target); + + if (target->output == &_file_output) { + /* don't close stderr */ + if (target->tgt_file.out != stderr) { + fclose(target->tgt_file.out); + target->tgt_file.out = NULL; + } + } + + talloc_free(target); +} + +/* close and re-open a log file (for log file rotation) */ +int log_target_file_reopen(struct log_target *target) +{ + fclose(target->tgt_file.out); + + target->tgt_file.out = fopen(target->tgt_file.fname, "a"); + if (!target->tgt_file.out) + return -errno; + + /* we assume target->output already to be set */ + + return 0; +} + const char *log_vty_level_string(struct log_info *info) { const struct value_string *vs; |