[log_format] Add an option to change the log format (#3016)

* [log_format] Add an option to change the log format

Hacing an option to change the log format could be useful when logs
are shipped into an aggregator such as Elasticsearch.

The current format is very hard to parse.

* [log_format] Set default Formatter

Because mycroft.configuration.Configuration() class import LOG class,
a default Formatter have to be defined before import the
mycroft.configuration.Configuration() class.
feature/file-system
Gaëtan Trellu 2021-10-29 01:29:22 -04:00 committed by GitHub
parent 34ee3a9a84
commit 0247b3a4b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 0 deletions

View File

@ -263,6 +263,14 @@
// If not defined, the default log level is INFO.
//"log_level": "INFO",
// Format of logs to store.
// NOTE: This configuration setting is special and can only be changed in the
// SYSTEM or USER configuration file, it will not be read if defined in the
// DEFAULT (here) or in the REMOTE mycroft config.
// If not defined, the default log format is:
// {asctime} | {levelname:8} | {process:5} | {name} | {message}
//"log_format": "{asctime} | {levelname:8} | {process:5} | {name} | {message}",
// Messagebus types that will NOT be output to logs
"ignore_logs": ["enclosure.mouth.viseme", "enclosure.mouth.display"],

View File

@ -87,6 +87,10 @@ class LOG:
cls.handler.setFormatter(formatter)
config = mycroft.configuration.Configuration.get(remote=False)
if config.get('log_format'):
formatter = logging.Formatter(config.get('log_format'), style='{')
cls.handler.setFormatter(formatter)
cls.level = logging.getLevelName(config.get('log_level', 'INFO'))
# Enable logging in external modules

View File

@ -85,6 +85,7 @@
"test": false
},
"log_level": "DEBUG",
"log_format": "{asctime} {levelname} {process} {name} {message}",
"ignore_logs": ["enclosure.mouth.viseme"],
"session": {
"ttl": 180

View File

@ -67,6 +67,7 @@
"test": false
},
"log_level": "DEBUG",
"log_format": "{asctime} {levelname} {process} {name} {message}",
"ignore_logs": ["enclosure.mouth.viseme"],
"session": {
"ttl": 180