Created
May 2, 2014 12:12
-
-
Save TerryMooreII/48b98e9080996eab11db to your computer and use it in GitHub Desktop.
Code to write the log files - Cardinal Solutions ALF blog post
This file contains hidden or 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
var writeToLog = function(project, service, data){ | |
var date = new Date(); | |
var directory = properties.baseDir + '/logs'; | |
fs.exists(directory, function (exists) { | |
if (!exists){ | |
fs.mkdirSync(directory); | |
} | |
for (var key in data) { | |
var file = project + '_'+ service + '_' + key + '.log'; | |
var logPathFile = directory + '/' + file; | |
if (data[key]){ | |
var consoleMsg = key + '\t[' + service.toUpperCase() + ']\n' + data[key] + '\n\n'; | |
if (properties.logToConsole){ | |
console.log(consoleMsg); | |
} | |
var msg = date + '\t[' + service.toUpperCase() + ']\n' + data[key] + '\n\n'; | |
fs.appendFile(logPathFile, msg, function(err) { | |
if(err) { | |
console.log('Unable to write to log file: ' + logPathFile); | |
console.log(err); | |
return false; | |
} | |
}); | |
} | |
} | |
}); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment