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

@zaneray/gcp-node-logging

v2.0.0

Published

Seller of the Product

Downloads

386

Readme

/**

  • This is a wrapper aroung the Winson logger, with support for logging to
  • Google Cloud Platform (GCP) Logging.
  • The behavior keys of NODE_ENV.
  • If NODE_ENV is 'development', logging is done to the console on one line
  • with a timestamped entry. Otherwise logging is streamed to the GCP Logging
  • in JSON format.
  • If NODE_ENV is 'development', all log levels are logged.
  • If NODE_ENV is 'test' or 'staging', log levels above 'debug' are logged.
  • If NODE_ENV is 'production', only log level 'error' is logged.
  • The level determined by NODE_ENV can be overwritten by calling the `logging.setLevel(level)'
  • method at runtime.

*/

ZaneRay Node Logging

This is a wrapper aroung the Winson logger, with support for logging to Google Cloud Platform (GCP) Logging.

Environments

The logging behavior keys of NODE_ENV, and supports the following environments

  • development, all log levels are logged.
  • test, log levels >= 'debug' are logged.
  • staging, log levels >= 'debug' are logged.
  • production, log levels >= 'info' are logged.

Log Levels

The levels supported are the Winton defaults.

The log level can be changed at runtime by using the logging.setLevel(level) method.

Setting the log level at runtime affects all loggers and their transports in the runtime.

Logging levels in winston conform to the severity ordering specified by syslog and supported by GCP Logging.

See https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#logseverity for levels and semantics/usage.

In order of severity, the log levels are

  • debug, info, notice, warning, error, crit (short for critical), alert, emerg (short for emergency)

  • development, log levels >= 'debug' are logged.

  • test, log levels >= 'debug' are logged.

  • staging, log levels >= 'debug' are logged.

  • production, log levels >= 'error' are logged.

Transports

Transports defines where logging output is sent and the formet, based on the environment

  • development, logs to Console/Standard Out, on a single line with a timestamp

  • test, logs to GCP Logging in JSON format, GCP Logging sets the timestamp

  • staging, logs to GCP Logging in JSON format, GCP Logging sets the timestamp

  • production, logs to GCP Logging in JSON format, GCP Logging sets the timestamp

Usage (see test/loggingTest.mjs)

in your node project

yarn add @zaneray/gcp-node-logging

in your application code

const {logging, logger} = require("@zaneray/gcp-node-logging");
// Writes some log entries
logger.info("here's some information");
logger.warn("something might be wrong");
logger.error("something is wrong, seriously");

//change log level to log warn and above
logging.setLevel("warning");
//show the current level
logger.warning(logging.getLevel());

// Writes some log entries
logger.info("here's some information");
logger.warning("something might be wrong");
logger.error("something is wrong, seriously");

to configure different transports, or formats, the 'logging' object is also esposed.

import {logging} from '../lib/logging.mjs';
import winston from 'winston';

let transports = [new winston.transports.Console({level: "debug",handleExceptions: true})];
let format = winston.format.json();

const customLogger = logging.getCustomLogger(transports,format);

// Writes some log entries
customLogger.debug("Debug or trace information");
customLogger.info("Routine information, such as ongoing status or performance");
customLogger.notice("Normal but significant events, such as start up, shut down, or a configuration change");
customLogger.warning("Warning events might cause problems");
customLogger.error("Error events are likely to cause problems");
customLogger.crit("Critical events cause more severe problems or outages");
customLogger.alert("A person must take an action immediately");
customLogger.emerg("One or more systems are unusable");