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

simple-gcloud-logger

v1.3.2

Published

An easy interface to send logs to Google Cloud Platform Logging.

Downloads

13

Readme

simple-gcloud-logger

An easy interface to send logs to Google Cloud Platform Logging for Compute Engine, for Node.js.

Getting started - important

This is an unofficial wrapper library.

This library is strictly for writing logs and will not have permission or APIs to do anything else.

Before using this library, look at the official docs real quick. so you understand the necessary requirements for doing logging. Certain fields are required and have expected values.

https://cloud.google.com/logging/docs/api/tasks/creating-logs#write_log_entries

At the time of writing, this was a beta service of google and you must ask for access.

Usage

npm i simple-gcloud-logger
var GCloudLogger = require('simple-gcloud-logger');
var logger = new GCloudLogger({
    clientEmail: '[email protected]',
    privateKeyPath: '/path/to/my/gcloud-credentials-file.p12',
    project: 'gcloud-project-name-3543',
    logId: 'mycustomservice',
    verbose: false,
    send: true,
    commonLabels: {
        // "compute.googleapis.com/resource_id": "12345",
        // "compute.googleapis.com/resource_type": "instance",
    }
});
logger.log('Hey');
logger.log({
    insertId: +new Date() + '-asdf', // custom log entry unique id
    myText: 'Asdf',
    myCode: 7
});
logger.flush(); // force sending the logs

To print output, pass environment variables via DEBUG=<logId>. This package uses the debug module internally.

Methods

logger.log('I will be INFO');

logger.debug('I will be DEBUG');
logger.info('I will be INFO');
logger.warning('I will be WARNING');
logger.error('I will be ERROR');
logger.critical('I will be CRITICAL');

The logger can also be passed an object.

logger.log({
    level: 'DEBUG',
    someData: {
        send: 'to gcloud loggin'
    }
});

logger.error({
    err: new Error('We need more spaghetti'),
    status: 400,
    something: 'else'
});

Log method options

When passing an object to a logger method, the following internal properties are used. All other properties are passed through and will be written to the console according to DEBUG=, as well as show up in the GCloud Log Viewer.

logger.log({
    // internal gcloud logging fields - will not be outputted to debug if
    // they are included in a log message
    level: 'INFO',
    insertId: '123-asdf-456',
    timestamp: new Date().toISOString(),
    labels: {
        "compute.googleapis.com/resource_id": "12345",
        "compute.googleapis.com/resource_type": "instance",
    },

    // will be logged
    myProperty: 75,
    someText: 'hot dogs'
});