mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-19 00:00:09 +00:00
Made changes corresponding to those in 1.2 here in main/logger.c for bug 7544.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@42208 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
150
main/logger.c
150
main/logger.c
@@ -295,6 +295,7 @@ static void init_logger_chain(void)
|
|||||||
AST_LIST_UNLOCK(&logchannels);
|
AST_LIST_UNLOCK(&logchannels);
|
||||||
|
|
||||||
global_logmask = 0;
|
global_logmask = 0;
|
||||||
|
errno = 0;
|
||||||
/* close syslog */
|
/* close syslog */
|
||||||
closelog();
|
closelog();
|
||||||
|
|
||||||
@@ -302,7 +303,10 @@ static void init_logger_chain(void)
|
|||||||
|
|
||||||
/* If no config file, we're fine, set default options. */
|
/* If no config file, we're fine, set default options. */
|
||||||
if (!cfg) {
|
if (!cfg) {
|
||||||
fprintf(stderr, "Unable to open logger.conf: %s\n", strerror(errno));
|
if (errno)
|
||||||
|
fprintf(stderr, "Unable to open logger.conf: %s; default settings will be used.\n", strerror(errno));
|
||||||
|
else
|
||||||
|
fprintf(stderr, "Errors detected in logger.conf: see above; default settings will be used.\n");
|
||||||
if (!(chan = ast_calloc(1, sizeof(*chan))))
|
if (!(chan = ast_calloc(1, sizeof(*chan))))
|
||||||
return;
|
return;
|
||||||
chan->type = LOGTYPE_CONSOLE;
|
chan->type = LOGTYPE_CONSOLE;
|
||||||
@@ -688,6 +692,23 @@ void ast_log(int level, const char *file, int line, const char *function, const
|
|||||||
if (!(buf = ast_dynamic_str_thread_get(&log_buf, LOG_BUF_INIT_SIZE)))
|
if (!(buf = ast_dynamic_str_thread_get(&log_buf, LOG_BUF_INIT_SIZE)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (AST_LIST_EMPTY(&logchannels))
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* we don't have the logger chain configured yet,
|
||||||
|
* so just log to stdout
|
||||||
|
*/
|
||||||
|
if (level != __LOG_VERBOSE) {
|
||||||
|
int res;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
res = ast_dynamic_str_thread_set_va(&buf, BUFSIZ, &log_buf, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
if (res != AST_DYNSTR_BUILD_FAILED)
|
||||||
|
fputs(buf->str, stdout);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* don't display LOG_DEBUG messages unless option_verbose _or_ option_debug
|
/* don't display LOG_DEBUG messages unless option_verbose _or_ option_debug
|
||||||
are non-zero; LOG_DEBUG messages can still be displayed if option_debug
|
are non-zero; LOG_DEBUG messages can still be displayed if option_debug
|
||||||
is zero, if option_verbose is non-zero (this allows for 'level zero'
|
is zero, if option_verbose is non-zero (this allows for 'level zero'
|
||||||
@@ -723,82 +744,67 @@ void ast_log(int level, const char *file, int line, const char *function, const
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!AST_LIST_EMPTY(&logchannels)) {
|
AST_LIST_TRAVERSE(&logchannels, chan, list) {
|
||||||
AST_LIST_TRAVERSE(&logchannels, chan, list) {
|
if (chan->disabled)
|
||||||
if (chan->disabled)
|
break;
|
||||||
break;
|
/* Check syslog channels */
|
||||||
/* Check syslog channels */
|
if (chan->type == LOGTYPE_SYSLOG && (chan->logmask & (1 << level))) {
|
||||||
if (chan->type == LOGTYPE_SYSLOG && (chan->logmask & (1 << level))) {
|
va_start(ap, fmt);
|
||||||
va_start(ap, fmt);
|
ast_log_vsyslog(level, file, line, function, fmt, ap);
|
||||||
ast_log_vsyslog(level, file, line, function, fmt, ap);
|
va_end(ap);
|
||||||
va_end(ap);
|
/* Console channels */
|
||||||
/* Console channels */
|
} else if ((chan->logmask & (1 << level)) && (chan->type == LOGTYPE_CONSOLE)) {
|
||||||
} else if ((chan->logmask & (1 << level)) && (chan->type == LOGTYPE_CONSOLE)) {
|
char linestr[128];
|
||||||
char linestr[128];
|
char tmp1[80], tmp2[80], tmp3[80], tmp4[80];
|
||||||
char tmp1[80], tmp2[80], tmp3[80], tmp4[80];
|
|
||||||
|
|
||||||
if (level != __LOG_VERBOSE) {
|
if (level != __LOG_VERBOSE) {
|
||||||
int res;
|
|
||||||
sprintf(linestr, "%d", line);
|
|
||||||
ast_dynamic_str_thread_set(&buf, BUFSIZ, &log_buf,
|
|
||||||
"[%s] %s[%ld]: %s:%s %s: ",
|
|
||||||
date,
|
|
||||||
term_color(tmp1, levels[level], colors[level], 0, sizeof(tmp1)),
|
|
||||||
(long)GETTID(),
|
|
||||||
term_color(tmp2, file, COLOR_BRWHITE, 0, sizeof(tmp2)),
|
|
||||||
term_color(tmp3, linestr, COLOR_BRWHITE, 0, sizeof(tmp3)),
|
|
||||||
term_color(tmp4, function, COLOR_BRWHITE, 0, sizeof(tmp4)));
|
|
||||||
|
|
||||||
ast_console_puts_mutable(buf->str);
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
res = ast_dynamic_str_thread_set_va(&buf, BUFSIZ, &log_buf, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
if (res != AST_DYNSTR_BUILD_FAILED)
|
|
||||||
ast_console_puts_mutable(buf->str);
|
|
||||||
}
|
|
||||||
/* File channels */
|
|
||||||
} else if ((chan->logmask & (1 << level)) && (chan->fileptr)) {
|
|
||||||
int res;
|
int res;
|
||||||
ast_dynamic_str_thread_set(&buf, BUFSIZ, &log_buf,
|
sprintf(linestr, "%d", line);
|
||||||
"[%s] %s[%ld] %s: ",
|
ast_dynamic_str_thread_set(&buf, BUFSIZ, &log_buf,
|
||||||
date, levels[level], (long)GETTID(), file);
|
"[%s] %s[%ld]: %s:%s %s: ",
|
||||||
res = fprintf(chan->fileptr, "%s", buf->str);
|
date,
|
||||||
if (res <= 0 && !ast_strlen_zero(buf->str)) { /* Error, no characters printed */
|
term_color(tmp1, levels[level], colors[level], 0, sizeof(tmp1)),
|
||||||
fprintf(stderr,"**** Asterisk Logging Error: ***********\n");
|
(long)GETTID(),
|
||||||
if (errno == ENOMEM || errno == ENOSPC) {
|
term_color(tmp2, file, COLOR_BRWHITE, 0, sizeof(tmp2)),
|
||||||
fprintf(stderr, "Asterisk logging error: Out of disk space, can't log to log file %s\n", chan->filename);
|
term_color(tmp3, linestr, COLOR_BRWHITE, 0, sizeof(tmp3)),
|
||||||
} else
|
term_color(tmp4, function, COLOR_BRWHITE, 0, sizeof(tmp4)));
|
||||||
fprintf(stderr, "Logger Warning: Unable to write to log file '%s': %s (disabled)\n", chan->filename, strerror(errno));
|
|
||||||
manager_event(EVENT_FLAG_SYSTEM, "LogChannel", "Channel: %s\r\nEnabled: No\r\nReason: %d - %s\r\n", chan->filename, errno, strerror(errno));
|
ast_console_puts_mutable(buf->str);
|
||||||
chan->disabled = 1;
|
|
||||||
} else {
|
va_start(ap, fmt);
|
||||||
int res;
|
res = ast_dynamic_str_thread_set_va(&buf, BUFSIZ, &log_buf, fmt, ap);
|
||||||
/* No error message, continue printing */
|
va_end(ap);
|
||||||
va_start(ap, fmt);
|
if (res != AST_DYNSTR_BUILD_FAILED)
|
||||||
res = ast_dynamic_str_thread_set_va(&buf, BUFSIZ, &log_buf, fmt, ap);
|
ast_console_puts_mutable(buf->str);
|
||||||
va_end(ap);
|
}
|
||||||
if (res != AST_DYNSTR_BUILD_FAILED) {
|
/* File channels */
|
||||||
term_strip(buf->str, buf->str, buf->len);
|
} else if ((chan->logmask & (1 << level)) && (chan->fileptr)) {
|
||||||
fputs(buf->str, chan->fileptr);
|
int res;
|
||||||
fflush(chan->fileptr);
|
ast_dynamic_str_thread_set(&buf, BUFSIZ, &log_buf,
|
||||||
}
|
"[%s] %s[%ld] %s: ",
|
||||||
|
date, levels[level], (long)GETTID(), file);
|
||||||
|
res = fprintf(chan->fileptr, "%s", buf->str);
|
||||||
|
if (res <= 0 && !ast_strlen_zero(buf->str)) { /* Error, no characters printed */
|
||||||
|
fprintf(stderr,"**** Asterisk Logging Error: ***********\n");
|
||||||
|
if (errno == ENOMEM || errno == ENOSPC) {
|
||||||
|
fprintf(stderr, "Asterisk logging error: Out of disk space, can't log to log file %s\n", chan->filename);
|
||||||
|
} else
|
||||||
|
fprintf(stderr, "Logger Warning: Unable to write to log file '%s': %s (disabled)\n", chan->filename, strerror(errno));
|
||||||
|
manager_event(EVENT_FLAG_SYSTEM, "LogChannel", "Channel: %s\r\nEnabled: No\r\nReason: %d - %s\r\n", chan->filename, errno, strerror(errno));
|
||||||
|
chan->disabled = 1;
|
||||||
|
} else {
|
||||||
|
int res;
|
||||||
|
/* No error message, continue printing */
|
||||||
|
va_start(ap, fmt);
|
||||||
|
res = ast_dynamic_str_thread_set_va(&buf, BUFSIZ, &log_buf, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
if (res != AST_DYNSTR_BUILD_FAILED) {
|
||||||
|
term_strip(buf->str, buf->str, buf->len);
|
||||||
|
fputs(buf->str, chan->fileptr);
|
||||||
|
fflush(chan->fileptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
/*
|
|
||||||
* we don't have the logger chain configured yet,
|
|
||||||
* so just log to stdout
|
|
||||||
*/
|
|
||||||
if (level != __LOG_VERBOSE) {
|
|
||||||
int res;
|
|
||||||
va_start(ap, fmt);
|
|
||||||
res = ast_dynamic_str_thread_set_va(&buf, BUFSIZ, &log_buf, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
if (res != AST_DYNSTR_BUILD_FAILED)
|
|
||||||
fputs(buf->str, stdout);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AST_LIST_UNLOCK(&logchannels);
|
AST_LIST_UNLOCK(&logchannels);
|
||||||
|
|||||||
Reference in New Issue
Block a user