summaryrefslogtreecommitdiff
path: root/main/logger.c
diff options
context:
space:
mode:
authorScott Emidy <jemidy@digium.com>2015-08-07 14:20:29 -0500
committerScott Emidy <jemidy@digium.com>2015-08-07 14:57:45 -0500
commit12e6f5ac01cac88f1f2ddd60b6dbe3f8755c5ef8 (patch)
treedd0f743affba1c2b33e0bea7886e57c668e5ef16 /main/logger.c
parentb91ca7ba49ce74152139309fd0ae1a66df695cc0 (diff)
ARI: Retrieve existing log channels
An http request can be sent to get the existing Asterisk logs. The command "curl -v -u user:pass -X GET 'http://localhost:8088 /ari/asterisk/logging'" can be run in the terminal to access the newly implemented functionality. * Retrieve all existing log channels ASTERISK-25252 Change-Id: I7bb08b93e3b938c991f3f56cc5d188654768a808
Diffstat (limited to 'main/logger.c')
-rw-r--r--main/logger.c48
1 files changed, 45 insertions, 3 deletions
diff --git a/main/logger.c b/main/logger.c
index c516ec07d..fdac22c6d 100644
--- a/main/logger.c
+++ b/main/logger.c
@@ -928,11 +928,11 @@ int ast_logger_rotate()
int ast_logger_rotate_channel(const char *log_channel)
{
struct logchannel *f;
- int success = 0;
+ int success = AST_LOGGER_FAILURE;
struct ast_str *filename = ast_str_create(64);
if (!filename) {
- return -1;
+ return AST_LOGGER_ALLOC_ERROR;
}
ast_str_append(&filename, 0, "%s/%s", ast_config_AST_LOG_DIR, log_channel);
@@ -952,7 +952,7 @@ int ast_logger_rotate_channel(const char *log_channel)
f->fileptr = NULL;
if (strcmp(ast_str_buffer(filename), f->filename) == 0) {
rotate_file(f->filename);
- success = 1;
+ success = AST_LOGGER_SUCCESS;
}
}
}
@@ -1007,6 +1007,48 @@ static char *handle_logger_set_level(struct ast_cli_entry *e, int cmd, struct as
return CLI_SUCCESS;
}
+int ast_logger_get_channels(int (*logentry)(const char *channel, const char *type,
+ const char *status, const char *configuration, void *data), void *data)
+{
+ struct logchannel *chan;
+ struct ast_str *configs = ast_str_create(64);
+ int res = AST_LOGGER_SUCCESS;
+
+ if (!configs) {
+ return AST_LOGGER_ALLOC_ERROR;
+ }
+
+ AST_RWLIST_RDLOCK(&logchannels);
+ AST_RWLIST_TRAVERSE(&logchannels, chan, list) {
+ unsigned int level;
+
+ ast_str_reset(configs);
+
+ for (level = 0; level < ARRAY_LEN(levels); level++) {
+ if ((chan->logmask & (1 << level)) && levels[level]) {
+ ast_str_append(&configs, 0, "%s ", levels[level]);
+ }
+ }
+
+ res = logentry(chan->filename, chan->type == LOGTYPE_CONSOLE ? "Console" :
+ (chan->type == LOGTYPE_SYSLOG ? "Syslog" : "File"), chan->disabled ?
+ "Disabled" : "Enabled", ast_str_buffer(configs), data);
+
+ if (res) {
+ AST_RWLIST_UNLOCK(&logchannels);
+ ast_free(configs);
+ configs = NULL;
+ return AST_LOGGER_FAILURE;
+ }
+ }
+ AST_RWLIST_UNLOCK(&logchannels);
+
+ ast_free(configs);
+ configs = NULL;
+
+ return AST_LOGGER_SUCCESS;
+}
+
/*! \brief CLI command to show logging system configuration */
static char *handle_logger_show_channels(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{