Skip to content

Commit

Permalink
Merge pull request #3 from airdrummingfool/config_winston
Browse files Browse the repository at this point in the history
Adding the ability to configure Winston's file transport logging level.
  • Loading branch information
farhad-a authored Jun 23, 2020
2 parents 7747033 + 9fd1893 commit 834f911
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ mqtt:

# Port number to listen on
port: 8080

# Log level for Winston's file transports (set to `error` to reduce logging to a minimum)
# winston_file_log_level: error
8 changes: 8 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var CONFIG_DIR = process.env.CONFIG_DIR || process.cwd(),
// The topic type to send state changes to smartthings
TOPIC_WRITE_STATE = 'set_state',
SUFFIX_WRITE_STATE = 'state_write_suffix',
WINSTON_FILE_LOG_LEVEL = 'winston_file_log_level',
RETAIN = 'retain';

var app = express(),
Expand Down Expand Up @@ -137,6 +138,11 @@ function migrateState (version) {
config.port = 8080;
}

// Default file transport logging level
if (!config[WINSTON_FILE_LOG_LEVEL]) {
config[WINSTON_FILE_LOG_LEVEL] = 'info';
}

// Default protocol
if (!url.parse(config.mqtt.host).protocol) {
config.mqtt.host = 'mqtt://' + config.mqtt.host;
Expand Down Expand Up @@ -323,6 +329,8 @@ async.series([
winston.info('Perfoming configuration migration');
migrateState(state.version);

winston.default.transports.file.level = config[WINSTON_FILE_LOG_LEVEL];

process.nextTick(next);
},
function connectToMQTT (next) {
Expand Down

0 comments on commit 834f911

Please sign in to comment.