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

loglevel-mixin

v7.2.2

Published

mixin to declare logging methods named after a set of log levels

Downloads

2,998

Readme

npm License Typed with TypeScript bundlejs downloads GitHub Issues Build Status Styled with prettier Commitizen friendly Known Vulnerabilities Coverage Status

loglevel-mixin

Injects methods named after a set of logLevels which are only forwarding messages. If the current logLevel is higher or equal to the logLevel the name of the called method reflects.

So the model object itself can be used as a logger and the log level is directly attaches to the model

usage

import { LogLevelMixin } from 'loglevel-mixin';

const LoggingEnabledClass = LogLevelMixin(
  class BaseClass {
    log(level, message) {
      console.log(`${level} ${message}`);
    }
  }
);

const someObject = new LoggingEnabledClass();

someObject.logLevel = 'error';
someObject.info(
  severity => 'my info message (not reported since logLevel is error)'
);
someObject.logLevel = 'info';
someObject.info(
  severity => 'my info message (reported since logLevel is now info)'
);

install

With npm do:

npm install loglevel-mixin

API

Table of Contents

Logger

Type: Function

Properties

Loglevel

Type: Object

Properties

defaultLogLevels

default log levels

  • trace
  • debug
  • info
  • notice
  • warn
  • error
  • crit
  • alert

declareLevels

Generate the loglevel objects out of a list of log level names.

Parameters

  • list Array<string> A list of log level names. The last name in the list will become the one with the highest priority.

Returns Object levels object a hash with all the loglevels. Stored by there name.

defineLoggerMethods

Adds logging methods to an existing object. For each loglevel a method with the name of the log level will be created.

Parameters

  • object Object target where to assign properties to
  • logLevels Object Hash with all the available loglevels. Stored by there name (optional, default defaultLogLevels)
  • theFunction Logger? to be added under the loglevel name. This function will only be called if the current loglevel is greater equal the log level of the called logging function. By default a method log(level,message) will be used

Examples

defineLoggerMethods( obj)
obj.info('info entry'); // will redirect to theFunction if obj.loglevel is at least info
obj.error('error entry'); // will redirect to theFunction if obj.loglevel is at least error

Returns undefined

LogLevelMixin

Parameters

  • superclass Object class to be extendet
  • logLevels Object Object with all the available loglevels. Stored by their name (optional, default defaultLogLevels)
  • initialLogLevel Loglevel the default value for the logLevel property (optional, default defaultLogLevels.info)

Examples

import { LogLevelMixin } = from 'loglevel-mixin';
class BaseClass {
  log(level, message) { console.log(`${level} ${message}`); }
}
class LoggingEnabledClass extends LogLevelMixin(BaseClass) {
}

Returns Object newly created class ready to be further extendet/used

makeLogEvent

Helper function to aggregate values into a log event.

Parameters

  • severity string log severity
  • arg (string | Object) original log message - level may be overwritten
  • args Object? additional values to be merged into the final log event - values have precedence

Returns Object suitable for log event processing

license

BSD-2-Clause