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

dblogger

v0.7.2

Published

Native code logging library, DB enabled

Downloads

11

Readme

dblogger

This implements a simple logging interface that is able to stream the log entries to a DB server or local sqlite files.

Obtaining the package

Just install dblogger with npm install --save dblogger

Changelog

see CHANGELOG.md

API

Initialization

Initialize a named logger:

const logger = require('dblogger')({
	type: "sqlite",
	name: "./test.db",
	stdout: true,
});

To get access to an already initialized logger just skip the options object:

const logger = require('dblogger')();

Available options in the options object:

  • type: sqlite, postgres or none (ask me if you need more)
  • name: db name to use (path to db file for sqlite, optional if using none)
  • host: db host (invalid for sqlite)
  • port: port number for db server (invalid for sqlite) (optional)
  • user: username for db server (invalid for sqlite) (optional)
  • password: password for db server (invalid for sqlite) (optional)
  • level: log level (defaults to 0/trace) (optional)
  • tablePrefix: prefix for logging tables (defaults to logger) (optional)
  • stdout: Mirror all log entries to stdout and stderr (for level >= 50/error) (optional)
  • logger: Name of the logger (if more than one service logs to the same db, defaults to default) (optional)

The logger is a native C++ addon, so all logging is sync. You can be sure that every log entry is in the DB when the log statement returns!

Usage

Log something

logger.trace('Message');
logger.debug('Message');
logger.info('Message');
logger.log('Message'); // same log level as info
logger.warn('Message');
logger.error('Message');
logger.fatal('Message');

If you log objects or arrays a JSON representation is logged

Set log level

You may set the log level on initialization or later by creating a new instance:

const logger = require('dblogger')(30);

Define tags for log entry

All log entries may be tagged for easier filtering and searching:

logger.tag('mytag', 'anothertag').log('Message');

All tags that are defined will be added to the returned logger instance. You could even do the following:

const logger = require('dblogger')().tag('globaltag');

logger.log('Message'); // this message will be tagged with `globaltag`

Log-rotation

If you're logging into an SQLite file you may want to rotate the logfiles from time to time. To do that just use the following procedure:

  1. Rename the logfile that the process currently logs into
  2. Send a HUP signal to the node process

The logging library will then close the old logfile and start anew with an empty file. Please do not use "copy and truncate" rotation as this makes SQLite sad (meaning: you will probably corrupt the "old" file and the logger will crash at the next log statement)

Command line example:

mv logfile.db logfile.db.1
pkill -F pidfile.pid -HUP

DB Schema

TODO