Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cf-logs

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cf-logs

codefresh logs

  • 1.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
517
decreased by-71.42%
Maintainers
1
Weekly downloads
 
Created
Source

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 = {
  filePath: String,
  console: Boolean,
  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 to file

Set 'filePath' field to an absolute path to a file save the logs to a file. The default is set to null which means no logging to file will happen.

Logging to console

Set 'console' filed to true or false to log to the console. The default is set to true

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

Keywords

FAQs

Package last updated on 04 Apr 2019

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