2.5.0 • Published 3 years ago

@jrh/log v2.5.0

Weekly downloads
-
License
-
Repository
github
Last release
3 years ago

@jrh/log

Combined local and remote logging (via LogDNA) for Node.js applications.

Installation

npm install @jrh/log

Logging

const log = require('@jrh/log')(options)

async function initialize() {
  try {
    log(message, [metadata])
    log(message, [metadata])
  }

  catch (error) {
    log.error(error.stack)
  }

  await log.complete()
}

Syntax: createLogger()

NameTypeDescription
optionsObject: OptionsConfiguration for the logging function.

Returns

TypeDescription
FunctionA logging function.

The Options Object

PropertyTypeDescription
applicationStringThe name of the application.
includeUniqueIdBooleanBy default, a unique ID specific to this logging function will be included with each message. Pass false to disable.
keyStringThe LogDNA API key.
modeStringThe mode of the running application (i.e. production). When the mode is set to testing, remote logs are disabled.
sourceStringThe source of the log message.

Syntax: Logging Function

Log general information.

NameTypeDescription
messageStringA message to log.
metadataObject (optional)Metadata to be included with the log message.

Effects

  • Logs will appear locally via console.log.
  • The LogDNA log level will be info.

Methods

.error()

Log errors.

NameTypeDescription
messageStringAn error message to log.
  • Logs will appear locally via console.error.
  • The LogDNA log level will be error.

.complete()

To reduce HTTP traffic, LogDNA sends logs in batches. Calling this method will send the current batch and resolve when it is finished.

When mode in the options object is set to testing, no remote logs will be sent.

Returns

TypeDescription
PromiseA promise to send all logs.

Testing

To run the integration tests, create tests/support/tests.environment.js in the following format:

module.exports = {
  logdna_key: 'your_logdna_key'
}

Test logs will appear in your LogDNA account.

2.3.0

3 years ago

2.2.0

3 years ago

2.5.0

3 years ago

2.4.0

3 years ago

2.1.0

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.0

3 years ago