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

easyloggingpp

v9.96.7

Published

Easylogging++ binding for Node.js

Downloads

13

Readme

Easylogging++ Node.js Binding

Build Status Build status

Version

GitHub license Donate

Easylogging++ Node.js binding provides ability to use efficient Easylogging++ to log important logs for your application.

Requirements

  • Node 7+

Download

npm install --save easyloggingpp

Getting Started

const easyloggingpp = require('easyloggingpp');
const ConfigType = easyloggingpp.ConfigType;
const Level = easyloggingpp.Level;
const logger = easyloggingpp.getLogger('mylogger'); // register logger

easyloggingpp.configureAllLoggers([
    {
        config: ConfigType.Format,
        value: '%levshort %datetime %fbase:%line %msg',  // <-- fbase or file for full path
    },
    {
        config: ConfigType.Filename,
        value: 'logs/output.log'
    }
]);

// alternatively you can use following to set default configurations
// for future loggers as well as existing logger
easyloggingpp.configureAllLoggers({
    config_file: 'easylogging-config.conf',
});

logger.info('simple log');
logger.info('array %s', [1, 2, 3]);
var person = { 'name': 'Adam', 'age': 960, }
logger.info('obj %s', person);

logger.error('an error occurred %s', new Error("error msg"));

easyloggingpp.setLogErrorStack(false); // turn stack logging off
logger.fatal('serious error occurred %s', new Error("fatal msg"));
logger.error('an error occurred %s', new Error("error msg"));

Above will print something like: sample-output

Log

logger.info(...);
logger.warn(...);
logger.error(...);
logger.debug(...);
logger.trace(...);
logger.fatal(...);
logger.verbose(verbose_level, ...);

Log Formats

You can use advanced logging format specifiers.

logger.info('array %s', [1, 2, 3]);

Taken from utils.format

| Format specifier | Explanation | |----|-----| | %s | String. | | %d | Number (integer or floating point value). | | %i | Integer. | | %f | Floating point value. | | %j | JSON. Replaced with the string '[Circular]' if the argument contains circular references. | | %% | single percent sign ('%'). This does not consume an argument. |

%o and %O should not be used. Use %s instead for better output.

Global Configuration

via File

easyloggingpp.configureAllLoggers({
    config_file: 'easylogging-config.conf',
});

This will configure all the existing loggers and set this new configuation to default for future loggers.

All Levels

easyloggingpp.configureAllLoggers({
    config: easyloggingpp.ConfigType.Format,
    value: '%datetime %msg',
});

or using array

easyloggingpp.configureAllLoggers([
  {
      config: easyloggingpp.ConfigType.Format,
      value: '%datetime %msg',
  },
  {
    config: easyloggingpp.ConfigType.Format,
    value: '%datetime %file:%line %msg',
  }
]);

This will configure existing loggers but will not change future loggers.

Specific Level

easyloggingpp.configureAllLoggers({
    level: easyloggingpp.Level.Info,
    config: easyloggingpp.ConfigType.Format,
    value: '%datetime %msg',
});

or using array

easyloggingpp.configureAllLoggers([
  {
      level: easyloggingpp.Level.Info,
      config: easyloggingpp.ConfigType.Format,
      value: '%datetime %msg',
  },
  {
    level: easyloggingpp.Level.Debug,
    config: easyloggingpp.ConfigType.Format,
    value: '%datetime %file:%line %msg',
  }
]);

This will configure existing loggers but will not change future loggers.

Logger Configuration

via File

const logger = easyloggingpp.getLogger('logger1');
logger.configure({
    config_file: 'easylogging-config.conf',
});

All Levels

const logger = easyloggingpp.getLogger('logger1');

logger.configure({
    config: easyloggingpp.ConfigType.Format,
    value: '%datetime %msg',
});

or using array

const logger = easyloggingpp.getLogger('logger1');
logger.configure({
    config: easyloggingpp.ConfigType.Format,
    value: '%datetime %msg',
});

Specific Level

const logger = easyloggingpp.getLogger('logger1');

logger.configure({
    config: easyloggingpp.ConfigType.Format,
    value: '%datetime %msg',
});

or using array

const logger = easyloggingpp.getLogger('logger1');
logger.configure({
    config: easyloggingpp.ConfigType.Format,
    value: '%datetime %msg',
});

This will configure existing loggers but will not change future loggers.

Add/Remove Logging Flag

easyloggingpp.addFlag(easyloggingpp.LoggingFlag.ColoredTerminalOutput);
easyloggingpp.removeFlag(easyloggingpp.LoggingFlag.ColoredTerminalOutput);

Profiler

You can use built-in profiler

logger.startProfiling('profiling-id');
// some heavy task
for (var i = 0; i < 100000; ++i) {

}
logger.endProfiling('profiling-id');

// other tasks that will not be profiled
// if needed or you could use finishProfiling directly

logger.finishProfiling('profiling-id', (item) => {
    logger.info(`finished profiling in ${item.diff}ms`);
});

Notes

Some notes for those who have previous experience with Easylogging++ (and for those who are absolutely new)

  • Logs are written to /dev/null by default. You must configure via easyloggingpp.configureAllLoggers at initialization.
  • Loggers are created automatically when you use easyloggingpp.getLogger.
  • ColoredTerminalOutput flag is set by default. You can unset it using easyloggingpp.removeFlag
  • You can safely log with Fatal level as DisableApplicationAbortOnFatalLog flag is set by default. You should not remove this flag. Read more

License

Copyright 2017-present Zuhd Web Services
Copyright 2017-present @abumusamq

https://github.com/zuhd-org
https://zuhd.org
https://muflihun.com

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.