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

Commit 0247b3a

Browse files
authored
[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.
1 parent 34ee3a9 commit 0247b3a

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

mycroft/configuration/mycroft.conf

+8
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,14 @@
263263
// If not defined, the default log level is INFO.
264264
//"log_level": "INFO",
265265

266+
// Format of logs to store.
267+
// NOTE: This configuration setting is special and can only be changed in the
268+
// SYSTEM or USER configuration file, it will not be read if defined in the
269+
// DEFAULT (here) or in the REMOTE mycroft config.
270+
// If not defined, the default log format is:
271+
// {asctime} | {levelname:8} | {process:5} | {name} | {message}
272+
//"log_format": "{asctime} | {levelname:8} | {process:5} | {name} | {message}",
273+
266274
// Messagebus types that will NOT be output to logs
267275
"ignore_logs": ["enclosure.mouth.viseme", "enclosure.mouth.display"],
268276

mycroft/util/log.py

+4
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ def init(cls):
8787
cls.handler.setFormatter(formatter)
8888

8989
config = mycroft.configuration.Configuration.get(remote=False)
90+
if config.get('log_format'):
91+
formatter = logging.Formatter(config.get('log_format'), style='{')
92+
cls.handler.setFormatter(formatter)
93+
9094
cls.level = logging.getLevelName(config.get('log_level', 'INFO'))
9195

9296
# Enable logging in external modules

test/unittests/util/commented.json

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
"test": false
8686
},
8787
"log_level": "DEBUG",
88+
"log_format": "{asctime} {levelname} {process} {name} {message}",
8889
"ignore_logs": ["enclosure.mouth.viseme"],
8990
"session": {
9091
"ttl": 180

test/unittests/util/plain.json

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"test": false
6868
},
6969
"log_level": "DEBUG",
70+
"log_format": "{asctime} {levelname} {process} {name} {message}",
7071
"ignore_logs": ["enclosure.mouth.viseme"],
7172
"session": {
7273
"ttl": 180

0 commit comments

Comments
 (0)