UNPKG

4.83 kBMarkdownView Raw
1![Build Status](https://travis-ci.org/logzio/logzio-nodejs.svg?branch=master)
2
3# logzio-nodejs
4NodeJS logger for LogzIO.
5The logger stashes the log messages you send into an array which is sent as a bulk once it reaches its size limit (100 messages) or time limit (10 sec) in an async fashion.
6It contains a simple retry mechanism which upon connection reset (server side) or client timeout, wait a bit (default interval of 2 seconds), and try this bulk again (it does not block other messages from being accumulated and sent (async). The interval increases by a factor of 2 between each retry, until we reached the maximum allowed attempts (3).
7
8 By default any error is logged to the console. This can be changed by supplying a callback function.
9
10
11## Sample usage
12```javascript
13var logger = require('logzio-nodejs').createLogger({
14 token: '__YOUR_API_TOKEN__',
15 type: 'YourLogType' // OPTIONAL (If none is set, it will be 'nodejs')
16});
17
18
19// sending text
20logger.log('This is a log message');
21
22// sending an object
23var obj = {
24 message: 'Some log message',
25 param1: 'val1',
26 param2: 'val2'
27};
28logger.log(obj);
29```
30
31**Note:** If logzio-js is used as part of a serverless service (AWS Lambda, Azure Functions, Google Cloud Functions, etc.), add `logger.sendAndClose()` at the end of the run.
32
33## Options
34
35* **token**
36 Mandatory. Your API logging token. Look it up in the Device Config tab in Logz.io
37* **type** - Log type. Help classify logs into different classifications
38* **protocol** - `http`, `https` or `udp`. Default: `http`
39* **host** - Destination host name. Default: `listener.logz.io`
40* **port** - Destination port. Default port depends on protocol. For `udp` default port is `5050`, for `http` is `8070` and `8071` is for `https`
41* **sendIntervalMs** - Time in milliseconds to wait between retry attempts. Default: `2000` (2 sec)
42* **bufferSize** - The maximum number of messages the logger will accumulate before sending them all as a bulk. Default: `100`.
43* **numberOfRetries** - The maximum number of retry attempts. Default: `3`
44* **debug** - Should the logger print debug messages to the console? Default: `false`
45* **callback** - A callback function called when an unrecoverable error has occured in the logger. The function API is: function(err) - err being the Error object.
46* **timeout** - The read/write/connection timeout in milliseconds.
47* **addTimestampWithNanoSecs** - Add a timestamp with nano seconds granularity. This is needed when many logs are sent in the same millisecond, so you can properly order the logs in kibana. The added timestamp field will be `@timestamp_nano` Default: `false`
48
49## Using UDP
50A few notes are worth mentioning regarding the use of the UDP protocol :
51* UDP has some limitations, and therefore it is not the recommended protocol :
52 * There is no guarantee that the logs have been received.
53 * UDP can't take advantage of the bulk api and therefore performance is sub-optimal.
54* When using UDP, each message is being sent separately, and not using the bulk api. This means that the meaning of `bufferSize` is slightly
55different in this case. The messages will still be sent separately, but the logger will wait for the buffer to reach the size specified before
56sending out all the messages. If you want each message to be sent out immediately, then set `bufferSize = 1`.
57
58
59## Update log
60**0.4.14**
61- UDP callback bug fix + tests
62- UDP close connection bug fix + tests
63- ESLint
64
65**0.4.12**
66- Updated ability to add custom port
67
68**0.4.6**
69- Updated moment (v2.19.3) and request (v2.81.0) packages
70
71**0.4.4**
72- `@timestamp` and `@timestamp_nano` will no longer be overriden given a custom value by the user.
73
74**0.4.3**
75- Add the `@timestamp` field to the logs on the client's machine (and not when it reaches the server)
76
77**0.4.1**
78- Updated `request` dependency to 2.75.0
79
80**0.4.0**
81- Fixed issue #12 - added support for UDP
82- Minor refactorings
83
84**0.3.10**
85- Fixed issue #17 - sendAndClose() wasn't actually closing the timer
86
87**0.3.9**
88- Added option to add a timestamp with nano second granularity
89
90**0.3.8**
91- Updated listener url
92- Added `sendAndClose()` method which immediately sends the queued messages and clears the global timer
93- Added option to supress error messages
94
95**0.3.6**
96- Fixed URL for github repository in package.json
97
98**0.3.5**
99- Bug fix : upon retry (in case of network error), the message gets sent forever
100
101**0.3.4**
102- Bug fix : `jsonToString()` was throwing an error in the catch()block
103
104**0.3.2**
105- Enhancement : Added option to attach extra fields to each log in a specific instance of the logger.
106
107**0.3.1**
108- Bug fix : When calling `log` with a string parameter, the object isn't constructed properly.
109
110
111
112# Scripts
113
114- run `npm install` to install required dependencies
115- run `npm test` to run unit tests