Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Commit

Permalink
[log_format] Add an option to change the log format (#3016)
Browse files Browse the repository at this point in the history
* [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.
  • Loading branch information
goldyfruit authored Oct 29, 2021
1 parent 34ee3a9 commit 0247b3a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions mycroft/configuration/mycroft.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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"],

Expand Down
4 changes: 4 additions & 0 deletions mycroft/util/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ def init(cls):
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
Expand Down
1 change: 1 addition & 0 deletions test/unittests/util/commented.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"test": false
},
"log_level": "DEBUG",
"log_format": "{asctime} {levelname} {process} {name} {message}",
"ignore_logs": ["enclosure.mouth.viseme"],
"session": {
"ttl": 180
Expand Down
1 change: 1 addition & 0 deletions test/unittests/util/plain.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"test": false
},
"log_level": "DEBUG",
"log_format": "{asctime} {levelname} {process} {name} {message}",
"ignore_logs": ["enclosure.mouth.viseme"],
"session": {
"ttl": 180
Expand Down

0 comments on commit 0247b3a

Please sign in to comment.