Skip to content

Instantly share code, notes, and snippets.

@sht5
Last active June 28, 2017 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sht5/28ef5cd3f049e52d9d6c27989e72d28a to your computer and use it in GitHub Desktop.
Save sht5/28ef5cd3f049e52d9d6c27989e72d28a to your computer and use it in GitHub Desktop.
logging utility functions
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