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

simplr-logger

v1.0.1

Published

Simple JavaScript logger written in TypeScript that can be used in browser or node application.

Downloads

486

Readme

Simplr Logger

NPM version Build Status Coverage Status dependencies Status devDependencies Status

Simple JavaScript logger written in TypeScript that can be used in browser or node application.

The package is most useful when used with TypeScript.

Get started

npm install simplr-logger

Building logger

With default configuration

import { LoggerBuilder } from "simplr-logger";

const logger = new LoggerBuilder();

With configuration builder

import { LoggerBuilder, LoggerConfigurationBuilder, LogLevel } from "simplr-logger";
import { FileMessageHandler, ConsoleMessageHandler } from "simplr-logger/handlers";

const config = new LoggerConfigurationBuilder()
    .SetDefaultLogLevel(LogLevel.Trace)
    .AddWriteMessageHandlers([
        { Handler: new ConsoleMessageHandler() },
        { Handler: new FileMessageHandler("./logs.txt") }]
    )
    .Build();

const logger = new LoggerBuilder(config);

With simple object

import { LoggerBuilder, LogLevel, ConsoleMessageHandler } from "simplr-logger";

const logger = new LoggerBuilder({
    DefaultLogLevel: {
        LogLevel: LogLevel.Trace,
        LogLevelIsBitMask: false
    },
    WriteMessageHandlers: [{
        Handler: new ConsoleMessageHandler(),
        LogLevel: LogLevel.Critical | LogLevel.Debug,
        LogLevelIsBitMask: true
    }]
});

Creating logger handler

import { MessageHandlerBase, LogLevel, LoggerBuilder, LoggerConfigurationBuilder } from "simplr-logger";

class MyMessageHandler extends MessageHandlerBase {
    public HandleMessage(level: LogLevel, timestamp: number, messages: any[]): void {
        console.log(...messages);
    }
}

const config = new LoggerConfigurationBuilder()
    .AddWriteMessageHandler({ Handler: new MyMessageHandler(), LogLevel: LogLevel.Trace })
    .Build();

const logger = new LoggerBuilder(config);

Using logger

Logging with methods

logger.Critical("Critical", "message");
logger.Debug("Debug", "message");
logger.Error("Error", "message");
logger.Info("Info", "message");
logger.Warn("Warn", "message");
logger.Trace("message", "with trace");

Logging with log level

logger.Log(LogLevel.Information, "Info message");
logger.Log(LogLevel.Critical, new Error("Critical error"));

Updating configuration

// Using old configuration
logger.UpdateConfiguration(builder => builder.SetPrefix("[new prefix]").Build());

// Or with default configuration
logger.UpdateConfiguration(builder => builder.SetPrefix("[new prefix]").Build(), false);

API

LogLevel

| Name | Value | Description | |-------------|:-----:|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | None | 0 | Not used for writing log messages. Specifies that a logging category should not write any messages. | | Critical | 1 | Logs that describe an unrecoverable application or system crash, or a catastrophic failure that requires immediate attention. | | | Error | 2 | Logs that highlight when the current flow of execution is stopped due to a failure. These should indicate a failure in the current activity, not an application-wide failure. | | Warning | 4 | Logs that highlight an abnormal or unexpected event in the application flow, but do not otherwise cause the application execution to stop. | | Information | 8 | Logs that track the general flow of the application. These logs should have long-term value. | | Debug | 16 | Logs that are used for interactive investigation during development. These logs should primarily contain information useful for debugging and have no long-term value. | | Trace | 32 | Logs that contain the most detailed messages. These messages may contain sensitive application data. These messages are disabled by default and should never be enabled in a production environment. |

Configuration

| Name | Default value | Description | |-----------------------|----------------------------------------------------------------------------|--------------------------------------------------------------------| | WriteMessageHandlers | [{ Handler: new ConsoleMessageHandler() }] | Message handlers list. ⁽¹⁾ | | DefaultLogLevel | { LogLevel: LogLevel.Warning, LogLevelIsBitMask: false } | Log level or log levels in bit mask value. | | Prefix | undefined | Custom message, which will be injected into the start of messages. |

(1) - The default value is only available if configuration property is not set.

License

Released under the MIT license.