Skip to content

Commit

Permalink
Merge pull request #6 from transferwise/default-logging-conf
Browse files Browse the repository at this point in the history
Add default config that meets singer spec criteria
  • Loading branch information
Samira-El authored Feb 17, 2020
2 parents 76db9db + 5eaddc8 commit 9c73d13
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
8 changes: 7 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,11 @@
'singer-tools'
]
},
packages=find_packages(),
packages=['singer'],
package_data={
'singer': [
'logging.conf'
]
},
include_package_data=True
)
6 changes: 6 additions & 0 deletions singer/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@

def get_logger(name='singer'):
"""Return a Logger instance to use in singer."""
# Use custom logging config provided by environment variable
if 'LOGGING_CONF_FILE' in os.environ and os.environ['LOGGING_CONF_FILE']:
path = os.environ['LOGGING_CONF_FILE']
logging.config.fileConfig(path, disable_existing_loggers=False)
# Use the default logging conf that meets the singer specs criteria
else:
this_dir, _ = os.path.split(__file__)
path = os.path.join(this_dir, 'logging.conf')
logging.config.fileConfig(path, disable_existing_loggers=False)

return logging.getLogger(name)
25 changes: 25 additions & 0 deletions singer/logging.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[loggers]
keys=root

[handlers]
keys=stderr

[formatters]
keys=child

[logger_root]
level=INFO
handlers=stderr
formatter=child
propagate=0

[handler_stderr]
level=INFO
class=StreamHandler
formatter=child
args=(sys.stderr,)

[formatter_child]
class=logging.Formatter
format=time=%(asctime)s name=%(name)s level=%(levelname)s message=%(message)s
datefmt=%Y-%m-%d %H:%M:%S

0 comments on commit 9c73d13

Please sign in to comment.