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

@beyond-js/logs

v0.0.2

Published

`@beyond-js/logs` is a logging utility package for applications running on Google Cloud. It provides easy integration with Google Cloud Logging, allowing you to manage and store logs efficiently. This package uses the `@google-cloud/logging` library to

Downloads

30

Readme

@beyond-js/logs

@beyond-js/logs is a logging utility package for applications running on Google Cloud. It provides easy integration with Google Cloud Logging, allowing you to manage and store logs efficiently. This package uses the @google-cloud/logging library to send logs to Google Cloud.

Features

  • Easy integration with Google Cloud Logging
  • Supports logging with different severity levels
  • Option to initialize with service account credentials or rely on Google Cloud's default service account

Installation

npm install @beyond-js/logs

Usage

Basic Setup

Create an instance of the Logger class by providing an identifier.

import Logger from '@beyond-js/logs';

const logger = new Logger('your-log-identifier');

// Adding a log entry
await logger.add('This is a log message', 'INFO');

// Retrieving log entries
const entries = await logger.get();
console.log(entries);

Configuration with Service Account and Environment Variables

To configure the logger to use a service account JSON file for authentication in a local environment, follow these steps:

  1. Service Account JSON File: Ensure that the service account JSON file is placed in the ./credentials directory. This file is necessary for local development to authenticate with Google Cloud Logging.

  2. Environment Variables:

    • PROJECT_ID: Set the PROJECT_ID environment variable in your .env file or directly in your environment. The PROJECT_ID is only required if your logs are intended for a different project than the one where the service is running.

      Create a .env file in the root of your project (if it doesn't already exist) and add the following line:

      PROJECT_ID=your-gcp-project-id
    • LOGS_DISABLED: If the LOGS_DISABLED environment variable is set, logging will be disabled. Add the following line to your .env file to disable logging:

      LOGS_DISABLED=true

By following these steps, you can ensure that your local environment is correctly configured to authenticate and send logs to Google Cloud Logging. The PROJECT_ID environment variable helps direct logs to the appropriate project when necessary, while the LOGS_DISABLED variable can be used to turn off logging when needed.

Closing the Logger

Although the @google-cloud/logging library does not require explicit resource cleanup, you can implement a close method to handle any necessary cleanup operations.

logger.close();

Methods

constructor(id: string)

Creates a new instance of the logger. The id parameter is required.

add(text: string, severity: string = 'INFO'): Promise<void>

Adds a log entry with the specified text and severity. The severity level defaults to 'INFO' if not provided.

get(): Promise<any[]>

Retrieves log entries for the current log identifier.

close(): void

Placeholder for any cleanup logic if needed in the future.

Recommendations

Avoid Blocking (await) Logging Calls

It is recommended not to use logging in a blocking manner (i.e., using await for logging calls). Logging operations should be non-blocking to prevent any potential delays in your application's main workflow. Instead, consider logging asynchronously without waiting for the logging operation to complete.

Using await with logging can introduce unnecessary latency, especially in high-throughput scenarios or when handling a large volume of logs. By allowing the logging operations to proceed in the background, you can maintain the responsiveness and performance of your application.

Example:

import Logger from '@beyond-js/logs';

const logger = new Logger('your-log-identifier');

// Non-blocking log entry
logger.add('This is a log message', 'INFO').catch(err => {
	console.error('Error writing log:', err);
});

// Continue with other operations without waiting for the log to complete

By following this recommendation, you can ensure that logging does not interfere with the primary operations of your application, leading to better performance and reliability.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

Support

If you have any questions or need help, feel free to open an issue on GitHub or contact the maintainers.


This package leverages the power of Google Cloud Logging to help you manage and analyze logs effectively. Whether you are developing locally or deploying to production, @beyond-js/logs provides a seamless and reliable logging solution.