mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-04-14 19:47:03 +00:00
chore(logging): add logging via Winston and wrapped it with a custom logging module
This commit is contained in:
parent
a9d7add1e3
commit
2188b5a6c0
3 changed files with 38 additions and 1 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -12,6 +12,8 @@ newrelic_agent.log
|
|||
.bower-tmp
|
||||
.bower-registry
|
||||
.bower-cache
|
||||
|
||||
*.log
|
||||
src/*/*.map
|
||||
src/*/*/*.map
|
||||
test/*.js
|
||||
|
|
|
|||
|
|
@ -45,7 +45,8 @@
|
|||
"passport": "~0.1.18",
|
||||
"passport-facebook": "~1.0.2",
|
||||
"newrelic": "~1.3.0",
|
||||
"connect-ratelimit": "0.0.6"
|
||||
"connect-ratelimit": "0.0.6",
|
||||
"winston": "~0.7.2"
|
||||
},
|
||||
"private": true,
|
||||
"subdomain": "habitrpg",
|
||||
|
|
|
|||
34
src/logging.js
Normal file
34
src/logging.js
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
var nconf = require('nconf');
|
||||
var winston = require('winston');
|
||||
|
||||
var logger;
|
||||
if (logger == null) {
|
||||
// We currently don't support logging on Heroku
|
||||
if (nconf.get('NODE_ENV') != 'production') {
|
||||
logger = new (winston.Logger)({
|
||||
transports: [
|
||||
new (winston.transports.Console)({colorize: true}),
|
||||
new (winston.transports.File)({ filename: 'habitrpg.log' })
|
||||
// TODO: Add email, loggly, or mongodb transports
|
||||
]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// A custom log function that wraps Winston. Makes it easy to instrument code
|
||||
// and still possible to replace Winston in the future.
|
||||
module.exports.log = function(/* variable args */) {
|
||||
logger.log.apply(logger, arguments);
|
||||
};
|
||||
|
||||
module.exports.info = function(/* variable args */) {
|
||||
logger.info.apply(logger, arguments);
|
||||
};
|
||||
|
||||
module.exports.warn = function(/* variable args */) {
|
||||
logger.warn.apply(logger, arguments);
|
||||
};
|
||||
|
||||
module.exports.error = function(/* variable args */) {
|
||||
winston.error(arguments);
|
||||
};
|
||||
Loading…
Reference in a new issue