From d7e0abd6a98e9dda16592ae24b7a6e39ab22cf66 Mon Sep 17 00:00:00 2001 From: Ben Adida <ben@adida.net> Date: Tue, 2 Aug 2011 19:48:59 -0700 Subject: [PATCH] added first logging infrastructure --- browserid/app.js | 1 + libs/logging.js | 28 ++++++++++++++++++++++++++++ package.json | 1 + 3 files changed, 30 insertions(+) create mode 100644 libs/logging.js diff --git a/browserid/app.js b/browserid/app.js index c62b6a2d8..e0519db1a 100644 --- a/browserid/app.js +++ b/browserid/app.js @@ -18,6 +18,7 @@ secrets = require('./lib/secrets.js'), db = require('./lib/db.js'), configuration = require('../libs/configuration.js'), substitution = require('../libs/substitute.js'); +logging = require("../libs/logging.js"); // looks unused, see run.js // const STATIC_DIR = path.join(path.dirname(__dirname), "static"); diff --git a/libs/logging.js b/libs/logging.js new file mode 100644 index 000000000..e166f27c5 --- /dev/null +++ b/libs/logging.js @@ -0,0 +1,28 @@ +const winston = require("winston"); +const configuration = require("./configuration"); + +// go through the configuration and determine log location +// for now we only log to one place +// FIXME: separate logs depending on purpose? + +var log_path = configuration.get('log_path'); +var LOGGER = null; +if (log_path) { + LOGGER= new (winston.Logger)({ + transports: [new (winston.transports.File)({filename: log_path})] + }); +} + +// entry is an object that will get JSON'ified +exports.log = function(entry) { + // entry must have at least a type + if (!entry.type) + throw new Error("every log entry needs a type"); + + // if no logger, go to console (FIXME: do we really want to log to console?) + if (LOGGER) + LOGGER.info(JSON.stringify(entry)); + else + winston.info(JSON.stringify(entry)); +}; + diff --git a/package.json b/package.json index 78fdad42f..85c35908c 100644 --- a/package.json +++ b/package.json @@ -15,5 +15,6 @@ , "temp": "0.2.0" , "express-csrf": "0.3.2" , "uglify-js": "1.0.6" + , "winston" : "0.3.3" } } \ No newline at end of file -- GitLab