From b3e1490d631cbc1f9994ce97d96f07c697a326e1 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Fri, 1 Jan 2016 21:17:13 -0700 Subject: [PATCH] Add username to client.log --- core/client_connections.js | 1 + core/user_login.js | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/core/client_connections.js b/core/client_connections.js index 6a2504cc..2e838e77 100644 --- a/core/client_connections.js +++ b/core/client_connections.js @@ -18,6 +18,7 @@ function addNewClient(client, clientSock) { var id = client.session.id = clientConnections.push(client) - 1; // Create a client specific logger + // Note that this will be updated @ login with additional information client.log = logger.log.child( { clientId : id } ); var connInfo = { diff --git a/core/user_login.js b/core/user_login.js index cfa4caa4..3b5798a9 100644 --- a/core/user_login.js +++ b/core/user_login.js @@ -5,6 +5,7 @@ var theme = require('./theme.js'); var clientConnections = require('./client_connections.js').clientConnections; var userDb = require('./database.js').dbs.user; var sysProp = require('./system_property.js'); +var logger = require('./logger.js'); var async = require('async'); var _ = require('lodash'); @@ -48,13 +49,13 @@ function userLogin(client, username, password, cb) { var existingConnError = new Error('Already logged in as supplied user'); existingClientConnection.existingConn = true; - cb(existingClientConnection); - return; + return cb(existingClientConnection); } - // use client.user so we can get correct case - client.log.info( { username : user.username }, 'Successful login'); + // update client logger with addition of username + client.log = logger.log.child( { clientId : client.log.fields.clientId, username : user.username }); + client.log.info('Successful login'); async.parallel( [