Skip to content

Commit

Permalink
Fix configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
romaryd committed Jan 5, 2018
1 parent 10f2e4c commit b0960a3
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions loggingmixin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

'formatters': {
'simple': {
'format': '%(name)s %(levelname)s [%(asctime)s] -- %(message)s',
'format': '%(name)s %(user)s %(levelname)s [%(asctime)s] -- %(message)s',
'datefmt': ISO8601_DATETIME,
}
},
Expand All @@ -31,31 +31,27 @@
},

'console': {
'level': 'DEBUG',
'level': os.environ.get('LOGGING_CONSOLE_LEVEL', 'DEBUG'),
'class': 'logging.StreamHandler',
'formatter': 'simple',
},

'logfile': {
'level': 'INFO',
'level': os.environ.get('LOGGING_FILE_LEVEL', 'INFO'),
'class': 'logging.handlers.RotatingFileHandler',
'filename': os.environ.get('LOGGING_FILE', 'DEBUG'),
'filename': os.environ.get('LOGGING_FILE', 'LOG'),
'maxBytes': 536870912, # 512 MB
'formatter': 'simple',
}
},

'loggers': {
'lifoid': {
'level': os.environ.get('LOGGING_LEVEL', 'DEBUG'),
'handlers': ['logfile'],
'propagagte': True,
},
'lifoid.service': {
'{}'.format(os.environ.get('LOGGING_SERVICE', 'process')): {
'level': os.environ.get('LOGGING_LEVEL', 'DEBUG'),
'handlers': ['logfile', 'console'],
'propagate': False,
},
'handlers': os.environ.get('LOGGING_HANDLERS',
'console').split(','),
'propagate': 0,
}
},
}

Expand All @@ -66,7 +62,7 @@

class WrappedLogger(object):
"""
Wraps the Python logging module's logger object to ensure that all lifoid
Wraps the Python logging module's logger object to ensure that all process
logging happens with the correct configuration as well as any extra
information that might be required by the log file (for example, the user
on the machine, hostname, IP address lookup, etc).
Expand Down Expand Up @@ -136,7 +132,7 @@ class ServiceLogger(WrappedLogger):
"""

logger = logging.getLogger(os.environ.get('LOGGING_SERVICE',
'service'))
'process'))

def __init__(self, **kwargs):
self._user = kwargs.pop('user', None)
Expand All @@ -146,7 +142,7 @@ def __init__(self, **kwargs):
def user(self):
if not self._user:
self._user = getpass.getuser()
return self._user
return self._user

def log(self, level, message, *args, **kwargs):
"""
Expand Down

0 comments on commit b0960a3

Please sign in to comment.