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

@bytehide/logger

v1.0.12

Published

The ByteHide Logger is a powerful and easy-to-use library that allows you to log information, warnings, and errors in your applications. It is designed to be simple to use and easy to integrate into your projects

Downloads

658

Readme

ByteHide.Logger SDK for JavaScript

ByteHide.Logger is a powerful and flexible logging library for JavaScript and TypeScript applications. It offers advanced features like enriched metadata logging, user identification, duplicate suppression, and more, ensuring a robust logging solution.

Installation

Install ByteHide.Logger using npm or yarn:

npm install @bytehide/logger
or with yarn:
yarn add @bytehide/logger

Features

  • Enriched Logging: Include tags, metadata, and correlation IDs.
  • Log Level Control: Configure the minimum log level to capture only relevant messages.
  • Duplicate Suppression: Avoid logging repetitive messages within a configurable time window.
  • Sensitive Data Protection: Mask sensitive information such as passwords or tokens.
  • User Identification: Associate logs with specific users.
  • Console and Persistence Integration: Log to the console or use custom integrations for storage.

Basic Usage

Initial Setup

Set up ByteHide.Logger with your desired logging settings:

import { Log } from "@bytehide/logger";

// Step 1: Configure the logger
Log.configure({
    minimumLevel: 'debug', // Capture logs from this level and above
    consoleEnabled: true, // Output logs to the console
    maskSensitiveData: ['password', 'token'], // Automatically mask these fields in logs
    duplicateSuppressionWindowMs: 1000, // Suppress duplicate logs within 1 second
});

// Step 2: Set the project token for log tracking
Log.setProjectToken('your-project-token');

Log.addMetaContext('AppVersion', '1.2.3');
Log.addMetaContext('Environment', 'Production');

// Step 3: Identify a user globally (optional)
Log.identify('john.doe', '[email protected]', 'abc123');
Log.info('User identification successful', { metadata: { email: '[email protected]' } });

// Step 4: Log messages with additional context
// Basic informational log
Log.info('Application started successfully.');

// Log with correlation ID to track related operations
const correlationId = '1234-abcd-5678-efgh';
Log.debug('Fetching user details', { correlationId, tags: ['service', 'user'] });

// Warning log with metadata
Log.warn('API rate limit reached', {
    correlationId,
    tags: ['api', 'rate-limit'],
    metadata: { userId: 'john.doe', endpoint: '/users/details' },
});

// Error log with critical context
Log.error('Failed to process user update', {
    tags: ['critical', 'update-failure'],
    correlationId,
    metadata: { userId: 'john.doe', operation: 'user.update' },
});

// Step 5: Handle exceptions gracefully
try {
    throw new Error('Test Error');
} catch (error) {
    Log.critical('An unhandled exception occurred', { tags: ['exception'] }, error);
}

// Step 6: Dynamically enable or disable logging
Log.disable();
Log.info('This log will not appear because logging is disabled.');
Log.enable();
Log.info('Logging is now enabled again.');

// Step 7: Suppress duplicate logs
Log.info("This log will be suppressed Start.");
Log.info("This log will be suppressed.");
Log.info("This log will be suppressed.");
Log.info("This log will be suppressed.");
Log.info("This log will be suppressed.");
Log.info("This log will be suppressed.");
Log.info("This log will be suppressed.");
Log.info("This log will be suppressed.");
Log.info("This log will be suppressed.");
Log.info("This log will be suppressed End.");

// Step 8: Log with context
Log.warn('Database query delay.', {tags: ['performance', 'database'], context: {query: 'SELECT * FROM users WHERE id = 1234'}});

// Optional: Demonstrate the masking of sensitive data
Log.info('Sensitive data example', {
    metadata: { password: 'my-secret-password', token: 'abc123' }, // These will be masked
});

// Step 8: Use custom log levels (if configured)
Log.debug('This is a debug message, useful for troubleshooting.');
Log.warn('This is a warning message, indicating potential issues.');
Log.error('This is an error message, reporting failures.');

console.log('Logger setup and example complete.');

Advanced Features

Global Properties

Enrich logs with global properties that are included in every log entry:

Log.addMetaContext('AppVersion', '1.2.3');
Log.addMetaContext('Environment', 'Production');

Correlation IDs

Track operations using correlation IDs:

Log.debug('Processing payment', { correlationId: 'operation-123' });

Log Configuration

Reset the configuration to default values easily:

Log.reset();

License

ByteHide.Logger is licensed under the MIT License.


Happy coding but keep it safe with @bytehide/logger! 🛡️