Commit Graph

235 Commits

Author SHA1 Message Date
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
osher
cd3971cc03 fix bug: headers are changed after log entry emits
In the original version, the following operation looks synchronic, however it is not:

```
res.end = end;
res.end(data,enc);

//emit the log entry 
```

In fact, it starts a series of async operations, in which the request may yet be changed after the request log has already been emitted
(in our case - a change on request headers was observed, probably by some low level hook or hacky wrap of some http.ServerResponse method that's involved on the process - but called asynchronously)
what leads to situation that the request log does not capture valid data.
(observed by us:
 - request headers
 - calculated end time, when concerning big content
)

The fix just used `setTimeout(function() { /*emit the log entry*/ }, 1)`, but I'm afraid it may not hold true for big contents.
Well. maybe the headers part will, but the response time calculation will lie.

The fix relays on: http://nodejs.org/api/http.html#http_event_finish
2014-11-04 17:28:52 +02:00
Gareth Jones
39ce97d140 Merge pull request #242 from marcelog/marcelog_logstash_udp_appender
adding logstash UDP appender
2014-09-11 09:20:42 +10:00
Marcelo Gornstein
a7a0964803 adding logstash UDP appender 2014-09-10 13:03:21 -03:00
Christian Langer
82950eb965 pass options to wrapped appender in logLevelFilter 2014-09-09 03:28:02 +02:00
Dmitry M. Lazutkin
7558a3c367 Closes #238 Updated async library in order to use lib in —use-strict mode 2014-08-28 12:04:02 +04:00
Jakub Chmura
00c62c7fa6 Adding maxLevel to levelFilter.
This optional parameter specifies what maximum level of event is accepted by the filter.
2014-08-25 19:48:15 +02: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
Grégoire Charvet 黑瓜
feef9975c7 Remove test logging 2014-08-20 10:20:57 +01:00
Grégoire Charvet 黑瓜
93695fbfc4 Change spaces by tabs
Keeping constitency with the rest of the code.
2014-08-20 10:20:57 +01:00
Grégoire Charvet 黑瓜
0571089a8b Correctly send message, level and hostname
Fix issue #230 where the level would hold the message and the log level
information would be lost.
2014-08-20 10:20:57 +01:00
Gareth Jones
c03185b563 Merge pull request #231 from eurekaa/buffered-logger
added getBufferedLogger function.
2014-08-17 11:00:10 +10:00
Stefano Graziato
59a6703549 getBufferedLogger tested. 2014-08-16 14:22:58 +02:00
Gareth Jones
ceffdf92e4 Removed hook.io appender, because hook.io does not build on systems without python 2014-08-16 12:23:50 +10:00
Stefano Graziato
c9e72d0f00 added getBufferedLogger function.
This function should be useful when you need to log during async
parallel operations, without having a mess in logs.
For example when you walk asynchronously a directory and you want logs
to be grouped by file.

It returns the same getLogger() object but messages are stored
internally and sent to appenders only when you call the flush() method
on it.
2014-08-15 13:42:08 +02:00
Gareth Jones
0242bae78f Merge pull request #214 from GregoireDigbil/master
Format message before adding loggly metadata
2014-08-15 18:29:19 +10:00
mishless
66872d136d Update connect-logger.js to work correctly with express
When used with express levels are wrong since send() does not call writeHead, but sets responseCode on response.
2014-07-30 13:06:51 +03:00
Gareth Jones
4648e7a5e6 Merge branch 'master' of https://github.com/mayconbordin/log4js-node into mayconbordin-master 2014-07-12 17:18:07 +10:00
Gareth Jones
60d2e093ae Merge branch 'set-global-log-level' of https://github.com/RolfKoenders/log4js-node into RolfKoenders-set-global-log-level 2014-07-12 17:08:39 +10:00
Gareth Jones
a4d55b3339 fixed up test after merge 2014-07-12 15:11:21 +10:00
Jens John
52b4aa1874 fix uninitialized field error 2014-07-11 19:19:19 +09:00
Jens John
0f51ab1bb3 GELF appender: set version to 1.1 2014-07-10 14:26:27 +09:00
Jens John
5b2d840472 GELF appender: move facility key into a custom field if present
At the same time, don't assign a default value as the field is optional
according to the GELF spec v1.1.
2014-07-10 14:07:38 +09:00
Jens John
ca635fc4b9 GELF appender: don't send full_message field
According to the GELF spec v1.1 [1], the full_message field in GELF is
optional. The log4js implemention until now has sent identitical
short_message and full_message fields. Since this does not add any new
information to the log message, I suggest that full_message be dropped
from GELF.

--
[1] http://graylog2.org/gelf#specs
2014-07-10 12:17:35 +09:00
Grégoire Charvet 黑瓜
d65d053bc1 Format message before adding loggly metadata
Also removed a throw err inside an asynchronous callback.
2014-07-04 14:03:08 +08:00
Gareth Jones
b2edbb1146 Merge pull request #175 from devotis/master
Loggly appender should not make use of any layout
2014-06-28 08:22:20 +10:00
Gareth Jones
99e7c0981d Merge pull request #189 from jengler/add-support-for-prerequired-appender-styles
Add support for prerequired appender styles
2014-06-28 08:20:12 +10:00
Gareth Jones
06bab894af Merge pull request #203 from idalv/master
Clusterred appender should consider the categories.
2014-06-28 08:17:16 +10:00
Ryan Wilson
f8ffccffd5 epic day with a forgotten console 2014-06-20 13:23:57 -07:00
Ryan Wilson
7d50b4aeff removed check for writeable
caused broken unit tests
2014-06-20 13:23:09 -07:00
Ryan Wilson
b12200fabc Update for "write after end" uncaught error. 2014-06-20 13:16:23 -07:00
Vladimir Mitev
f8b6cc7c39 Revert "Update connect-logger.js to work correctly with express"
This reverts commit d18fb466fb.
2014-05-26 15:56:23 +03:00
mishless
d18fb466fb Update connect-logger.js to work correctly with express
When used with express levels are wrong since send() does not call writeHead, but sets responseCode on response.
2014-05-23 13:58:52 +03:00
Vladimir Mitev
2daf29b400 Clusterred appender should consider the categories.
It turns out that whenever the clusterred appender is used the log event is passed to all actual appenders.
The actual appender's category is ignored.

Signed-off-by: Vladimir Mitev <idalv@users.noreply.github.com>
2014-05-20 13:45:46 +03:00
Gareth Jones
614127bb10 added shutdown to datefile 2014-04-22 10:05:37 +10:00
Gareth Jones
a549df44b4 Merge pull request #199 from lulurun/fix_file_appender
fix shutdown method: make sure to callback when write completed immediat...
2014-04-22 09:58:03 +10:00
Xiaolu Liu
f5a76d9073 file won't get rolled if the process restarted daily 2014-04-24 00:07:11 +09:00
Xiaolu Liu
29d941f0a6 fix shutdown method: make sure to callback when write completed immediately 2014-04-21 16:27:51 +09:00
Gareth Jones
e4d5228f2b Merge branch 'flush-on-exit' 2014-04-09 07:37:17 +10:00
John Engler
633ed3cddb Support for disabling log writes on shutdown.
Updated logger.js to support disabling all log writes.
Updated log4js.js shutdown function to disable log writes.
Added tests.
Update gitignore to ignore rolling date stream's test output.
2014-04-07 19:06:29 -07:00
John Engler
8ca092cdb9 Removed callback to write, as it is not needed. 2014-04-05 16:14:56 -07:00
John Engler
3ec9811b5e Update log4js module to expose a shutdown function.
loadAppender will check for a shutdown function exposed by
a loaded appender. If present, it will be cached so that the
shutdown function can execute it.

The intent here is that a Node application would not invoked
process.exit until after the log4js shutdown callback returns.
2014-04-05 15:12:45 -07:00
John Engler
c569919160 Simplied loadAppender logic. 2014-03-11 02:19:00 -07:00
John Engler
28f7c87a0e Allow adding of appenders as objects
Previously, appenders could only be added by specifying the filepath
to the appender. This required the appender's path to be specified
either relative to the log4js installation, relative to a NODE_PATH
token, or absolute. This creates a coupling between the log4js
configurer and the log4js installation location, or a coupling between
the log4js configurer and the global NODE_PATH. This commit removes
the coupling by allowing the loading of appenders to be done relative
to the log4js configurer.
2014-03-11 02:07:58 -07:00
Gareth Jones
470baa6c09 Merge pull request #187 from jci-fox/addHasLogger
adding ability to check if a logger exists
2014-03-05 13:16:51 +11:00
jci-fox
fd05d90c2f adding ability to check if a logger exists
This allows for not accidentally adding a non-configured logger
2014-03-04 09:45:56 -06:00
jci-fox
22c156582f Adding level checks on dynamic logging
using levels.toLevel and this.isLevelEnabled prior to emiting the event will prevent the appenders from being notified if the log level provided is below the loggers level.
2014-03-04 09:08:27 -06:00
Rolf Koenders
6ae01b2b84 Update log4js.js
Overlooked that there was already a var with '[all]'.
2014-01-23 10:34:56 +01:00
Rolf Koenders
e7c0b0da52 Changed to only the ‚levels’ option as discussed in #87 2014-01-22 20:13:36 +01:00