Commit Graph

33 Commits

Author SHA1 Message Date
Gareth Jones
c624aef282 Merge pull request #261 from boljen/clusterpid
added cluster identifier support
2015-01-10 15:29:01 +11:00
Patrick Hogan
6b029e98fc Allow for blank tokens due to dynamic data
Metadata for users such as name, email, etc are not always present for users.  For example, I am running express and I want to log the %x{company}%x{username} so that when I look at my logs I can immediately understand which user this affects.  Or for example, I could log %x{payingOrTial} the type of user.  

This works well when the user is logged in.  However, my logger encompasses everything.  I log when the server boots up.  I log during the login screen where a user is not yet logged in.  In these circumstances there is no way to retrieve this metadata.

So for example

```
"username": function () {
            var session = require('continuation-local-storage').getNamespace('api.callinize');
            if(!session) session = require('continuation-local-storage').getNamespace('dashboard.callinize');
            var username = session && session.get('user') && session.get('user').username;
            if(!username) return "";
            return " " + username + " ";
        }
```

I try to get the metadata.  If I get no metdata I return a blank string.  Unfortunately, in the current implementation, due to the OR operator, even if I have a replacement of "" || matchedString, 

```
  replaceToken(conversionCharacter, loggingEvent, specifier) || 
          matchedString;
```

the blank string equals false and puts the token in the log instead of the blank string.  This makes the log lines get long with information that is not relevant.  The better thing to do is simply allow for blank strings.  This lets the user have control over their logs and also allows for more metadata to go in the logs, without having to pick only metadata that is always present.
2014-12-21 14:49:25 -08:00
Christophe Bol
3300dfae60 fixed error when logging from the clustered master 2014-12-01 15:34:09 +01:00
Christophe Bol
b694fd1d8d added cluster identifier support 2014-12-01 12:29:45 +01:00
j2ro
3e78fcb630 #233: Adding ability to put pid in log layout pattern 2014-08-20 10:43:48 +01:00
j2ro
44687e1bd1 #233: Adding ability to put pid in log layout pattern 2014-08-20 10:23:31 +01:00
wood1986
7888381991 Update layouts.js 2013-08-18 01:43:48 +08:00
wood1986
6df4753822 Update layouts.js 2013-08-18 01:36:07 +08:00
wood1986
21aebbde33 Update layouts.js 2013-08-13 23:04:11 +08:00
Gareth Jones
efc4e36317 improved coverage for layouts 2013-06-14 08:13:16 +10:00
Gareth Jones
41ddf5eea7 merged util.format branch (fixes a lint error and simplifies the code) 2013-06-05 08:52:07 +10:00
Gareth Jones
6368de1094 refactored pattern layout 2013-06-05 08:02:10 +10:00
Gareth Jones
5d6f00eda4 fixed all lint errors except ones which require refactoring of code 2013-06-04 08:17:36 +10:00
Gareth Jones
f272e3fd0a Merge branch 'master' into util.format 2013-02-25 16:43:03 +11:00
Jan Schmidle
5c75ba9468 fixed small issue that could occur with wrong evaluated parameters 2013-02-08 16:17:24 +01:00
Jan Schmidle
bec0d05847 added some documentation to the function header 2013-02-08 16:15:51 +01:00
Jan Schmidle
e4bf405f20 add your own tokens to the patternLayout 2013-02-08 14:54:18 +01:00
Gareth Jones
0dbc4921a3 Changed layouts to use util.format instead of my own implementation 2013-01-11 15:35:00 +11:00
Friedel Ziegelmayer
4a7a90ed53 [feature] Add color option to pattern layout.
Based on #90 this implements the possibillity to add the color codes
according to the log level via %[ and %].
2012-12-02 23:41:59 +01:00
osher
54e420eb58 Update lib/layouts.js
Errors sometimes carry additional attributes on them as part of the passed error data.
A utility that utilizes it, for example - is called 'errs', which is in use for instance 'nano' - the couch-db driver.

when only the stack is printed - all the additional information that is augmented on the error object does not sink to the log and is lost.

consider the following code:

```
//the oups throwing utility
function oups(){
  e = new Error();
  extend(
    { message    : "Oups error"
    , description: "huston, we got a problem"
    , status     : "MESS"
    , errorCode  : 991
    , arr :[1,2,3,4,{}]
    , data: 
      { c:{}
      , d:{e:{}}
      }
    }
  throw e;
}

var log = require('log4js')

try{
  oups()
} catch( e ) {
   log.error("error on oups", e );
}

```


output before the fix

```
error on oups Error: Oups error
    at repl:1:11
    at REPLServer.eval (repl.js:80:21)
    at Interface.<anonymous> (repl.js:182:12)
    at Interface.emit (events.js:67:17)
    at Interface._onLine (readline.js:162:10)
    at Interface._line (readline.js:426:8)
    at Interface._ttyWrite (readline.js:603:14)
    at ReadStream.<anonymous> (readline.js:82:12)
    at ReadStream.emit (events.js:88:20)
```


output after the fix would be

```
error on oups { [Error: My error message]
  name: 'Error',
  description: 'huston, we got a problem',
  status: 'MESS',
  errorCode: 991,
  arr: [ 1, 2, 3, 4, {} ],
  data: { c: {}, d: { e: {} } } }
Error: Oups error
    at repl:1:11
    at REPLServer.eval (repl.js:80:21)
    at Interface.<anonymous> (repl.js:182:12)
    at Interface.emit (events.js:67:17)
    at Interface._onLine (readline.js:162:10)
    at Interface._line (readline.js:426:8)
    at Interface._ttyWrite (readline.js:603:14)
    at ReadStream.<anonymous> (readline.js:82:12)
    at ReadStream.emit (events.js:88:20)
```
2012-07-31 14:32:03 +03:00
Gareth Jones
7a02f39921 Fallback to \n if os.EOL is not defined 2012-07-04 09:25:08 +10:00
Gareth Jones
638ce187bb use os.EOL instead of \n 2012-07-04 08:53:09 +10:00
Gareth Jones
a33e48cb07 Changed multiprocess appender to use a single socket per client 2012-07-04 08:44:50 +10:00
Gareth Jones
9a34d9edfd fixed missing space between log data elements 2011-09-15 08:18:24 +10:00
Gareth Jones
7aa076c278 removed the annoying extra new line 2011-07-22 18:25:26 +10:00
Gareth Jones
4b32456db7 fixed a bug where if the first log arg was not a string it wouldn't get logged 2011-07-22 12:28:02 +10:00
Gareth Jones
d0b4563ba0 fixed small bug checking for stack on undefined object 2011-07-20 19:39:54 +10:00
Gareth Jones
d64d4ca0ca updated to remove TODO and credit danbell 2011-07-15 09:13:09 +10:00
Gareth Jones
b338b34fd6 added tests for pattern layout 2011-07-15 08:22:44 +10:00
Gareth Jones
3691648cd0 fixed patternlayout, needs tests though 2011-07-13 18:42:56 +10:00
Gareth Jones
d7ffa59434 moved level colours into layouts where they belong, updated README 2011-07-13 18:29:53 +10:00
Gareth Jones
5868856a7d all tests pass, now with proper console.log formatting 2011-07-13 18:12:29 +10:00
Gareth Jones
f89d54b66e removed main function, now using felixge's sandboxed-module, split code into multiple files 2011-07-12 13:03:17 +10:00