New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

simplr-logger

Package Overview
Dependencies
Maintainers
2
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simplr-logger

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

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

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

NameValueDescription
None0Not used for writing log messages. Specifies that a logging category should not write any messages.
Critical1Logs that describe an unrecoverable application or system crash, or a catastrophic failure that requires immediate attention.
Error2Logs 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.
Warning4Logs that highlight an abnormal or unexpected event in the application flow, but do not otherwise cause the application execution to stop.
Information8Logs that track the general flow of the application. These logs should have long-term value.
Debug16Logs that are used for interactive investigation during development. These logs should primarily contain information useful for debugging and have no long-term value.
Trace32Logs 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

NameDefault valueDescription
WriteMessageHandlers[{ Handler: new ConsoleMessageHandler() }]Message handlers list. ⁽¹⁾
DefaultLogLevel{ LogLevel: LogLevel.Warning, LogLevelIsBitMask: false }Log level or log levels in bit mask value.
PrefixundefinedCustom 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.

Keywords

FAQs

Package last updated on 28 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc