mirror of
https://github.com/ZettaIO/restic-compose-backup.git
synced 2025-10-10 12:20:58 +00:00
Move package to src/ to properly separate what goes into docker image
This commit is contained in:
27
src/restic_compose_backup/log.py
Normal file
27
src/restic_compose_backup/log.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
logger = logging.getLogger('restic_compose_backup')
|
||||
HOSTNAME = os.environ['HOSTNAME']
|
||||
|
||||
DEFAULT_LOG_LEVEL = logging.INFO
|
||||
LOG_LEVELS = {
|
||||
'debug': logging.DEBUG,
|
||||
'info': logging.INFO,
|
||||
'warning': logging.WARNING,
|
||||
'error': logging.ERROR,
|
||||
}
|
||||
|
||||
def setup(level: str = 'warning'):
|
||||
"""Set up logging"""
|
||||
level = level or ""
|
||||
level = LOG_LEVELS.get(level.lower(), DEFAULT_LOG_LEVEL)
|
||||
logger.setLevel(level)
|
||||
|
||||
ch = logging.StreamHandler(stream=sys.stdout)
|
||||
ch.setLevel(level)
|
||||
# ch.setFormatter(logging.Formatter(f'%(asctime)s - {HOSTNAME} - %(name)s - %(levelname)s - %(message)s'))
|
||||
# ch.setFormatter(logging.Formatter(f'%(asctime)s - {HOSTNAME} - %(levelname)s - %(message)s'))
|
||||
ch.setFormatter(logging.Formatter(f'%(asctime)s - %(levelname)s: %(message)s'))
|
||||
logger.addHandler(ch)
|
Reference in New Issue
Block a user