Skip to content

Commit

Permalink
Merge pull request #66 from pangeo-forge/logging-config
Browse files Browse the repository at this point in the history
Support setting arbitrary logging config
  • Loading branch information
yuvipanda authored Aug 19, 2023
2 parents 6a96e0a + 3cd642c commit a0fef17
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion pangeo_forge_runner/commands/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from pythonjsonlogger import jsonlogger
from repo2docker import contentproviders
from traitlets import Bool, Instance, List, Unicode
from traitlets import Bool, Dict, Instance, List, Unicode
from traitlets.config import Application

# Common aliases we want to support in *all* commands
Expand Down Expand Up @@ -41,6 +41,21 @@ class BaseCommand(Application):

log_level = logging.INFO

logging_config = Dict(
{},
config=True,
help="""
Logging configuration for this python application.
When set, this value is passed to logging.config.dictConfig,
and can be used to configure how logs *throughout the application*
are handled, not just for logs from this application alone.
See https://docs.python.org/3/library/logging.config.html#logging.config.dictConfig
for more details.
""",
)

repo = Unicode(
"",
config=True,
Expand Down Expand Up @@ -199,6 +214,13 @@ def initialize(self, argv=None):
# Load traitlets config from a config file if present
self.load_config_file(self.config_file)

# Allow arbitrary logging config if set
# We do this first up so any custom logging we set up ourselves
# is not affected, as by default dictConfig will replace all
# existing config.
if self.logging_config:
logging.config.dictConfig(self.logging_config)

# The application communicates with the outside world via
# stdout, and we structure this communication via logging.
# So let's setup the default logger to log to stdout, rather
Expand Down

0 comments on commit a0fef17

Please sign in to comment.