-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #SB-21909 merge: Merge pull request #26 from JagadishPujari/sta…
…ndard-log Issue #SB-21909 feat: Change all logs to follow the standard log form at - Collaboration & Interaction
- Loading branch information
Showing
5 changed files
with
189 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* @file: index.js | ||
* @author: Jagadish P | ||
* @desc: using log4s, enables application wide logging. | ||
*/ | ||
var log4js = require('log4js') | ||
var fs = require('fs') | ||
var dir = '../../log' | ||
var configUtil = require('../sb-config-util') | ||
|
||
if (!fs.existsSync(dir)) { | ||
fs.mkdirSync(dir) | ||
} | ||
|
||
var options = { | ||
'appenders': [{ | ||
'type': 'clustered', | ||
'appenders': [ | ||
{ | ||
'type': 'console' | ||
}, { | ||
'type': 'logLevelFilter', | ||
'level': 'TRACE', | ||
'category': 'api', | ||
'appender': { | ||
'type': 'file', | ||
'maxLogSize': 26214400, | ||
'filename': '../../log/microService.log' | ||
} | ||
} | ||
] | ||
}] | ||
} | ||
|
||
log4js.configure(options) | ||
var logger = log4js.getLogger('api') | ||
|
||
var isLoggerEnabled = function () { | ||
var loggerEnabled = configUtil.getConfig('ENABLE_LOGGING') | ||
return (loggerEnabled !== undefined && loggerEnabled === 'true') | ||
} | ||
|
||
var info = function (data) { | ||
if (data) { | ||
logger.setLevel('INFO') | ||
logger.info(JSON.stringify(data)) | ||
} | ||
} | ||
|
||
var error = function (data) { | ||
if (data && isLoggerEnabled()) { | ||
logger.setLevel('ERROR') | ||
logger.error(JSON.stringify(data)) | ||
} | ||
} | ||
|
||
var warn = function (data) { | ||
if (data && isLoggerEnabled()) { | ||
logger.setLevel('WARN') | ||
logger.warn(JSON.stringify(data)) | ||
} | ||
} | ||
|
||
var trace = function (data) { | ||
if (data && isLoggerEnabled()) { | ||
logger.setLevel('TRACE') | ||
logger.trace(JSON.stringify(data)) | ||
} | ||
} | ||
|
||
module.exports.info = info | ||
module.exports.error = error | ||
module.exports.warn = warn | ||
module.exports.trace = trace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "sb_logger_util", | ||
"version": "1.0.0", | ||
"description": "this package serves as log", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "Jagadish", | ||
"license": "ISC", | ||
"dependencies": { | ||
"log4js": "^0.6.29" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters