Code Monkey home page Code Monkey logo

node-simple-redis-logger's Introduction

Node-Simple-Redis-Logger

About

A simple Node.JS module to store logs into Redis List, based on node-redis

Install

Install via NPM npm install simple-redis-logger

Then, import it in your project.

let SimpleRedisLogger = require('simple-redis-logger')

Methods

constructor([options])
  • options - Optional. An object containing any or all of the following options

    • redis - Optional, a node-redis client instance
    • connectOptions - Optional, a node-redis connection option object, check more details here
    • throwErrors - Optional, default is false. If throwErrors is set to false, the module will not throw errors if an error occurs while communicating with Redis server. But it will still throw Errors if an error occurs in getLogs method. And error event will always emit while an error occurs.
    • limitAmount - Optional, the amount of log messages in every list(or called types in this case). Default is null, which means there is no limit on the amount of messages.
    • serviceName - Optional, the prefix of the list. Default is simple-logger.

    To connect to the Redis server, either redis or connectOptions is Required.

log(type)(content)
  • type - type of the message.
  • content - Can be string, Object, or Error Object.
    • String: The module will store the original string to the Redis List
    • Object: Using JSON.stringify to convert the Object into String, then store to Redis List
    • Error Object: Module will store myError.message to the Redis List
[async] getLogs(type[, from[, end]])
  • type - type of the messages
  • from - Optional, the beginning index of the messages you want to get. Default is 0
  • end - Optional, the ending index of the messages you want to get. Default is -1

Returns

  • logs - An array of the logs
    • log - A log Object
      • content - The log contents
      • timestamp - The timestamp of the time when the log is committed.
      • time - A Date Object of the time when the log is committed.

Example

To create a logger
let logger = new SimpleRedisLogger({
    serviceName: 'test_logger',
    limitAmount: 3
})
logger.log('info')(new Error('This is an Error'))
logger.log('info')('This is an example of String message')
logger.log('info')({
    message: 'This is an example of Object'
})
To get logs
logger.getLogs('info')
    .then((infos) => {
        ...
    })

node-simple-redis-logger's People

Contributors

y2nk4 avatar

Stargazers

 avatar  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.