Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

fdemir/flex-logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flex Logger

This package saves the logs inside the database. It is so simple and very easy to use. It's supports MongoDB and Mysql. You dont need a create a table. If there is no table, it is gonna create automatically.

Install

$ npm install flex-logger

Documentation

Quick Start

const FlexLogger = require('flex-logger')

Firstly you must create instance from flex logger class. Flex logger constructor can take arguments.

Mongodb:

const logger = new FlexLogger('mongodb', 'mongodb+srv://username:password@host/dbname', 'collectionName')

Mysql:

const logger = new FlexLogger('mysql', 'host=localhost;user=root;password=;dbname=test;', 'tableName')

There is five log level has automatically created. Each level has own unique number.

Now logging time

Logging

  FATAL: 0
  ERROR: 10
  WARN: 20
  INFO: 30
  DEBUG: 40
logger.fatal('fatal error')
logger.error('something is wrong')
logger.warn('it is gonna explode')
logger.info('i am super')
logger.debug('debug')

Event Handlers

It will be executed before the log save in the database.

Usage:

  logger.on(level, (msg, level) => {})

Example:

  logger.on(10, (msg, level) => {
    console.log('hello')
  })

Custom Levels

You can set a new log method with level number and name.

Usage:

  logger.setLevel('success', 100)

Example:

  logger.success('hello world')

For more example please look at the examples folder. And, just let me know when you find a bug.

Contributors

Lisence & Copyright

@ Furkan Demir

Lisenced under the MIT Lisence

About

Save your app logs in your database

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published