Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
christiaanwesterbeek committed Jan 9, 2014
1 parent d210278 commit 19c0ee1
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 283 deletions.
228 changes: 14 additions & 214 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,215 +1,15 @@
#################
## Eclipse
#################

*.pydevproject
.project
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# CDT-specific
.cproject

# PDT-specific
.buildpath


#################
## Visual Studio
#################

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.sln.docstates

# Build results

[Dd]ebug/
[Rr]elease/
x64/
build/
[Bb]in/
[Oo]bj/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
lib-cov
*.seed
*.log
*.scc

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile

# Visual Studio profiler
*.psess
*.vsp
*.vspx

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# NCrunch
*.ncrunch*
.*crunch*.local.xml

# Installshield output folder
[Ee]xpress/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.Publish.xml
*.pubxml

# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
#packages/

# Windows Azure Build Output
csx
*.build.csdef

# Windows Store app package directory
AppPackages/

# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.[Pp]ublish.xml
*.pfx
*.publishsettings

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# SQL Server files
App_Data/*.mdf
App_Data/*.ldf

#############
## Windows detritus
#############

# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Mac crap
.DS_Store


#############
## Python
#############

*.py[co]

# Packages
*.egg
*.egg-info
dist/
build/
eggs/
parts/
var/
sdist/
develop-eggs/
.installed.cfg

# Installer logs
pip-log.txt

# Unit test / coverage reports
.coverage
.tox

#Translations
*.mo

#Mr Developer
.mr.developer.cfg
*.csv
*.dat
*.out
*.pid
*.gz

pids
logs
results

npm-debug.log
node_modules
133 changes: 70 additions & 63 deletions lib/express-loggly.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,79 @@
var loggly = require('loggly');
var config = require('../../../config'); // <!---- here now en nu naar Loggly..
module.exports = function(config, tags) {
var _ = require('underscore');
var loggly = require('loggly');

var client = loggly.createClient(config.loggly);
var client = loggly.createClient(config);

//example by http://www.hacksparrow.com/how-to-write-midddleware-for-connect-express-js.html
//info on sequence: http://runnable.com/UTlPPV-f2W1TAAEf/custom-error-pages-in-express-for-node-js
// http://expressjs.com/guide.html#error-handling
//some other middleware for logging:
// http://fabianosoriani.wordpress.com/2013/04/13/loggly-middleware-for-express-js-server-visibility/
//
var tags = ['application', 'node', 'express', 'http'];

var logger = function (err, req, res, next, type) {
if (!err && type === 'error')
return;
//example by http://www.hacksparrow.com/how-to-write-midddleware-for-connect-express-js.html
//info on sequence: http://runnable.com/UTlPPV-f2W1TAAEf/custom-error-pages-in-express-for-node-js
// http://expressjs.com/guide.html#error-handling
//some other middleware for logging:
// http://fabianosoriani.wordpress.com/2013/04/13/loggly-middleware-for-express-js-server-visibility/
if (typeof tags === 'string') {
tags = tags.split(/\s*,\s*/);
} else if (tags instanceof Array) {
tags = _.uniq(['application', 'node', 'express', 'http'].concat(tags));
} else {
tags = ['application', 'node', 'express', 'http'];
}
console.log('tags', tags);

console.log('log in loggly');
var logger = function (err, req, res, next, type) {
if (!err && type === 'error')
return;

var level;
var level;

if (err || res.statusCode >= 500) { // server internal error or error
level = 'error';
} else if (res.statusCode >= 400) { // client error
level = 'warn';
} else { // redirect/success
level = 'info';
}
if (err || res.statusCode >= 500) { // server internal error or error
level = 'ERROR';
} else if (res.statusCode >= 400) { // client error
level = 'WARN';
} else { // redirect/success
level = 'INFO';
}

var fields = { //partly from express-bunyan-logger (middleware)
'level' : level,
'location' : process.argv && process.argv.length && process.argv[1],
'pid' : process.pid,
'host' : req.host,
'port' : req.app.settings.port,
'path' : req.path,
'query' : req.query,
'protocol' : req.protocol,
'method' : req.method,
'status' : res.statusCode,
'remoteAddress': req.headers['x-forwarded-for'] || req.connection.remoteAddress ||
(req.socket && req.socket.remoteAddress) ||
(req.socket.socket && req.socket.socket.remoteAddresss),
'user-agent' : req.header('user-agent'),
'http-version' : req.httpVersionMajor+'.'+req.httpVersionMinor,
'sessionID' : req.sessionID,
'body' : req.body && req.body.toString && req.body.toString().substring(0, Math.max(req.body.toString().length, 20)),
'originalUrl' : req.originalUrl,
'referrer' : req.referrer,
'headers' : req.query/
}

client.log(fields, tags)
next(err);
}
var fields = { //partly from express-bunyan-logger (middleware)
'level' : level,
'location' : process.argv && process.argv.length && process.argv[1],
'pid' : process.pid,
'host' : req.host,
'port' : req.app.settings.port,
'path' : req.path,
'query' : req.query,
'protocol' : req.protocol,
'method' : req.method,
'status' : res.statusCode,
'remoteAddress': req.headers['x-forwarded-for'] || req.connection.remoteAddress ||
(req.socket && req.socket.remoteAddress) ||
(req.socket.socket && req.socket.socket.remoteAddresss),
'user-agent' : req.header('user-agent'),
'http-version' : req.httpVersionMajor+'.'+req.httpVersionMinor,
'sessionID' : req.sessionID,
'body' : req.body && req.body.toString && req.body.toString().substring(0, Math.max(req.body.toString().length, 20)),
'originalUrl' : req.originalUrl,
'referrer' : req.referrer,
'headers' : req.query
};
client.log(fields, tags);
next(err);
};

module.exports.requestLogger = function(opts) {
return function (req, res, next) {
console.log('requestLogger')
logger(null, req, res, next, 'request')
}
};
return {
requestLogger : function() {
return function (req, res, next) {
console.log('requestLogger');
logger(null, req, res, next, 'request');
};
},

module.exports.errorLogger = function(opts) {
return function (err, req, res, next) {
console.log('errorLogger')
logger(err, req, res, next, 'error')
}

};
errorLogger : function() {
return function (err, req, res, next) {
console.log('errorLogger');
logger(err, req, res, next, 'error');
};
}
};

//ook loggen in textbestand met log4js, winston of bunyan
//ook loggen in textbestand met log4js, winston of bunyan
};
21 changes: 15 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
{
"name": "express-loggly",
"version": "0.0.1",
"description": "Loggly middleware for Express",
"dependencies": {
"loggly": "1.x"
}
"name" : "express-loggly",
"version" : "0.0.1",
"author" : "Christiaan Westerbeek <[email protected]>",
"description": "Loggly middleware for Express",
"license" : "MIT",
"main" : "index.js",
"repository" : {
"type": "git",
"url": "https://github.com/devotis/node-express-loggly.git"
},
"dependencies": {
"loggly": "1.x",
"underscore": "1.x"
},
"keywords" : ["node", "express", "middleware", "loggly"]
}

0 comments on commit 19c0ee1

Please sign in to comment.