1.0.16 • Published 10 months ago

@everlog/core v1.0.16

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

Everlog


CircleCI npm version


Overview

This repository contains a lightweight and optimized logging library, specifically designed for both NodeJS and browser environments. The library is rewritten to offer support for both UMD and ESM modules, ensuring compatibility across a wide range of projects.

Note: "I have rewritten the library to support UMD and ESM modules for NodeJS and Browser, and to include only necessary functions for logging, without viewer and CLI capabilities. Those should be later available via additional modules."

The goal of this project is to provide essential logging functionality with minimal overhead, keeping it simple and modular. Future development will extend this functionality via separate viewer and CLI packages.

Features

  • UMD & ESM Support: Fully compatible with modern module systems for seamless integration into different environments.
  • Lightweight: Includes only the core functionality required for logging, keeping the package size minimal.
  • NodeJS and Browser Support: Works efficiently in both server and client-side environments.
  • Filesystem Logging for NodeJS:
    • Asynchronous and Efficient: Supports asynchronous logging to minimize performance overhead.
    • Buffering: Logs are buffered and written to the filesystem in batches to optimize I/O operations.
    • File Retention: Automatic file retention management ensures older log files are archived or deleted based on configured retention policies.
    • Thread Safety: Ensures thread-safe logging, preventing race conditions in multi-threaded environments or concurrent logging scenarios.
  • Structured Logging with Channels: Enables predefined logging "channels" for organizing logs, each capable of exporting structured logs in CSV format for better data analysis.
  • Future Expandability: Viewer and CLI features are planned to be available through external modules.

Usage

  1. Initialize the Everlog
import { Everlog } from 'everlog'

await Everlog.initialize({
    directory: `./logs/`,
});
  1. Create Log Streams
const channel = Everlog.createChannel<[string, number, Date]>('foo', {
    loggers: [
        {
            name: 'fs',
            // Keep only last N files
            fileCountMax: 20,
            // Limit size for a file. When reached, next file is created
            fileBytesMax: 500 * 1024;
            // Limit message count for a file. When reached, next file is created
            fileMessagesMax: 10 ** 7

            // Buffer N messages
            messageBufferMax: 50;
            columns: [] as ICsvColumn[];

            // Flush logs, when no activity was for N milliseconds
            writeTimeout: null as number;
        },
    ],

    columns: [
        { name: 'Title', filterable: true },
        { name: 'MyVal', type: 'number', sortable: true, groupable: true },
        { name: 'Timestamp', type: 'date', sortable: true, groupable: true },
    ]
});

channel.log(`Lorem ipsum`, 123, new Date());

// On the application end flush the data (in case there is smth in the buffer)
await channel.flush();

🏁


©️ MIT License.

1.0.16

10 months ago

1.0.15

10 months ago

1.0.14

11 months ago

1.0.13

11 months ago

1.0.11

11 months ago