Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding the ability to configure Winston's file transport logging level. #3

Merged
merged 1 commit into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,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