Skip to content

Commit a7e09f5

Browse files
committed
Use STDERR as default log target
1 parent f2cb7c9 commit a7e09f5

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ in progress
99
- When title is not set in configuration settings, use ``mqttwarn: {topic}``
1010
instead of ``mqttwarn`` only. Thanks, Rob!
1111
- Add launch configuration for VSCode. Thanks, David!
12+
- Use STDERR as default log target
1213

1314

1415
2021-06-18 0.25.0

HANDBOOK.md

100755100644
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,19 @@ I've written an introductory post, explaining [what mqttwarn can be used for](ht
110110
cleansession = False
111111

112112
; logging
113+
114+
; Log format
113115
logformat = '%(asctime)-15s %(levelname)-5s [%(module)s] %(message)s'
114-
logfile = 'mqttwarn.log'
116+
117+
; Send log to STDERR (default)
118+
logfile = 'stream://sys.stderr'
115119

120+
; Write log output to file
121+
; logfile = 'mqttwarn.log'
122+
123+
; Turn off logging completely
124+
; logfile = false
125+
116126
; one of: CRITICAL, DEBUG, ERROR, INFO, WARN
117127
loglevel = DEBUG
118128

mqttwarn/commands.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ def setup_logging(config):
130130
LOGFORMAT = config.logformat
131131

132132
# Send log messages to sys.stderr by configuring "logfile = stream://sys.stderr"
133-
if LOGFILE.startswith('stream://'):
133+
if not LOGFILE:
134+
pass
135+
136+
elif LOGFILE.startswith('stream://'):
134137
LOGFILE = LOGFILE.replace('stream://', '')
135138
logging.basicConfig(stream=eval(LOGFILE), level=LOGLEVEL, format=LOGFORMAT)
136139

mqttwarn/configuration.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ def load_configuration(configfile=None, name='mqttwarn'):
191191
defaults = {
192192
'clientid': name,
193193
'lwt': 'clients/{}'.format(name),
194-
'logfile': os.getenv(name.upper() + 'LOG', name + '.log'),
195194
}
196195

197196
return Config(configfile, defaults=defaults)

0 commit comments

Comments
 (0)