Skip to content

Commit

Permalink
feat: log level support (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakowenko committed Sep 11, 2021
1 parent eeb7852 commit 5f91b83
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api/src/constants/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,7 @@ module.exports = {
priority: 5,
},
},
logs: {
level: 'info',
},
};
7 changes: 7 additions & 0 deletions api/src/util/logger.util.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { createLogger, format, transports } = require('winston');
const util = require('util');
const { core: SYSTEM_CORE } = require('../constants/system');
const { LOGS } = require('../constants');
const mqtt = require('./mqtt.util');
const redact = require('./redact-secrets.util');

Expand All @@ -17,6 +18,8 @@ module.exports.init = () => {
const logFormat = format.combine(combineMessageAndSplat(), format.simple());

const logger = createLogger({
silent: LOGS.LEVEL === 'silent',
level: LOGS.LEVEL,
transports: [
new transports.Console({
format: format.combine(
Expand Down Expand Up @@ -59,4 +62,8 @@ module.exports.init = () => {
: JSON.stringify({ message }),
});
};
console.http = (...args) => logger.http(...args);
console.verbose = (...args) => logger.verbose(...args);
console.debug = (...args) => logger.debug(...args);
console.silly = (...args) => logger.silly(...args);
};

0 comments on commit 5f91b83

Please sign in to comment.