summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/log.py140
1 files changed, 73 insertions, 67 deletions
diff --git a/src/log.py b/src/log.py
index bf00c71..ef1fe71 100644
--- a/src/log.py
+++ b/src/log.py
@@ -2,79 +2,85 @@ import logging
import logging.config
import os
-from src.utils.net import getifaddr
-DEFAULT_LOGGING_LINUX = {
- 'version': 1,
- 'disable_existing_loggers': False,
- 'formatters': {
- 'formatter.syslog': {
- '()': 'logging.Formatter',
- 'format': 'ogClient: [{levelname}] - {message}',
- 'style': '{',
+def _default_logging_linux():
+ from src.utils.net import getifaddr
+ logconfig = {
+ 'version': 1,
+ 'disable_existing_loggers': False,
+ 'formatters': {
+ 'formatter.syslog': {
+ '()': 'logging.Formatter',
+ 'format': 'ogClient: [{levelname}] - {message}',
+ 'style': '{',
+ },
+ 'formatter.console': {
+ '()': 'logging.Formatter',
+ 'format': '[{levelname}] - {message}',
+ 'style': '{',
+ },
+ 'formatter.syslogtime': {
+ '()': 'logging.Formatter',
+ 'datefmt': '%Y-%m-%d %H:%M:%S',
+ 'format': '({asctime}) ogClient: [{levelname}] - {message}',
+ 'style': '{',
+ },
},
- 'formatter.console': {
- '()': 'logging.Formatter',
- 'format': '[{levelname}] - {message}',
- 'style': '{',
- },
- 'formatter.syslogtime': {
- '()': 'logging.Formatter',
- 'datefmt': '%Y-%m-%d %H:%M:%S',
- 'format': '({asctime}) ogClient: [{levelname}] - {message}',
- 'style': '{',
- },
- },
- 'handlers': {
- 'console': {
- 'class': 'logging.StreamHandler',
- 'formatter': 'formatter.console',
- 'stream': 'ext://sys.stdout',
- },
- 'syslog': {
- 'class': 'logging.handlers.SysLogHandler',
- 'formatter': 'formatter.syslog',
- 'address': '/dev/log',
- },
- 'samba': {
- 'class': 'logging.FileHandler',
- 'formatter': 'formatter.syslogtime',
- 'filename': f'/opt/opengnsys/log/{getifaddr(os.getenv("DEVICE"))}.log',
- },
- },
- 'loggers': {
- '': {
- 'handlers': ['syslog', 'console'],
- 'level': 'INFO',
+ 'handlers': {
+ 'console': {
+ 'class': 'logging.StreamHandler',
+ 'formatter': 'formatter.console',
+ 'stream': 'ext://sys.stdout',
+ },
+ 'syslog': {
+ 'class': 'logging.handlers.SysLogHandler',
+ 'formatter': 'formatter.syslog',
+ 'address': '/dev/log',
+ },
+ 'samba': {
+ 'class': 'logging.FileHandler',
+ 'formatter': 'formatter.syslogtime',
+ 'filename': f'/opt/opengnsys/log/{getifaddr(os.getenv("DEVICE"))}.log',
+ },
},
+ 'loggers': {
+ '': {
+ 'handlers': ['syslog', 'console'],
+ 'level': 'INFO',
+ },
+ }
}
-}
+ return logconfig
-DEFAULT_LOGGING_WIN = {
- 'version': 1,
- 'disable_existing_loggers': False,
- 'formatters': {
- 'formatter.console': {
- '()': 'logging.Formatter',
- 'format': 'ogClient: [{levelname}] - {message}',
- 'style': '{',
- }
- },
- 'handlers': {
- 'console': {
- 'level': 'DEBUG',
- 'class': 'logging.StreamHandler',
- 'formatter': 'formatter.console',
- 'stream': 'ext://sys.stdout',
+
+def _default_logging_win():
+ logconfig = {
+ 'version': 1,
+ 'disable_existing_loggers': False,
+ 'formatters': {
+ 'formatter.console': {
+ '()': 'logging.Formatter',
+ 'format': 'ogClient: [{levelname}] - {message}',
+ 'style': '{',
+ }
},
- },
- 'loggers': {
- '': {
- 'handlers': ['console'],
- 'level': 'DEBUG',
+ 'handlers': {
+ 'console': {
+ 'level': 'DEBUG',
+ 'class': 'logging.StreamHandler',
+ 'formatter': 'formatter.console',
+ 'stream': 'ext://sys.stdout',
+ },
},
+ 'loggers': {
+ '': {
+ 'handlers': ['console'],
+ 'level': 'DEBUG',
+ },
+ }
}
-}
+ return logconfig
+
def configure_logging(mode, level):
"""
@@ -86,9 +92,9 @@ def configure_logging(mode, level):
logging to the expected samba shared log file ({ip}.txt.log).
"""
if mode == 'windows':
- logconfig = DEFAULT_LOGGING_WIN
+ logconfig = _default_logging_win()
else:
- logconfig = DEFAULT_LOGGING_LINUX
+ logconfig = _default_logging_linux()
if mode == 'live':
logconfig['loggers']['']['handlers'].append('samba')