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

w-tiny-logger

v0.0.7

Published

Small and simple logger for Node.JS Apps. Implementing winston.

Downloads

3

Readme

w-tiny-logger

An easy-to-use logger to implement on your NodeJs App. It implements winston logger.

Example

const logger = require("w-tiny-logger").getLogger()

logger.info("Hi there, my first log!")

This example will just log on your console.

File Logging

If you want to log information on a log file, you can try the next example:

const logger = require("w-tiny-logger").getLogger({
    File: {}
})

logger.info("Hi there, my first file log!")

Metadata

You can log string messages, or maybe JSON metadata objects.

const logger = require("w-tiny-logger").getLogger({})

logger.info("Logging my JSON!", { myObject: "This is my JSON Metadata object" })
logger.warn("Logging my JSON!", { whatever: "This is my warn" })

Logging Levels

You can use different levels for logging.

const logger = require("w-tiny-logger").getLogger({})

logger.log('info', "Info log");
logger.log('warn', "Warn log");
logger.log('error', "Error log");
logger.info("Info log by method call");
logger.warn("Warn log by method call");
logger.error("Error log by method call");

Other Transports and Multiple Transports

It´s possible to use MongoDB or Graylog aswell. Or maybe you want to use all of them together.

const logger = require("w-tiny-logger").getLogger({
    File: {
        filename: "MyLog" //optional
    },
    MongoDB: { db: "mongodb://127.0.0.1"},
    Graylog: {}
})

logger.info("Using many transports at the same time!")

It´s default the use of the Console Transport, but any other is optional.

Other Considerations

This module is an implementation of the Winston Logger Library, using some of the basic transports available for the library, like Winston Graylog2 and and Winston MongoDB.

You can find more information about the options for each transport on the authors library.

Full Example

It´s possible to implement other transports, just like using winston.

const assert = require("assert")
const winston = require('winston');
const sinon = require('sinon');
const spyLogger = require('winston-spy');

const spy = sinon.spy();

const logger = require("w-tiny-logger").getLogger({
    File: {
        filename: "MyLog" //optional
    },
    MongoDB: { 
        level: 'info',
        silent: false,
        db: "mongodb://127.0.0.1",
        options: { poolSize: 2, autoReconnect: true },
        collection: 'log',
        storeHost: false,
        username: '',
        password: '',
        label: '',
        name: '',
        capped: false,
        cappedSize: 10000000,
        cappedMax: 10000000,
        tryReconnect: false,
        decolorize: false,
        expireAfterSeconds: 10000
    },
    Graylog: {
        name: 'Graylog',
        level: 'debug',
        silent: false,
        handleExceptions: false,
        prelog: function(msg) {
            return msg.trim();
        },
        graylog: {
            servers: [{host: 'localhost', port: 12201}, {host: 'remote.host', port: 12201}],
            hostname: 'myServer',
            facility: 'myAwesomeApp',
            bufferSize: 1400
        },
        staticMeta: {env: 'staging'}
    }
}, [new spyLogger({ spy: spy })])

let message = "Using many transports at the same time!"
logger.info(message)

assert(spy.calledWith('info', message));