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

winston-better-sqlite3

v1.0.4

Published

a better Sqlite3 transport for Winston

Downloads

55

Readme

winston-better-sqlite3

aka wbs

sqite3 Transport for Winston

Install

$ npm install winston-better-sqlite3

Use

const winston = require('winston');

const wbs = require('winston-better-sqlite3');
const logger = winston.createLogger({
    level: 'info',
    format: winston.format.json(),
    transports: [
        new wbs({

            // 'db' is required, and should include the full 
            // path to the sqlite3 database file on the disk
            db: '<name of sqlite3 database file>',

            // The name of the table to use in the database.
            // Defaults to 'log'
            table: 'log',

            // A list of the log params to log. Defaults to 
            // ['level, 'message']. These params are used as 
            // columns in the sqlite3 table
            params: ['level', 'resource', 'query', 'message']
        })
    ]
});

There are a couple of sqlite3 transports for Winston out there, but this one is different. For one, it uses Josuha Wise's most excellent better-sqlite3 package. Second, in my biased opinion, wbs is also better because it uses no ORMs or any such middleware. It is just a plain, no-nonsense transport that writes the logs to a sqlite3 database. You have to provide the name of (and path to) the database file and optionally the table name (defaults to log), but the module creates the table (if it doesn't already exist) with the following four columns by default

CREATE TABLE IF NOT EXISTS log (
    id INTEGER PRIMARY KEY,
    timestamp INTEGER DEFAULT (strftime('%s','now')),
    level TEXT,
    message TEXT
);

Later on, in your program where you want to log something

// the following two messages will be logged
logger.log({
    level: 'info',
    resource: 'collaborators',
    query: 'q=punkish',
    message: 'searching for folks'
});

logger.log({
    level: 'error',
    resource: 'collaboratoradoras',
    query: 'q=normal',
    message: 'searching for state'
});

// the following message will not be logged because 
// its level is less important than the log level
logger.log({
    level: 'verbose',
    resource: 'funding',
    query: 'q=normal&something',
    message: 'searching for habbine'
});

Note: The user has to provide only the name of the sqlite3 database file. The module will create a database if it doesn't already exist (as sqlite3 always does), and will create a table of a given name (log by default) inside the database if the table doesn't already exist.

The id and timestamp columns are automatically inserted by sqlite3. The user can provide whatever others columns needed for tracking logging info. For example, I use level, resource, query and message in one of my projects (as shown in the example above). All logging params are stored in columns of datatype TEXT.