UNPKG

lincoln

Version:

Presidential logging. Fancy loggers for winston.

64 lines (55 loc) 1.55 kB
// Generated by CoffeeScript 1.6.3 var constructorRegex, methodRegex, moduleRegex, objectRegex, pad; constructorRegex = /^new /; methodRegex = /at (.*) \(/; moduleRegex = /(\w+)\.?(\w+)?:\d/; objectRegex = /^Object\.(module\.exports\.)?/; exports.captureLocation = function(message, metadata) { var error, line, match, method, module, stack; if (metadata.method || metadata.module) { return; } if (message instanceof Error) { stack = error.stack; line = stack.split('\n')[1]; } else { error = null; stack = (new Error()).stack; line = stack.split('\n')[11]; } method = '<unknown>'; module = ''; if (match = methodRegex.exec(line)) { method = match[1].replace(objectRegex, ''); if (constructorRegex.test(method)) { method = method.replace(constructorRegex, '') + '.constructor'; } } if (match = moduleRegex.exec(line)) { module = match[1]; } metadata.method = method; return metadata.module = module; }; exports.pad = pad = function(n) { n = n + ''; if (n.length >= 2) { return n; } else { return new Array(2 - n.length + 1).join('0') + n; } }; exports.timestamp = function() { var d, date, hour, min, month, sec, year; d = new Date(); year = d.getUTCFullYear(); month = pad(d.getUTCMonth() + 1); date = pad(d.getUTCDate()); hour = pad(d.getUTCHours()); min = pad(d.getUTCMinutes()); sec = pad(d.getUTCSeconds()); return "" + year + "-" + month + "-" + date + " " + hour + ":" + min + ":" + sec; }; /* //@ sourceMappingURL=utils.map */