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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@luckyorange/utilities-cron-logger

v1.1.4

Published

More helpful log messages for cron jobs

Readme

LuckyLogger

LuckyLogger is a lightweight logging utility built specifically for cron jobs. It uses Google Cloud Logging and can optionally patch console.log, console.error, etc. to log to GCP automatically.

Features

  • Simple setup with minimal configuration
  • Automatically formats logs with proper severity levels
  • Filters logs based on a minimum log level
  • Adds Kubernetes pod and container metadata automatically
  • (New!) Optional patching of console methods to log to GCP

Installation

npm install @luckyorange/utilities-cron-logger

Usage

1. Basic Logging

const LuckyLogger = require('@luckyorange/utilities-cron-logger')
// Initialize with the name of your cron job
const logger = new LuckyLogger('session-count-check')

2. Logging to GCP

logger.info('Starting session count check')
logger.debug('Session count details', { sessionCount: 42 })
logger.warn('Session count is lower than expected')
logger.error('Failed to fetch session data')
logger.critical('Session service unreachable')

Constructor

new LuckyLogger(cronName, options = {})

| Parameter | Type | Default | Description | |-------------|----------|--------------|-------------| | cronName | string | (required) | Name of the cron job (used for the log name and container name) | | options | object | {} | Configuration options (see below) |

Options

| Option | Type | Default | Description | |----------------|-----------|-----------|-------------| | minLogLevel | string | 'INFO' | Minimum severity to log (DEBUG, INFO, WARNING, ERROR, CRITICAL) | | patchConsole | boolean | false | Whether to patch console.log, console.warn, etc. to log to GCP |

Examples

Basic usage with defaults:

const logger = new LuckyLogger('session-count-check')

With options:

const logger = new LuckyLogger('session-count-check', {
  minLogLevel: 'ERROR',
  patchConsole: true
})

Just enabling console patching:

const logger = new LuckyLogger('session-count-check', { patchConsole: true })
console.log('This logs to both the terminal and Google Cloud Logging')

Log Methods

Each method corresponds to a severity level in Google Cloud Logging: | Method | Severity | |---------------------------------|------------| | logger.debug(message, metadata) | DEBUG | | logger.info(message, metadata) | INFO | | logger.warn(message, metadata) | WARNING | | logger.error(message, metadata) | ERROR | | logger.critical(message, metadata)| CRITICAL |

  • message: a string describing the log event
  • metadata: (optional) an object with additional information (e.g., IDs, counts, etc.)

Optional: Restore Console

If you enabled patchConsole and later want to undo it:

logger.restoreConsole()
console.log('Now this logs only to the terminal')

Environment Variables

  • HOSTNAME — auto-populated in Buddy; used as the pod_name
  • CONTAINER_NAME — auto-populated in Buddy or container environments

Example

const LuckyLogger = require('@luckyorange/utilities-cron-logger')
const logger = new LuckyLogger('session-count-check', {
  minLogLevel: 'INFO',
  patchConsole: true
})

logger.info('Cron started')
console.warn('This is also sent to GCP because patchConsole is enabled')

try {
  logger.debug('Fetched session data', { sessions: 500 })
} catch (error) {
  logger.error('Error during cron execution', { error: error.message })
}

Optional: Restore Console

If you enable patchConsole, you can later restore the original console methods to stop logging to Google Cloud.

Example

const LuckyLogger = require('@luckyorange/utilities-cron-logger')
// Enable console patching
const logger = new LuckyLogger('session-count-check', { patchConsole: true })
console.log('This goes to both terminal and GCP')

// Restore original console behavior
logger.restoreConsole()
console.log('This now logs to terminal only')

This is useful if you only want GCP logging during certain phases of a script, or for fine-grained control in tests, parallel jobs, or debugging.


License

Internal use only — property of Lucky Orange