Created
May 18, 2016 14:56
-
-
Save evantahler/75d011647f2a872fbb5f4af2a780bfcb to your computer and use it in GitHub Desktop.
in-line-logger.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// middleware to set up the logger for the connection | |
var middleware = { | |
name: 'in-line-logger', | |
global: true, | |
priority: 1, | |
preProcessor: function(data, next){ | |
data.log = function(s){ | |
// create a connection ID | |
if(!data.connectionId){ data.connectionId = uuid.v4(); } | |
// set up the extra data you want to log | |
var logData = { params: {}}; | |
for(var key in data.params){ logData.params[key] = data.params[key]; } | |
logData.ip = data.connection.ip; | |
logData.sessionId = data.session.id; //or however you load this normally | |
api.log(s, 'info', logData); | |
} | |
} | |
} | |
api.actions.addMiddleware(middleware); | |
// then, in your actions... | |
data.log('I am in step 1'); | |
data.log('I am in step 2'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment