Skip to content
Snippets Groups Projects
Commit 4e06613a authored by Ben Adida's avatar Ben Adida
Browse files

logging now supports multiple log files

parent b7bcbed1
No related branches found
No related tags found
No related merge requests found
......@@ -42,7 +42,7 @@ function router(app) {
// this should probably be an internal redirect
// as soon as relative paths are figured out.
app.get('/sign_in', function(req, res, next ) {
logging.userEntry(req);
logging.userEntry('browserid', req);
res.render('dialog.ejs', {
title: 'A Better Way to Sign In',
layout: false,
......
......@@ -25,26 +25,29 @@ const g_configs = {
hostname: 'browserid.org',
port: '443',
scheme: 'https',
use_minified_resources: true
use_minified_resources: true,
log_path: '/home/browserid/var/'
},
development: {
hostname: 'dev.diresworb.org',
port: '443',
scheme: 'https',
use_minified_resources: true
use_minified_resources: true,
log_path: '/home/browserid/var/'
},
beta: {
hostname: 'diresworb.org',
port: '443',
scheme: 'https',
use_minified_resources: true
use_minified_resources: true,
log_path: '/home/browserid/var/'
},
local: {
hostname: '127.0.0.1',
port: '10002',
scheme: 'http',
use_minified_resources: false,
log_path: 'log.txt'
log_path: './'
}
};
......
......@@ -6,37 +6,47 @@ const configuration = require("./configuration");
// 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})]
var LOGGERS = [];
function setupLogger(category) {
if (!log_path)
return console.log("no log path! Not logging!");
// don't create the logger if it already exists
if (LOGGERS[category])
return;
// FIXME: check if log_path is properly terminated
var filename = log_path + category + "-log.txt";
LOGGERS[category] = new (winston.Logger)({
transports: [new (winston.transports.File)({filename: filename})]
});
}
// entry is an object that will get JSON'ified
exports.log = function(entry) {
exports.log = function(category, entry) {
// entry must have at least a type
if (!entry.type)
throw new Error("every log entry needs a type");
// setup the logger if need be
setupLogger(category);
// timestamp
entry.at = new Date().toUTCString();
// 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));
LOGGERS[category].info(JSON.stringify(entry));
};
// utility function to log a bunch of stuff at user entry point
exports.userEntry = function(req) {
exports.log({
exports.userEntry = function(category, req) {
exports.log(category, {
type: 'signin',
browser: req.headers['user-agent'],
rp: req.headers['referer'],
// IP address (this probably needs to be replaced with the X-forwarded-for value
ip: req.connection.remoteAddress
});
console.log(JSON.stringify(req.headers));
};
\ No newline at end of file
......@@ -37,7 +37,7 @@ function doVerify(req, resp, next) {
audience,
function(payload) {
// log it!
logging.log({
logging.log('verifier', {
type: 'verify',
result: 'success',
rp: payload.audience
......@@ -53,7 +53,7 @@ function doVerify(req, resp, next) {
resp.json(result);
},
function(errorObj) {
logging.log({
logging.log('verifier', {
type: 'verify',
result: 'failure',
rp: audience
......@@ -63,7 +63,7 @@ function doVerify(req, resp, next) {
);
} catch (e) {
console.log(e.stack);
logging.log({
logging.log('verifier', {
type: 'verify',
result: 'failure',
rp: audience
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment