Giter Site home page Giter Site logo

rowno / ecs-logs-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from segmentio/ecs-logs-js

0.0 1.0 0.0 805 KB

Simple Node.js console logger that outputs human friendly and ecs-logs compatible messages

License: MIT License

TypeScript 100.00%

ecs-logs-js's Introduction

ecs-logs-js

A simple Node.js console logger that outputs human friendly messages in development and ecs-logs compatible messages in production. Supports all of Node's primitive data types, including those that can't be JSON stringified like Error, Map, Set and BigInt.

TypeScript types are also included in the package.

Development log output example

Install

yarn add ecs-logs-js
# or
npm install ecs-logs-js

Usage

import { Logger } from 'ecs-logs-js'

const logger = new Logger({ devMode: true })
logger.info('Server started at http://localhost:8000')
logger.warn('Request rate limited', { ip: '127.0.0.1' })
logger.error('๐Ÿšจ Unexpected Error', new Error('Failed to connect to Postgress'))

API

new Logger(options?)

Creates a new logger instance.

options

Type: object

level

Type: 'emerg' | 'alert' | 'crit' | 'error' | 'warn' | 'notice' | 'info' | 'debug'
Default: 'debug'

Sets the maximum log level that will be output. By setting this option to 'info', it can be used to disable debug logs in production.

devMode

Type: boolean
Default: process.env.NODE_ENV === 'development'

Enables the human friendly development output.

logger.log(level, message, data?)

Logs a message at the given log level.

level

Type: 'emerg' | 'alert' | 'crit' | 'error' | 'warn' | 'notice' | 'info' | 'debug'

Log level for the message.

message

Type: string

The message to log.

data

Type: any

Any additional data to log with the message. This can be any type.

logger.emerg(message, data?)

logger.alert(message, data?)

logger.crit(message, data?)

logger.error(message, data?)

logger.warn(message, data?)

logger.notice(message, data?)

logger.info(message, data?)

logger.debug(message, data?)

Logs a message at the respective log level.

message

Type: string

The message to log.

data

Type: any

Any additional data to log with the message. This can be any type.

Development

Make sure you have Node >=10 and Yarn installed, and then run yarn install to install the development dependencies.

To run the tests use yarn test. To run the tests in watch mode use yarn test --watch.

To lint the files use yarn lint.

To compile the TypeScript files use yarn build.

ecs-logs-js's People

Contributors

achille-roussel avatar dependabot[bot] avatar dominicbarnes avatar kevinburkesegment avatar rowno avatar

Watchers

 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.