UNPKG

5.79 kBMarkdownView Raw
1![Build Status](https://travis-ci.org/logzio/logzio-nodejs.svg?branch=master)
2
3# logzio-nodejs
4NodeJS logger for Logz.io.
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 it reaches 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_ACCOUNT_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 account 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* **compress** - If true the the logs are compressed in gzip format. Default: `false`
49* **internalLogger** - set internal logger that supports the function log. Default: console.
50* **extraFields** - Adds your own custom fields to each log. Add in JSON Format, for example: `extraFields : { field_1: "val_1", field_2: "val_2" , ... }`.
51
52
53## Using UDP
54A few notes are worth mentioning regarding the use of the UDP protocol:
55* UDP has some limitations, and therefore it is not the recommended protocol:
56 * There is no guarantee that the logs have been received.
57 * UDP can't take advantage of the bulk API, so performance is sub-optimal.
58* When using UDP, each message is sent separately, and not using the bulk API. This means that the meaning of `bufferSize` is slightly different in this case. The messages will still be sent separately, but the logger will wait for the buffer to reach the size specified before sending out all the messages. If you want each message to be sent out immediately, then set `bufferSize = 1`.
59
60
61## Update log
62**2.0.2**
63- Updated required fields for typescript
64
65**2.0.1**
66- Fixed sorting by nanosec-timestamp
67- Added option to log string with an object
68- Updated Typescript declaration for optional dependencies
69
70**2.0.0**
71- Added support for TypeScript
72- End of support for node 6
73- Upgrade dependencies due to security vulnerabilities
74
75**1.0.4 - 1.0.6**
76- Upgrade dependencies due to security vulnerabilities
77
78**1.0.3**
79- Added the bulk to the callback in case the send failed
80
81**1.0.2**
82- Handle no Error code on bad requests
83
84**1.0.1**
85- ES6
86- Support node greater than node 6
87- Added gzip compress option
88- Added internal logger option
89
90**0.4.14**
91- UDP callback bug fix + tests
92- UDP close connection bug fix + tests
93- ESLint
94
95**0.4.12**
96- Updated ability to add custom port
97
98**0.4.6**
99- Updated moment (v2.19.3) and request (v2.81.0) packages
100
101**0.4.4**
102- `@timestamp` and `@timestamp_nano` will no longer be overriden given a custom value by the user.
103
104**0.4.3**
105- Add the `@timestamp` field to the logs on the client's machine (and not when it reaches the server)
106
107**0.4.1**
108- Updated `request` dependency to 2.75.0
109
110**0.4.0**
111- Fixed issue #12 - added support for UDP
112- Minor refactorings
113
114**0.3.10**
115- Fixed issue #17 - sendAndClose() wasn't actually closing the timer
116
117**0.3.9**
118- Added option to add a timestamp with nano second granularity
119
120**0.3.8**
121- Updated listener url
122- Added `sendAndClose()` method which immediately sends the queued messages and clears the global timer
123- Added option to supress error messages
124
125**0.3.6**
126- Fixed URL for github repository in package.json
127
128**0.3.5**
129- Bug fix : upon retry (in case of network error), the message gets sent forever
130
131**0.3.4**
132- Bug fix : `jsonToString()` was throwing an error in the catch()block
133
134**0.3.2**
135- Enhancement : Added option to attach extra fields to each log in a specific instance of the logger.
136
137**0.3.1**
138- Bug fix : When calling `log` with a string parameter, the object isn't constructed properly.
139
140
141
142# Scripts
143
144- run `npm install` to install required dependencies
145- run `npm test` to run unit tests