add your own tokens to the patternLayout #113

merged 5 commits into from Feb 11, 2013


None yet

2 participants


Added the ability to add your own dynamic tokens to the patternLayout so you can easily extend your log with any additional information.

I currently use it to add the process pid to distinguish parallel running node instances logging to the same ressource.

I introduced a new %x field and used its specifier to address the token to use.

With this you should be able to add interesting status values like memory usage or any other status to your log messages to add some more context to them.

var log4js = require("log4js");

var config = {
    "appenders": [
        "type": "console",
        "layout": {
          "type": "pattern",
          "pattern": "%[%r (%x{pid}) %p %c -%] %m%n",
          "tokens": {
            "pid" : function() { return; }

log4js.configure(config, {});

var logger = log4js.getLogger("app");"Test log message");

you are right, completely forgot about the documentation. Will work on that and submit another push.


Don't know why af428c5 didn't go thru the test. There seems to be an error related to another part.

@nomiddlename nomiddlename merged commit 22da622 into nomiddlename:master Feb 11, 2013

1 check passed

Details default The Travis build passed

Awesome - thanks a lot for this work, especially the attention to tests and documentation. Much appreciated.

@bitcloud bitcloud deleted the unknown repository branch Feb 11, 2013

Released in 0.5.7 in npm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment