Skip to content
Snippets Groups Projects
Commit 0f942794 authored by Andrew Newdigate's avatar Andrew Newdigate
Browse files

Merge pull request #5 from gitterHQ/feature/fluent-logging

In-app fluent logging
parents 41d8ca85 af3b0de8
No related branches found
No related tags found
No related merge requests found
/*jshint globalstrict:true, trailing:false, unused:true, node:true */
"use strict";
 
var processName = require('./process-name')
exports.create = function(options) {
var raven = require('raven');
var path = require('path');
Loading
Loading
@@ -20,9 +22,9 @@ exports.create = function(options) {
release: release
}, supplied);
 
var upstartJob = process.env.UPSTART_JOB || process.env.JOB;
if (upstartJob) {
tags.job = upstartJob.replace(/\-\d*$/,''); // gitter-webapp-1 becomes gitter-webapp
var appName = processName.getShortProcessName();
if (appName) {
tags.job = appName;
}
return tags;
} catch(e) {
Loading
Loading
Loading
Loading
@@ -3,16 +3,7 @@
var util = require('util');
var os = require('os');
var path = require('path');
function getProcessIdentifier() {
var upstartJob = process.env.UPSTART_JOB || process.env.JOB;
if (upstartJob) return upstartJob;
var main = require.main;
if (!main || !main.filename) return 'unknown';
return path.basename(main.filename, '.js');
}
var processName = require('./process-name')
 
function getDateIdentifier() {
function pad(d) {
Loading
Loading
@@ -46,11 +37,11 @@ exports.install = function(options) {
var logger = options.logger;
 
process.on('SIGUSR2', function() {
var identifier = getProcessIdentifier();
var appName = processName.getFullProcessName();
 
var filename = util.format('heap.%s.%s.%s.%s.heapsnapshot',
os.hostname(),
identifier,
appName,
process.pid,
getDateIdentifier());
 
Loading
Loading
/*jshint globalstrict:true, trailing:false, unused:true, node:true */
"use strict";
 
var processName = require('./process-name')
exports.create = function(options) {
var winston = require("winston");
var fs = require('fs');
Loading
Loading
@@ -108,7 +110,31 @@ exports.create = function(options) {
defaultLogger.remove({ name: name });
}
 
if(nconf.get('logging:logToFile') && nconf.get('LOG_FILE')) {
if(nconf.get("logging:logToUDP")) {
var appName = processName.getGenericProcessName();
if (appName) {
require('winston-udp')
var os = require('os')
defaultLogger.add(winston.transports.UDP, {
host: nconf.get('logging:udpHost') || '127.0.0.1',
port: nconf.get('logging:udpPort') || 24224,
timestamp: function() {
return Date.now();
},
formatter: function(options) {
return JSON.stringify({
"app": appName,
"env": process.env.NODE_ENV,
"level": options.level,
"message": options.message,
"host": os.hostname(),
"meta": options.meta
});
}
});
}
}
if (nconf.get('logging:logToFile') && nconf.get('LOG_FILE')) {
defaultLogger.add(winston.transports.File, {
filename: nconf.get('LOG_FILE'),
level: nconf.get("logging:level"),
Loading
Loading
'use strict';
var path = require('path');
/**
* These functions are used to determine the current app name.
* Before each function there is an example of the returned
* value when the input is "gitter-webapp-1".
*
* Returns "gitter-webapp-1"
*/
function getFullProcessName() {
var upstartJob = process.env.UPSTART_JOB || process.env.JOB;
if (upstartJob) return upstartJob;
var main = require.main;
if (!main || !main.filename) return 'unknown';
return path.basename(main.filename, '.js');
}
/* Returns "gitter-webapp" */
function getGenericProcessName(){
return getFullProcessName().replace(/\-\d*$/,'');
}
/* Returns "webapp" */
function getShortProcessName(){
return getGenericProcessName().replace(/^gitter-/, '');
}
module.exports = {
getFullProcessName: getFullProcessName,
getGenericProcessName: getGenericProcessName,
getShortProcessName: getShortProcessName
};
/*jshint globalstrict:true, trailing:false, unused:true, node:true */
"use strict";
 
var processName = require('./process-name')
 
function emergencyLog() {
console.error.apply(console, arguments);
Loading
Loading
@@ -39,10 +40,9 @@ exports.create = function(options) {
globalTags = globalTags.concat(statsdNodeJsVersionTags());
}
 
var upstartJob = process.env.UPSTART_JOB || process.env.JOB;
if (upstartJob) {
upstartJob = upstartJob.replace(/\-\d*$/,''); // gitter-webapp-1 becomes gitter-webapp
globalTags.push('job:' + upstartJob);
var appName = processName.getShortProcessName();
if (appName) {
globalTags.push('job:' + appName);
}
 
// Add the main entry point into the app as a tag
Loading
Loading
Loading
Loading
@@ -44,7 +44,8 @@
"response-time": "^2.3.1",
"shutdown": "^0.2.3",
"universal-analytics": "^0.3.4",
"winston": "^0.7.3"
"winston": "^2.2.0",
"winston-udp": "^0.0.6"
},
"devDependencies": {
"mocha": "^1.18.2",
Loading
Loading
Loading
Loading
@@ -20,7 +20,6 @@ describe('gitter-stats-client', function() {
});
 
var client = statsClient.create({ config: config, tags: ['test:1'] });
console.log(client);
assert(client);
assert(client.global_tags.indexOf('test:1') >= 0);
});
Loading
Loading
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