Installations
npm install logentries-client
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>=0.8.0
Node Version
0.12.3
NPM Version
2.9.1
Score
64.5
Supply Chain
96.2
Quality
74.6
Maintenance
25
Vulnerability
99
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
bathos
Download Statistics
Total Downloads
10,444
Last Day
1
Last Week
15
Last Month
57
Last Year
387
GitHub Statistics
3 Stars
41 Commits
2 Forks
1 Watching
2 Branches
3 Contributors
Bundle Size
95.38 kB
Minified
31.64 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.0.1
Package Id
logentries-client@1.0.1
Size
25.91 kB
NPM Version
2.9.1
Node Version
0.12.3
Total Downloads
Cumulative downloads
Total Downloads
10,444
Last day
0%
1
Compared to previous day
Last week
7.1%
15
Compared to previous week
Last month
62.9%
57
Compared to previous month
Last year
-1.3%
387
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
8
Logentries Client (JS)
Allows you to send logs to your logentries account from Node or io.js.
It might work with Browserify, too, but you would need to use shims for net or tls (depending on whether you set
secure
totrue
). Such shims do exist, but I haven’t tested it.
Tested in Node v0.10 + and io.js. It probably works in Node 0.8 too, but one of the test libraries (mitm) doesn’t, so it remains unconfirmed.
- Start
- Options
- Log Levels
- Events
- Log Entries
- Methods
- Buffer & Connection Issues
- Using as a Winston ‘Transport’
- Using with Bunyan
- Setting Up With Logentries Itself
- Changelog
Start
1var LogentriesClient = require('logentries-client'); 2 3var logger = new LogentriesClient({ 4 token: 'myAccessToken' 5}); 6 7logger.warning('The kittens have become alarmingly adorable.')
Options
The options object you provide to the constructor only requires your access token, but you can configure its behavior further.
All of the following except token
, levels
and secure
can also be
configured after instantiation as settable properties on the client. They are
accessors, though, and invalid values will be ignored.
Required
- token: String. Authorization token for the Logentries service.
Behavior
- console: If truthy, log events also get sent to
console.log
,console.warn
andconsole.error
as appropriate. Default:false
. - levels: Custom names for the 8 log levels and their corresponding methods. More details on this below.
- minLevel: The minimum level to actually record logs at. String or Number. Defaults to 0.
- secure: If truthy, uses a tls connection. Default:
false
. - timeout: The time, in milliseconds, that inactivity should warrant closing the connection to the host until needed again. Defaults to three minutes.
Log Processing Options
- flatten: Convert objects into a single-level object where the values of
interior objects become dot-notation properties of the root object. Defaults
to
false
. More details on this below. - flattenArrays: If
flatten
is true, you can also indicate whether arrays should be subject to the same process. Defaults totrue
ifflatten
istrue
; otherwise meaningless. - replacer: A custom value-transform function to be used during JSON serialization. Applied before error transformation.
- timestamp: If truthy, prefix entries with an ISO timestamp (if strings)
or add the same as a property (if objects). Default:
false
. - withLevel: Will prepend (string) or add property (object) indicating the log level.
- withStack: If an object is or contains an
Error
object, setting this totrue
will cause the stack trace to be included. Default:false.
Other
- host: The host to send logs to. Normally you would not want to set this, but it may be useful for mocking during tests. The value may be just the host or the host with the port specified.
- port: As above. This will default to 80 if
secure
is false, or 443 if it’s true.
Log Levels
The default log levels are:
- debug
- info
- notice
- warning
- err
- crit
- alert
- emerg
You can provision the constructor with custom names for these levels with either an array or an object hash:
1[ 'boring', 'yawn', 'eh', 'hey' ] 2 3{ boring: 0, yawn: 1, eh: 2, hey: 3 }
In the former case, the index corresponds to the numeric level, so sparse arrays are valid. In either case, missing levels will be filled in with the defaults.
The minLevel
option respects either level number (e.g. 2
) or the name (e.g.
'eh'
).
The level names each become methods on the client, which are just sugar for
calling client.log(lvl, logentry)
with the first argument curried.
Since these names will appear on the client, they can’t collide with existing properties. Not that you’re particularly likely to try naming a log level ‘hasOwnProperty’ or ‘_write’ but I figured I should mention it.
So the following three are equivalent:
1logger.notice('my msg'); 2logger.log('notice', 'my msg'); 3logger.log(2, 'my msg');
It’s also possible to forgo log levels altogether. Just call log
with a single
argument and it will be interpretted as the log entry. When used this way, the
minLevel
setting is ignored.
Events
The client is an EventEmitter, so you should (as always) make sure you have a
listener on 'error'
. The only other event is 'log'
which fires when you’d
expect. Error events can occur when there’s been a problem with the connection
or if a method was called with invalid parameters.
Log Entries
Log entries can be strings or objects. If the log argument is an array, it will be interpretted as multiple log events.
Object Serialization
In the case of objects, the native JSON.stringify serialization is augmented in several ways. In addition to handling circular references, it will automatically take care of a variety of objects and primitives which otherwise wouldn’t serialize correctly, like Error, RegExp, Set, Map, Infinity, NaN, etc.
If you choose to set withStack
to true, errors will include their stacktraces
as an array (so that they are not painful to look at). Be sure to turn on
"expand JSON" (meaning pretty print) in the options on logentries:
You can adjust this further by supplying your own custom replacer
. This is a
standard argument to JSON.stringify -- See MDN: JSON > Stringify > The Replacer Parameter
for details. In the event that you supply a custom replacer, it is applied
prior to the built-in replacer described above so you can override its behavior.
Optional Augmentation
Two options are available, timestamp
and withLevel
, which will add data to
your log events. For objects, these are added as properties (non-mutatively).
For strings, these values are prepended. If the name of a property would cause
a collision with an existing property, it will be prepended with an underscore.
Flattening Log Objects
In some cases it will end up being easier to query your data if objects aren’t
deeply nested. With the flatten
and flattenArrays
options, you can tell the
client to transform an object like this:
{ "a": 1, "b": { "c": 2 } }
=>{ "a": 1, "b.c": 2 }
If flattenArrays
has not been set to false, this transformation will apply to
arrays as well:
{ "a": [ "b", { "c": 3 } ] }
=>{ "a.0": "b", "a.1.c": 3 }
Methods
In addition to log
and its arbitrary sugary cousins, you can call
closeConnection
to explicitly close an open connection if one exists; you
might wish to do this as part of a graceful exit. The connection will reopen if
you log further.
Also, because the client is actually a writable stream, you can call write
directly. This gives you lower-level access to writing entries. It is in object
mode, but this means it expects discreet units (one call = one entry), not
actual objects; you should pass in strings. This is useful if you want to pipe
stdout, for example.
Buffer & Connection Issues
If there’s a problem with the connection, entries will be buffered to a max of
60 entries. After that, error events will be emitted when trying to log further.
If the buffer drains, normal logging can resume. If console
is true, these log
entries will still pass through there, but they will not make it to LogEntries.
If the connection fails, it will retry with an exponential backoff for several minutes. If it does not succeed in that time, an error is emitted. A ‘ban’ will be placed on further attempts but it will lift after some more time has passed, at which point the process can repeat (and hopefully work).
A connection to the host does not guarantee that your logs are transmitting successfully. If you have a bad token, there is no feedback from the server to indicate this. The only way to confirm that your token is working is to check the live tail on Logentries. I will investigate this further to see if there’s some other means with which a token can be tested for validity.
Using as a Winston ‘Transport’
If Winston is included in your package.json dependencies, simply requiring the
Logentries client will place the transport constructor at winston.transports
,
even if Winston itself hasn’t yet been required.
1var winston = require('winston'); 2var LogentriesClient = require('logentries-client'); 3 4winston.add(winston.transports.Logentries, opts);
The usual options are supported. If custom levels are not provided, Winston’s defaults will be used.
In the hard-to-imagine case where you’re using Winston without including it in
package.json, you can explicitly provision the transport by first requiring
Winston and then calling LogentriesClient.provisionWinston()
.
Using with Bunyan
For Bunyan it’s like so:
1var bunyan = require('bunyan'); 2 3var LogentriesClient = require('logentries-client'); 4 5var leBunyan = LogentriesClient.bunyanStream(opts); 6 7// One stream 8var logger = bunyan.createLogger(leBunyan); 9 10// Multiple streams 11var logger = bunyan.createLogger({ 12 name: 'whatevs', 13 streams: [ leBunyan, otherStream ] 14});
Note that with Bunyan, only the first six log levels will be used, and
timestamps are provided by Bunyan already. Other options are the same. If after
creation you wish to change the minimum log level, use Bunyan’s methods. The
stream will be named ‘logentries,’ though you can change it on the object
returned by bunyanStream()
.
Setting Up With Logentries Itself
When you create an account at Logentries (just a standard signup form; there’s a free tier), you can find the token you need. It’s shown during the initial walk- through but you can find it later under Logs/Hosts/{ the name of your host } -- on the far right, a gray TOKEN button that you can click to reveal the string.
That’s it -- once you have the token you’re set.
Changelog
1.0.0
- Major overhaul -- rewrote in ES6
- Client is now a writable stream, compatible with stdout
- Added
withLevel
andtimeout
options - Exposed
host
andport
options for testing - Expanded default serialization to handle more JSON-choking cases, including Map, Set and Symbol
- Added more sanity checks on instantiation
- Made 'level' argument optional when calling
client.log
- BREAKING CHANGE:
client.log
method no longer accepts an arbitrary number of log entry arguments (to support above case, which seems much likely to be useful) - Added custom, informative error objects
- Changed default
minLevel
value to zero (1 was an accident) - The most significant changes concern handling the connection to the host:
- An exponential backoff is used when connecting fails
- After repeated failures, a cooldown period is enforced before further tries
- The buffer of pending entries has a maximum now (60)
- Errors get emitted when these conditions occur
0.5.0
- Added
flatten
andflattenArray
options - Added more special cases for the default serializer
- Added new tests
0.4.0
- Prevented mutation of incoming log objects when adding timestamp or level
- Turned thrown strings into proper errors (oops!)
- Updated dependencies
0.3.3
- Switched to the new API endpoint
0.3.1 & 0.3.2
- Readme updated
0.3.0
- Improved stack trace handling when
withStack
set to true
0.2.1
- Path for problems with new 0.2.0 options
- Added new tests
0.2.0
- Added proper handling for objects with circular references
- Added custom serialization for Error objects &
withStack
option - Changed lodash to
runInContext()
to prevent template string problems
0.1.0
- Initial release
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE.txt:0
- Warn: project license file does not contain an FSF or OSI license.
Reason
project is archived
Details
- Warn: Repository is archived.
Reason
Found 2/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 2 are checked with a SAST tool
Score
3
/10
Last Scanned on 2025-02-03
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to logentries-client
r7insight_node
Rapid7 Insight Platform client for node; use with or without Winston or Bunyan.
logs-to-logentries
A simple logentries log client tool
@healthadvisor/r7insight_node
Rapid7 Insight Platform client for node; use with or without Winston or Bunyan.
pa-logging-client_hosting
Logging client for Pacifica system, uses logentries logging client to beam logs to the cloud.