Coder Social home page Coder Social logo

s3pweb / s3pweb-logger Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 0.0 1.62 MB

A simple lib to log message using bunyan to console, file and logstash.

License: ISC License

JavaScript 96.26% Shell 3.74%
nodejs bunyan logger logging logstash console file

s3pweb-logger's Introduction

npm (scoped)

This is a simple lib to log messages built on top of bunyan. This lib can send logs to the console, to a file or to a logstash instance.

Installation

npm install @s3pweb/s3pweb-logger

Configuration

The constructor expect a config object following this format:

{
  "name": "your-application-name",
  "logger": {
    "source": false,
    "console": {
      "enable": true,
      "level": "debug"
    },
    "file": {
      "enable": true,
      "level": "info",
      "dir": "./logs",
      "addHostnameToPath": true
    },
    "server": {
      "enable": true,
      "level": "trace",
      "url": "0.0.0.0",
      "port": "9998",
      "type": "elk"
    },
    "ringBuffer": {
      "enable": true,
      "size": 5
    }
  }
}

Example

const Logger = require('@s3pweb/s3pweb-logger')

const log = new Logger(config).get()
const child = log.child({ child: 'childName' })

log.info('one message from log')
child.info('one message from child')

Tests

Set the name of your environment with NODE_ENV=xxxx before node

NODE_ENV=test node example/example.js

Bonus

To start a ELK stack on docker :

chmod +x example/startElk.sh 

./example/startElk.sh

Or with docker compose :

docker-compose -f example/docker-stack.yaml up -d

Open your favorite browser : http://localhost:5601

Create an index with just * (replace logstash-* by *)

s3pweb-logger's People

Contributors

dependabot[bot] avatar kasia-sztymelska avatar mualig avatar sguilly avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.