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

simple-redis-logger

v1.0.0

Published

A simple Node.JS module to store logs into Redis List, based on [node-redis](https://www.npmjs.com/package/redis)

Downloads

5

Readme

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) => {
        ...
    })