Last active
June 28, 2017 18:35
-
-
Save sht5/28ef5cd3f049e52d9d6c27989e72d28a to your computer and use it in GitHub Desktop.
logging utility functions
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
const config = require('config'); // library for code configuration setups | |
const logHttpRequestError = (request, errorObj) => { | |
const logObj = { | |
server_type : config.get('server_type'), // we take the server type from configuration | |
//in order to know which server created the log | |
//such as production\staging etc | |
message : errorObj.message, | |
stack : errorObj.stack, | |
url : request.url, | |
query : JSON.stringify(request.query), | |
body : JSON.stringify(request.body), | |
userEmail : request.user.email, | |
initiator : 'server', | |
errorType : consts.LOGGING_ERROR_TYPES.HTTP_REST_ERROR, | |
}; | |
logger.error(logObj); | |
}; | |
const logGenerelError = (errorObj, errorType, otherProperties = {}) => { | |
let logObj = { | |
server_type : config.get('server_type'), | |
message : errorObj.message, | |
stack : errorObj.stack, | |
initiator : 'server', | |
errorType, | |
} | |
logObj = Object.assign(otherProperties, logObj); // merge objects | |
logger.error(logObj); | |
} | |
const logSimpleTextError = (message, errorType, otherProperties = {}) => { | |
let logObj = { | |
server_type : config.get('server_type'), | |
message, | |
errorType, | |
} | |
logObj = Object.assign(otherProperties, logObj); | |
logger.error(logObj); | |
} | |
module.exports = { | |
logHttpRequestError, | |
logGenerelError, | |
logSimpleTextError | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment