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

gelf-simple-js-logger

v1.0.2

Published

gelf-simple-js-logger is a simple logger that sends logs to Graylog using the GELF (Graylog Extended Log Format) protocol and console. This package allows you to configure the logger to send logs via UDP or TCP.

Downloads

17

Readme

gelf-simple-js-logger

Description

gelf-simple-js-logger is a simple logger that sends logs to Graylog using the GELF (Graylog Extended Log Format) protocol and console. This package allows you to configure the logger to send logs via UDP or TCP.

Installation

To install the package, use npm:

npm install gelf-simple-js-logger

Usage

  1. Create a configuration file: Create a file named logger-config.js with the following content or use this environment variables on run:

// logger-config.js
module.exports = {
    GRAYLOG_HOST: '127.0.0.1', // Replace with your Graylog server address
    GRAYLOG_TRANSPORT: 'udp', // or 'tcp'
    GRAYLOG_PORT: 12201,
    GRAYLOG_APPLICATION_NAME: 'my_app',
    GRAYLOG_ENVIRONMENT: 'development',
    GRAYLOG_MIN_LEVEL_LOCAL: 'debug',
    GRAYLOG_MIN_LEVEL_REMOTE: 'info',
    GRAYLOG_OUTPUT: 'both' // both, local or remote
};
  • If you prefer, you can provide these variables as environment variables instead of creating this file.

2.Use the logger in your project: Import and use the logger in your project files.

// test.js
const createLogger = require('gelf-simple-js-logger');
const customConfig = require('./logger-config');

const logger = createLogger(customConfig);

// Send messages to Graylog and Console
logger.debug({ message: 'Information log test', additional: 'debug log', product: 'test' });
logger.info({ message: 'Information log test', additional: 'info log', product: 'test' });
logger.warn({ message: 'Information log test', additional: 'warning log', product: 'test' });
logger.error({ message: 'Information log test', additional: 'error log', product: 'test' });
logger.critical({ message: 'Information log test', additional: 'critical log', product: 'test' });

logger.info({ message: 'Information log test' });

No value is required. But it is recommended to send the message and/or full_message values. Any other value sent becomes additional fields on the Graylog Server, in addition to the fields that are already sent by default:

  • host (get by function os.hostname())
  • short_message (get by message field or if null 'No message')
  • full_message (get by full_message field or equals message field)
  • level (get by function - debug, info, warn, error or critical)
  • application_name (get by ENV GRAYLOG_APPLICATION_NAME )
  • environment (get by ENV GRAYLOG_ENVIRONMENT)
  • remote_addr (get public IP via https://checkip.amazonaws.com)
  • timestamp (get by new Date().toISOString() command)

3.Run your project: Execute your project to see the logs being sent to Graylog.

node --expose-gc test.js

Configuration Options

  • GRAYLOG_HOST: The address of your Graylog server.
  • GRAYLOG_TRANSPORT: The transport protocol to use (udp, tcp, or http).
  • GRAYLOG_PORT: The port on which Graylog is listening.
  • GRAYLOG_APPLICATION_NAME: The name of your application.
  • GRAYLOG_ENVIRONMENT: The environment (e.g., development, production).
  • GRAYLOG_MIN_LEVEL_LOCAL: The minimum log level for local logging.
  • GRAYLOG_MIN_LEVEL_REMOTE: The minimum log level for remote logging.
  • GRAYLOG_OUTPUT: Where to output logs (console, graylog, or both).