Last active
December 16, 2015 22:39
-
-
Save mainiak/5508377 to your computer and use it in GitHub Desktop.
node v0.10.5, winston v0.7.1
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
node_modules |
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
{ | |
"name": "winston-meta", | |
"version": "0.0.0", | |
"description": "ERROR: No README.md file found!", | |
"main": "winston-meta.js", | |
"dependencies": { | |
"winston": "git://github.com/apodzolko/winston.git#1541dfc7b50f98acd4054c44251f35241f0facdf" | |
}, | |
"devDependencies": {}, | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"repository": { | |
"type": "git", | |
"url": "https://gist.github.com/5508377.git" | |
}, | |
"author": "", | |
"license": "BSD", | |
"gitHead": "ac72a750c1f8805cb89ca8e7f57dafa5f73fbf0f" | |
} |
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
#!/bin/sh | |
rm -f somefile.log | |
node winston-meta.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
{"level":"info","message":"test message my string","timestamp":"2013-05-03T11:45:29.257Z"} | |
{"level":"info","message":"test message 123","timestamp":"2013-05-03T11:45:29.260Z"} | |
{"level":"info","message":"test message {\"number\":123}","timestamp":"2013-05-03T11:45:29.260Z"} | |
{"number":123,"level":"info","message":"test message first, second","timestamp":"2013-05-03T11:45:29.261Z"} | |
{"number":123,"level":"info","message":"test message first second","timestamp":"2013-05-03T11:45:29.262Z"} | |
{"number":123,"level":"info","message":"test message first, second","timestamp":"2013-05-03T11:45:29.262Z"} | |
{"number":123,"level":"info","message":"test message first second","timestamp":"2013-05-03T11:45:29.263Z"} |
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
/* | |
// source is https://github.com/flatiron/winston#logging-with-metadata | |
npm install winston | |
node winston-meta.js | |
*/ | |
var winston = require('winston'); | |
var logger = new (winston.Logger)({ | |
transports: [ | |
new (winston.transports.Console)(), | |
new (winston.transports.File)({ filename: 'somefile.log' }) | |
] | |
}); | |
logger.info('test message %s', 'my string'); | |
// info: test message my string | |
logger.info('test message %d', 123); | |
// info: test message 123 | |
logger.info('test message %j', {number: 123}, {}); | |
// info: test message {"number":123} | |
// meta = {} | |
logger.info('test message %s, %s', 'first', 'second', {number: 123}); | |
// info: test message first, second | |
// meta = {number: 123} | |
logger.info('test message', 'first', 'second', {number: 123}); | |
// info: test message first second | |
// meta = {number: 123} | |
logger.info('test message %s, %s', 'first', 'second', {number: 123}, function(){}); | |
// info: test message first, second | |
// meta = {numer: 123} | |
// callback = function(){} | |
logger.info('test message', 'first', 'second', {number: 123}, function(){}); | |
// info: test message first second | |
// meta = {numer: 123} | |
// callback = function(){} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment