Console logging settings are now overridden by env vars.

remotes/origin/master-1.0.x
Victor Julien 16 years ago
parent 9527aa26a2
commit 4875c2daf4

@ -1,4 +1,7 @@
/** Copyright (c) 2009 Open Information Security Foundation. /* Copyright (c) 2009 Open Information Security Foundation. */
/**
* \file
* \author Anoop Saldanha <poonaatsoc@gmail.com> * \author Anoop Saldanha <poonaatsoc@gmail.com>
*/ */
@ -541,7 +544,8 @@ static inline SCLogOPIfaceCtx *SCLogInitFileOPIface(const char *file,
} }
/** /**
* \brief Initializes the console output interface * \brief Initializes the console output interface and deals with possible
* env var overrides.
* *
* \param log_format Pointer to the log_format for this op interface, that * \param log_format Pointer to the log_format for this op interface, that
* overrides the global_log_format * overrides the global_log_format
@ -552,6 +556,8 @@ static inline SCLogOPIfaceCtx *SCLogInitFileOPIface(const char *file,
static inline SCLogOPIfaceCtx *SCLogInitConsoleOPIface(const char *log_format, static inline SCLogOPIfaceCtx *SCLogInitConsoleOPIface(const char *log_format,
SCLogLevel log_level) SCLogLevel log_level)
{ {
printf("SCLogInitConsoleOPIface start\n");
SCLogOPIfaceCtx *iface_ctx = SCLogAllocLogOPIfaceCtx(); SCLogOPIfaceCtx *iface_ctx = SCLogAllocLogOPIfaceCtx();
if ( (iface_ctx = malloc(sizeof(SCLogOPIfaceCtx))) == NULL) { if ( (iface_ctx = malloc(sizeof(SCLogOPIfaceCtx))) == NULL) {
@ -562,13 +568,33 @@ static inline SCLogOPIfaceCtx *SCLogInitConsoleOPIface(const char *log_format,
iface_ctx->iface = SC_LOG_OP_IFACE_CONSOLE; iface_ctx->iface = SC_LOG_OP_IFACE_CONSOLE;
if (log_format != NULL && /* console log format is overridden by envvars */
(iface_ctx->log_format = strdup(log_format)) == NULL) { const char *tmp_log_format = log_format;
const char *s = getenv(SC_LOG_ENV_LOG_FORMAT);
if (s != NULL) {
printf("Overriding setting for \"console.format\" because of env "
"var SC_LOG_FORMAT=\"%s\".\n", s);
tmp_log_format = s;
}
if (tmp_log_format != NULL &&
(iface_ctx->log_format = strdup(tmp_log_format)) == NULL) {
printf("Error allocating memory\n"); printf("Error allocating memory\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
iface_ctx->log_level = log_level; /* console log level is overridden by envvars */
SCLogLevel tmp_log_level = log_level;
s = getenv(SC_LOG_ENV_LOG_LEVEL);
if (s != NULL) {
SCLogLevel l = SCMapEnumNameToValue(s, sc_log_level_map);
if (l > SC_LOG_NOTSET && l < SC_LOG_LEVEL_MAX) {
printf("Overriding setting for \"console.level\" because of env "
"var SC_LOG_LEVEL=\"%s\".\n", s);
tmp_log_level = l;
}
}
iface_ctx->log_level = tmp_log_level;
return iface_ctx; return iface_ctx;
} }
@ -659,12 +685,12 @@ static inline void SCLogSetLogLevel(SCLogInitData *sc_lid, SCLogConfig *sc_lc)
SCLogLevel log_level = SC_LOG_NOTSET; SCLogLevel log_level = SC_LOG_NOTSET;
const char *s = NULL; const char *s = NULL;
if (sc_lid != NULL) { /* envvar overrides config */
s = getenv(SC_LOG_ENV_LOG_LEVEL);
if (s != NULL) {
log_level = SCMapEnumNameToValue(s, sc_log_level_map);
} else if (sc_lid != NULL) {
log_level = sc_lid->global_log_level; log_level = sc_lid->global_log_level;
} else {
s = getenv(SC_LOG_ENV_LOG_LEVEL);
if (s != NULL)
log_level = SCMapEnumNameToValue(s, sc_log_level_map);
} }
/* deal with the global_log_level to be used */ /* deal with the global_log_level to be used */
@ -702,10 +728,13 @@ static inline void SCLogSetLogFormat(SCLogInitData *sc_lid, SCLogConfig *sc_lc)
{ {
char *format = NULL; char *format = NULL;
if (sc_lid != NULL) /* envvar overrides config */
format = sc_lid->global_log_format; format = getenv(SC_LOG_ENV_LOG_FORMAT);
else if (format == NULL) {
format = getenv(SC_LOG_ENV_LOG_FORMAT); if (sc_lid != NULL) {
format = sc_lid->global_log_format;
}
}
/* deal with the global log format to be used */ /* deal with the global log format to be used */
if (format == NULL || strlen(format) > SC_LOG_MAX_LOG_FORMAT_LEN) { if (format == NULL || strlen(format) > SC_LOG_MAX_LOG_FORMAT_LEN) {

@ -191,18 +191,24 @@ logging:
# The default log level, can be overridden in an output section. # The default log level, can be overridden in an output section.
# Note that debug level logging will only be emitted if Suricata was # Note that debug level logging will only be emitted if Suricata was
# compiled with the --enable-debug configure option. # compiled with the --enable-debug configure option.
#
# This value is overriden by the SC_LOG_LEVEL env var.
default-log-level: info default-log-level: info
# The default output format. Optional parameter, should default to # The default output format. Optional parameter, should default to
# something reasonable if not provided. Can be overriden in an # something reasonable if not provided. Can be overriden in an
# output section. You can leave this out to get the default. # output section. You can leave this out to get the default.
#
# This value is overriden by the SC_LOG_FORMAT env var.
#default-log-format: "[%i] %t - (%f:%l) <%d> (%n) -- " #default-log-format: "[%i] %t - (%f:%l) <%d> (%n) -- "
# A regex to filter output. Can be overridden in an output section. # A regex to filter output. Can be overridden in an output section.
# Defaults to empty (no filter). # Defaults to empty (no filter).
#
# This value is overriden by the SC_LOG_OP_FILTER env var.
default-output-filter: default-output-filter:
# Define your logging outputs. If none are define, or they are all # Define your logging outputs. If none are defined, or they are all
# disabled you will get the default - console output. # disabled you will get the default - console output.
outputs: outputs:
- console: - console:

Loading…
Cancel
Save