log.js | |
---|---|
Tracing and logging support functions. | var log = exports; |
Property: log.streamA writable stream to which toddick log output is be written. Set to a different writable stream to direct log output to a file. | log.stream = process.stdout; |
Property: log.seperatorString used to seperate the log output fields. Default is a tab character. Assign a different string to change the field seperator. | log.seperator = "\t"; |
Property: log.eolString used at the end of a log line. Default is a newline character. Assign a different string to change the end of line marker. | log.eol = "\n"; |
Function: log.makeDataStringSerializes an object to a string for log output. Default uses JSON.stringify. Assign a different function to change the data output format. | log.makeDataString = function(data) {
var data_string;
if(typeof data === "undefined") {
data_string = "{}";
} else {
try {
data_string = JSON.stringify(data);
} catch(e) {
data_string = "(JSON.strigify failed: " + e + ")";
}
}
return data_string;
} |
Function: log.makeTimeStringCreates the date/time string used in log output. Default uses Date.toUTCString. Assign a different function to change the timestamp output format. | log.makeTimeString = function() {
var date = new Date();
return date.toUTCString();
} |
Function: log.writeWrites log output.
type - indicates the type of log output, e.g. trace, info or error. entity - a string identifing the entity that is doing the logging activity - a string identifing the activity being logged data - an object containing data to be included in the log output. The entity and activity values should be short strings. The details of the log output should be included in the data object. For example:
A timestamp is included in the log output. It is generated using the log.makeLogTimeString function. The data object is converted to a string using log.makeDataString. Fields are seperated by the log.seperator string. The output is terminated by the log.eol string. The log output is written to the log.stream stream. | log.write = function(type, entity, activity, data) {
var data_string = log.makeDataString(data);
var time_string = log.makeTimeString();
var entry =
time_string + log.seperator +
type + log.seperator +
entity + log.seperator +
activity + log.seperator +
data_string + log.eol;
log.stream.write(entry);
} |
Function: log.traceWrites trace level log output. Calls toddick.log with "trace" for the type parameter. | log.trace = function(entity, activity, data) {
log.write("trace", entity, activity, data);
} |
Function: log.infoWrites information level log output. Calls toddick.log with "info" for the type parameter. | log.info = function(entity, activity, data) {
log.write("info", entity, activity, data);
} |
Function: log.errorWrites error level log output. Calls toddick.log with "error" for the type parameter. | log.error = function(entity, activity, data) {
log.write("error", entity, activity, data);
}
|