npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@digipolis/log

v1.1.0

Published

A logging tool for Digipolis kibana logging

Downloads

24

Readme

CI Coverage Status npm version

npm: npmjs.com/package/@digipolis/log

@digipolis/log

Log helper which converts default logs to indexable json log.

Table of contents:

Spec

https://github.com/digipolisantwerpdocumentation/logging-requirements

Installing

npm:

$ npm i @digipolis/log

Yarn:

$ yarn add @digipolis/log

Configuration

Params:

| Param | Description | Values | | :--- | :--- | :--- | | type (optional) | Set logging mode | log (default) / json / text / silent | | override (optional) | Set to override given console (default) | true / false (default) | | level (optional) | Set the log level (given level and higher will be logged | debug (default) / info / log / warn / error |

Examples

Example:
const digipolisLogger = require('@digipolis/log');

const mylogger = digipolisLogger(console, {
  type: 'text', // log(default) | json | text
  override: false, // false(default) | true
});

// human readable for local development
mylogger.log('hello');
/*
type: 'text' -> INFO: 2021-12-01T09:43:19.173Z hello
*/

const mylogger = digipolisLogger(console, {
  type: 'json', // log(default) | json | text
  override: false, // false(default) | true
});

// human readable json local development
mylogger.log('hello');
/*
type: 'json' -> {
  message: 'hello',
  timestamp: '2021-12-01T09:44:20.565Z',
  type: [ 'technical' ],
  level: 'INFO',
  correlationId: ''
}
*/

const mylogger = digipolisLogger(console, {
  type: 'log', // log(default) | json | text
  override: false, // false(default) | true
});
// log for kibana json for production
mylogger.log('hello');
/*
type: 'log' -> {"message":"hello","timestamp":"2021-12-01T09:45:56.515Z","type":["technical"],"level":"INFO","correlationId":""}
*/

const mylogger = digipolisLogger(console, {
  type: 'log', // log(default) | json | text
  override: false, // false(default) | true
  level: "error", // debug(default) | info | log | warn | error
});
// log for kibana json for production only error
mylogger.log('logmessage'); // -> won't be visible
mylogger.error('error');
/*
type: 'log' ->
type: 'error' -> {"message":"error","timestamp":"2021-12-01T09:45:56.515Z","type":["technical"],"level":"ERROR","correlationId":""}
*/
Example (override the global log (this will impact more than just your code)):
const digipolisLogger = require('@digipolis/log');

digipolisLogger((console, {
  type: 'text', // log(default) | json | text
  override: true, // false(default) | true
});

// human readable for local development
console.log('hello');
/*
type: 'text' -> INFO: 2021-12-01T09:43:19.173Z hello
*/

digipolisLogger((console, {
  type: 'json', // log(default) | json | text
  override: true, // false(default) | true
});
// human readable json local development
console.log('hello');
/*
type: 'json' -> {
  message: 'hello',
  timestamp: '2021-12-01T09:44:20.565Z',
  type: [ 'technical' ],
  level: 'INFO',
  correlationId: ''
}
*/

digipolisLogger((console, {
  type: 'log', // log(default) | json | text
  override: true, // false(default) | true
});
// log for kibana json for production
console.log('hello');
/*
type: 'log' -> {"message":"hello","timestamp":"2021-12-01T09:45:56.515Z","type":["technical"],"level":"INFO","correlationId":""}
*/

output examples


// type: json
console.log('hello');
/*
{
  message: 'hello',
  timestamp: '2021-12-01T09:44:20.565Z',
  type: [ 'technical' ],
  level: 'INFO',
  correlationId: ''
}
*/

// type: json
console.error('hello');
/*
{
  message: 'hello',
  timestamp: '2021-12-01T09:44:20.565Z',
  type: [ 'technical' ],
  level: 'ERROR',
  correlationId: ''
}
// type: json
*/

console.error(new Error('Errormessage'));
/*
{
  message: 'Errormessage Error: Errormessage\n' +
    '    at Object.<anonymous> (/Users/oliviervandenmooter/Projects/Digipolis/diglog/example/index.js:17:13)\n' +
    '    at Module._compile (node:internal/modules/cjs/loader:1095:14)\n' +
    '    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1124:10)\n' +
    '    at Module.load (node:internal/modules/cjs/loader:975:32)\n' +
    '    at Function.Module._load (node:internal/modules/cjs/loader:816:12)\n' +
    '    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)\n' +
    '    at node:internal/main/run_main_module:17:47',
  timestamp: '2021-12-01T11:00:13.073Z',
  type: [ 'technical' ],
  level: 'ERROR',
  correlationId: ''
}
*/

// structured message
console.log({ message: 'logmessage2', timestamp: 'timestamp123' })
/*
{
  message: 'logmessage2',
  timestamp: 'timestamp123',
  type: [ 'technical' ],
  level: 'INFO',
  correlationId: ''
}

// structured message with extra params
*/
console.log({ message: 'logmessage2', timestamp: 'timestamp123', extra_param1: "extra_value" });

/*
{
  message: 'logmessage2 Extrainfo: {"extra_param1":"extra_value"}',
  timestamp: 'timestamp123',
  type: [ 'technical' ],
  level: 'INFO',
  correlationId: ''
}
*/

Running the tests

Run the tests in this repo:

$ npm run test
$ npm run coverage

Dependencies

none.

Versioning

We use SemVer

for versioning. For the released version check changelog / tags

Contributing

Pull requests are always welcome, however keep the following things in mind:

  • New features (both breaking and non-breaking) should always be discussed with the repo's owner. If possible, please open an issue first to discuss what you would like to change.
  • Fork this repo and issue your fix or new feature via a pull request.
  • Please make sure to update tests as appropriate. Also check possible linting errors and update the CHANGELOG if applicable.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details