4.2.3 • Published 6 years ago

nocms-logger v4.2.3

Weekly downloads
5
License
ISC
Repository
github
Last release
6 years ago

Logger package for NoCMS

semantic-release Dependency Status devDependencies

Install

npm install nocms-logger

Usage

const logger = require('nocms-logger');
logger.warn(<message or object goes here>);

Config

Use logger.setConfig(configObj) to override the defaults.

fielddescriptiondefault
logLevelOne of debug, info, warn or error, or numeric, 1-4. Select the minimun log level to to outputdebug
timestampFormatstrftime formatted date string. Example '%d.%m.%Y %H:%M'ISO 8601
logFormatString template for log format. %T for timestamp, %C for message content and %L for numeric log level'%T %L %C'
outputOne of console, none or file. The logger functions return the output string, so that ouput none makes sense if you wish to manually do the logging using the returned value. Output file uses an additional outputConfig object.console
outputConfigOne output config can be assigned for each log level, in addition to all which will cover all of them. Each config is an object with a property file pointing to a file, of which the log entry is appended to. 
serializersAn object containing a set of functions to serialize certain types of log entries. The logger functions takes a second parameter, serializer, which will match a serializer provided in the config.

Output Config Example

This example shows the configuration where all log entries are logged to file (file.log), whereas debug entries are also logged to console, info entries to info.log and errors to error.log. Each log level can also have an array lising multiple log outputs, such as error in the following example.

config.output = {
  all: { file: '/path/to/file.log' },
  debug: 'console',
  info: { file: '/path/to/info.log' },
  error: ['console', { file: '/path/to/error.log' }],
};

Serializer Example

This example shows how certain objects can be serialized to custom formatted strings. Keep in mind that it is only the entry's content (%C) that is serialized, so that you can use the logFormat configuration as well.

config.serializers = {
  superagentError: (err) => {
    return `${err.status} ${err.response.text}`;
  }
};

Further specifying log format logFormat: '%C (%L)' will result in the following output: 404 Not found (4).

4.2.3

6 years ago

4.2.2

6 years ago

4.2.1

6 years ago

4.2.0

6 years ago

4.1.2

6 years ago

4.1.1

6 years ago

4.1.0

6 years ago

4.0.0

6 years ago

3.3.1

7 years ago

3.3.0

7 years ago

3.2.2

7 years ago

3.2.1

7 years ago

3.2.0

7 years ago

3.1.0

7 years ago

3.0.0

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

1.1.7

7 years ago

1.1.6

7 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.0.1

7 years ago