[CORD-1357] Use new config in old logger
Change-Id: I109d922317d0d72ed4e694192dac6806bdf077a7
diff --git a/docs/modules/xosconfig.md b/docs/modules/xosconfig.md
index 094d93f..5cf2d9d 100644
--- a/docs/modules/xosconfig.md
+++ b/docs/modules/xosconfig.md
@@ -21,6 +21,9 @@
Config.init("/path/to/my/config.yaml")
```
+### Configuration defaults
+Note that defaults are defined for some of the configuration items. Defaults are defined in `lib/xos-config/xosconfig/default.py`.
+
### Reading data from the configuration file
To access static information defined in the `config.yaml` file you can use this api:
diff --git a/lib/xos-config/.gitignore b/lib/xos-config/.gitignore
index 161b154..1a050a8 100644
--- a/lib/xos-config/.gitignore
+++ b/lib/xos-config/.gitignore
@@ -1,2 +1,4 @@
.noseids
-build
\ No newline at end of file
+build
+XosConfig.egg-info
+dist
\ No newline at end of file
diff --git a/lib/xos-config/xosconfig/config-schema.yaml b/lib/xos-config/xosconfig/config-schema.yaml
index 5d30b86..b79905e 100644
--- a/lib/xos-config/xosconfig/config-schema.yaml
+++ b/lib/xos-config/xosconfig/config-schema.yaml
@@ -19,6 +19,8 @@
logging:
type: map
map:
+ logstash_hostport:
+ type: str
level:
type: str
channels:
diff --git a/lib/xos-config/xosconfig/default.py b/lib/xos-config/xosconfig/default.py
index eaea40a..02abaa6 100644
--- a/lib/xos-config/xosconfig/default.py
+++ b/lib/xos-config/xosconfig/default.py
@@ -1,7 +1,9 @@
DEFAULT_VALUES = {
'xos_dir': '/opt/xos',
'logging': {
+ 'file': '/var/log/xos.log',
'level': 'info',
- 'channels': ['file', 'console']
+ 'channels': ['file', 'console'],
+ 'logstash_hostport': 'cordloghost:5617'
}
}
\ No newline at end of file
diff --git a/xos/xos/logger.py b/xos/xos/logger.py
index 1f57a4a..f891d52 100644
--- a/xos/xos/logger.py
+++ b/xos/xos/logger.py
@@ -30,7 +30,7 @@
import logging
import logging.handlers
import logstash
-from xos.config import Config
+from xosconfig import Config
CRITICAL = logging.CRITICAL
ERROR = logging.ERROR
@@ -45,32 +45,23 @@
def __init__(self, logfile=None, loggername=None, level=logging.INFO):
- # Logstash config - try as specified explicitly in config
+ # Logstash config
try:
- logstash_host, logstash_port = Config().observer_logstash_hostport.split(':')
+ logstash_host, logstash_port = Config.get("logging.logstash_hostport").split(':')
logstash_handler = logstash.LogstashHandler(
logstash_host, int(logstash_port), version=1)
# always log at DEBUG level to logstash
logstash_handler.setLevel(logging.DEBUG)
except:
+ # if connection fails (eg: logstash is not there) just move on
logstash_handler = None
- # try using the default cordloghost:5617
- if not logstash_handler:
- try:
- logstash_handler = logstash.LogstashHandler(
- "cordloghost", 5617, version=1)
- # always log at DEBUG level to logstash
- logstash_handler.setLevel(logging.DEBUG)
- except:
- logstash_handler = None
-
# default is to locate loggername from the logfile if avail.
if not logfile:
- logfile = getattr(Config(), "log_file", "/var/log/xos.log")
+ logfile = Config.get("logging.file")
# allow config-file override of console/logfile level
- level_str = getattr(Config(), "log_level", None)
+ level_str = Config.get("logging.level")
if level_str:
level_str = level_str.lower()
@@ -158,7 +149,7 @@
def extract_context(self, cur):
try:
- observer_name = Config().observer_name
+ observer_name = Config.get("name")
cur['synchronizer_name'] = observer_name
except:
pass