summaryrefslogtreecommitdiffstats
path: root/src/log.py
diff options
context:
space:
mode:
authorJavier Sánchez Parra <jsanchez@soleta.eu>2022-10-07 15:07:57 +0200
committerJavier Sánchez Parra <jsanchez@soleta.eu>2022-11-02 16:37:46 +0100
commit94f6793f96e75292bdccf20e58e1769b992f4db2 (patch)
treec0b1388f50031bfcf321ed8fe045b7e61b1b5321 /src/log.py
parentf1fff0b0b6587363523e408c19732ff7c1fef411 (diff)
log: declare samba handler only in live mode
ogClient in linux mode only write its logs to syslog and the console. Also, raise exception if mode its not supported.
Diffstat (limited to 'src/log.py')
-rw-r--r--src/log.py29
1 files changed, 20 insertions, 9 deletions
diff --git a/src/log.py b/src/log.py
index ef1fe71..cabe4d0 100644
--- a/src/log.py
+++ b/src/log.py
@@ -37,11 +37,6 @@ def _default_logging_linux():
'formatter': 'formatter.syslog',
'address': '/dev/log',
},
- 'samba': {
- 'class': 'logging.FileHandler',
- 'formatter': 'formatter.syslogtime',
- 'filename': f'/opt/opengnsys/log/{getifaddr(os.getenv("DEVICE"))}.log',
- },
},
'loggers': {
'': {
@@ -53,6 +48,21 @@ def _default_logging_linux():
return logconfig
+def _default_logging_live():
+ from src.utils.net import getifaddr
+ logconfig = _default_logging_linux()
+ samba = {
+ 'samba': {
+ 'class': 'logging.FileHandler',
+ 'formatter': 'formatter.syslogtime',
+ 'filename': f'/opt/opengnsys/log/{getifaddr(os.getenv("DEVICE"))}.log',
+ }
+ }
+ logconfig['handlers'].update(samba)
+ logconfig['loggers']['']['handlers'].append('samba')
+ return logconfig
+
+
def _default_logging_win():
logconfig = {
'version': 1,
@@ -93,11 +103,12 @@ def configure_logging(mode, level):
"""
if mode == 'windows':
logconfig = _default_logging_win()
- else:
+ elif mode == 'linux':
logconfig = _default_logging_linux()
-
- if mode == 'live':
- logconfig['loggers']['']['handlers'].append('samba')
+ elif mode == 'live':
+ logconfig = _default_logging_live()
+ else:
+ raise ValueError(f'Error: Mode {mode} not supported')
logconfig['loggers']['']['level'] = level