Include docker container hostname in logger

This commit is contained in:
Einar Forselv 2019-11-25 21:21:00 +01:00
parent a35814fd2d
commit d910c62c62
1 changed files with 3 additions and 2 deletions

View File

@ -1,12 +1,13 @@
import logging
import os
import sys
logger = logging.getLogger('restic_volume_backup')
HOSTNAME = os.environ['HOSTNAME']
level = logging.INFO
logger.setLevel(level)
ch = logging.StreamHandler(stream=sys.stdout)
ch.setLevel(level)
ch.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
# ch.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
ch.setFormatter(logging.Formatter(f'%(asctime)s - {HOSTNAME} - %(name)s - %(levelname)s - %(message)s'))
logger.addHandler(ch)