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

cf-logs

v1.1.28

Published

codefresh logs

Downloads

3,171

Readme

Coverage Status

Codefresh logging library

This library is a wrapper of winston logging library that adds additional beheaviour dedicated for our use.

Basic Usage - default logger

var logger = require('cf-logs');

logger.info("info message");
logger.error("error message");

Notice that if you use this option then you will not be able to use the DEBUG environment variable to filter these logs. So our main use should be with the advanced usage.

Advanced Usage - specific namespaced logger

You can provide a namespace for your current logger, just like in 'debug' module and then controll the output logs with DEBUG environment variable

var logger = require('cf-logs').Logger("codefresh:example");

logger.info("info message");
logger.debug("debug meesage"):

This is very powerfull for development, because many times you want to see only logs from a specific part of the application so you can for example set the DEBUG environment variable to for example: "codefresh:builds". The default is set so that all logs that begins with a namespace 'codefresh,codefresh:*' will be shown.

Logging Errors

var logger = require('cf-logs').Logger("codefresh:example");

var error = new Error("very bad error");
logger.error("error: %s", error.toString());
logger.error("stack: %s", error.stack);

Configuring the logger

The options that can be passed are:

var options = {
  showNamespace: Boolean,
  env_module: String,
  showRequestId: Boolean,
  level: String(one of: "error/warn/info/debug"),
  consoleOptions: {
      formatter: function(options) {
          // Receives the consoleOptions object, merged with the meta objects
          // Should return a formatted string for this log.
          // This is an example:
          return new Date().toISOString() +' '+ options.level.toUpperCase() +' >> '+ (undefined !== options.message ? options.message : '') +
                                    (options.meta && Object.keys(options.meta).length ? ' << ' + JSON.stringify(options.meta) : '' );
      }
  },
  basePath: String,
  baseNamepsace: String
}

var logger = require('cf-logs');
logger.setGlobalOptions(options);

Logging levels

The logging level is an additional filter that can be set, mainly for production usage. we have 4 levels, from highest to lowest priority:

  1. error
  2. warn
  3. info
  4. debug If not set, the default logging level is 'debug'. For example: if we set the logging level to warn, then only error and warn logs will be handled. info and debug will not be handled.

Showing namespace

Set 'showNamespace' field to true or false to show the namespace in the logs The default is false

Global name to the logger

You can set 'env_module' field to a name that will be shown on all logs. for example: "cf-api-machine-1" The default is set to null which will not print anything

Show request id

Set 'showRequestId' field to true or false to show the current request id if exists The default is set to false

Namespace based on file path

Set the basePath to your project root (__dirname), then create loggers with __filename as the namespace. Also, set your base namespace. (e.g. lalala) Result: basePath: /home/user/workspace/projectDir namespace: projectName newLogger(//home/user/workspace/projectDir/internalDir/file.js) will get the namespace: projectName:internalDir:file