Use same logging format for file and stream

The file logging handler was using a timestamped output format,
while the stream handler was just dumping the log message without
any extra context.  This creates some weird issues if you want to
be explicit that a message is an error, because prepending ERROR:
to the logging string results in a double message in the log file.

Since the timestamped logging format is probably useful anyway,
let's just use that everywhere and not have to worry about
redundantly specifying the severity of a log message.  This also
allows us to remove the awk pipe for the puppet apply since we'll
already be timestamping the output.

Change-Id: I2bafc5f167eea3dbac77d2720c1df0672d1276e3
This commit is contained in:
Ben Nemec 2016-09-27 16:44:23 +00:00
parent 72b959afaf
commit 1510844ba5
2 changed files with 5 additions and 2 deletions

View File

@ -5,7 +5,7 @@ set -o pipefail
function puppet_apply {
set +e
$@ 2>&1 | awk '{print strftime("%Y-%m-%d %H:%M:%S") " - "$0; fflush()}'
$@ 2>&1
rc=$?
set -e

View File

@ -469,7 +469,10 @@ def _configure_logging(level, filename):
level=level)
global LOG
LOG = logging.getLogger(__name__)
LOG.addHandler(logging.StreamHandler())
handler = logging.StreamHandler()
formatter = logging.Formatter(DEFAULT_LOG_FORMAT)
handler.setFormatter(formatter)
LOG.addHandler(handler)
def _load_config():