Skip to content

Commit

Permalink
Make an stderr handler available as well and provide a way to swap be…
Browse files Browse the repository at this point in the history
…tween them
  • Loading branch information
Jacob Beck committed May 1, 2019
1 parent 154aae5 commit 4c02b4a
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion core/dbt/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def notice(self, msg, *args, **kwargs):
stdout_handler.setFormatter(logging.Formatter('%(message)s'))
stdout_handler.setLevel(NOTICE)

stderr_handler = logging.StreamHandler()
stderr_handler.setFormatter(logging.Formatter('%(message)s'))
stderr_handler.setLevel(WARNING)


logger = logging.getLogger('dbt')
logger.addHandler(stdout_handler)
logger.setLevel(DEBUG)
Expand Down Expand Up @@ -79,6 +84,13 @@ def notice(self, msg, *args, **kwargs):
initialized = False


def log_to_stderr(logger):
if stdout_handler in logger.handlers:
logger.handlers.remove(stdout_handler)
if stderr_handler not in logger.handlers:
logger.addHandler(stderr_handler)


def make_log_dir_if_missing(log_dir):
import dbt.clients.system
dbt.clients.system.make_directory(log_dir)
Expand All @@ -99,14 +111,17 @@ def default_formatter():


def initialize_logger(debug_mode=False, path=None):
global initialized, logger, stdout_handler
global initialized, logger, stdout_handler, stderr_handler

if initialized:
return

if debug_mode:
# we'll only use one of these, but just set both up
stdout_handler.setFormatter(default_formatter())
stdout_handler.setLevel(DEBUG)
stderr_handler.setFormatter(default_formatter())
stderr_handler.setLevel(DEBUG)

if path is not None:
make_log_dir_if_missing(path)
Expand Down

0 comments on commit 4c02b4a

Please sign in to comment.