mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-08-03 12:40:00 +00:00
v3: do not log entire promise on error and add ability to enable console logging of errors in prod
This commit is contained in:
parent
20f9bbf449
commit
0cb0780c14
2 changed files with 10 additions and 9 deletions
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"PORT":3000,
|
||||
"ENABLE_CONSOLE_LOGS_IN_PROD":"false",
|
||||
"IP":"0.0.0.0",
|
||||
"CORES":1,
|
||||
"BASE_URL":"http://localhost:3000",
|
||||
|
|
@ -33,7 +34,7 @@
|
|||
"EMAIL_SERVER": {
|
||||
"url": "http://example.com",
|
||||
"authUser": "user",
|
||||
"authPassword": "password"
|
||||
"authPassword": "password"
|
||||
},
|
||||
"S3":{
|
||||
"bucket":"bucket",
|
||||
|
|
@ -60,7 +61,7 @@
|
|||
"subdomain": "subdomain",
|
||||
"token": "token",
|
||||
"username": "username",
|
||||
"password": "password"
|
||||
"password": "password"
|
||||
},
|
||||
"PUSH_CONFIGS": {
|
||||
"GCM_SERVER_API_KEY": "",
|
||||
|
|
|
|||
|
|
@ -5,17 +5,19 @@ import _ from 'lodash';
|
|||
|
||||
const IS_PROD = nconf.get('IS_PROD');
|
||||
const IS_TEST = nconf.get('IS_TEST');
|
||||
const ENABLE_CONSOLE_LOGS_IN_PROD = nconf.get('ENABLE_CONSOLE_LOGS_IN_PROD') === 'true';
|
||||
|
||||
const logger = new winston.Logger();
|
||||
|
||||
if (IS_PROD) {
|
||||
// TODO production logging, use loggly and new relic too
|
||||
// log errors to console too
|
||||
logger
|
||||
.add(winston.transports.Console, {
|
||||
|
||||
if (ENABLE_CONSOLE_LOGS_IN_PROD) {
|
||||
logger.add(winston.transports.Console, {
|
||||
colorize: true,
|
||||
prettyPrint: true,
|
||||
});
|
||||
}
|
||||
} else if (IS_TEST) {
|
||||
// Do not log anything when testing
|
||||
} else {
|
||||
|
|
@ -53,10 +55,8 @@ let loggerInterface = {
|
|||
|
||||
// Logs unhandled promises errors
|
||||
// when no catch is attached to a promise a unhandledRejection event will be triggered
|
||||
process.on('unhandledRejection', function handlePromiseRejection (reason, promise) {
|
||||
loggerInterface.error(reason, {
|
||||
promise,
|
||||
});
|
||||
process.on('unhandledRejection', function handlePromiseRejection (reason) {
|
||||
loggerInterface.error(reason);
|
||||
});
|
||||
|
||||
module.exports = loggerInterface;
|
||||
|
|
|
|||
Loading…
Reference in a new issue