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

l4js

v1.0.0

Published

Tiny but Impressive Logging for Modern JavaScript Applications

Downloads

15

Readme

L4js (Logging For JavaScript) Intro

l4js is a lightweight, user-friendly logging utility designed to simplify the logging process for JavaScript and Node.js applications. Unlike other npm logging packages, l4js focuses on ease of use, reusability, and a streamlined "create once, use everywhere" pattern. With l4js, there's no need for complex instantiation or configuration—just quick, intuitive logging that gets out of your way.

Key features include:

  • Small and Lightweight: Minimal footprint with no unnecessary dependencies.
  • Easy to Use: Simple setup and straightforward API, perfect for developers of all experience levels.
  • Reusable: Design once, and reuse your logger configuration across your entire project.
  • No Complex Instantiation: Say goodbye to cumbersome configuration; l4js gets you logging instantly.
  • l4js is the perfect tool for developers seeking a hassle-free logging solution that just works.

Quick Start

Getting Started is easy and quick !

install l4js

$ npm install l4js@latest

Simple Logging Examples

Import The Library into project or app.


/* Import l4js into your Application */
let {L4js} = require("L4js");

Create an options or configuration Object


let options = {
        dateFormat:"",     // A Date Format Default is "yyyy-MM-dd"
        filePath:"",       // The File path where the log file file should be placed if logging to file is enabled 
        logLevel:"*",      // The Log Level Default is * (Supports All Levels). you can choose info|warn|error|debug
        logToFile: false,  // boolean flag to enable or disable logging to a file default is false
        fileName: null,    // Your desired log filename if logging to file is enabled Default is "l4js.yyyy-MM-dd.log"
        batchSize: 0,      // Log Queue Batch size (default is 0)  
        flushInterval: 0   // The Log Queue flush interval to clear and write logs from a log queue 
} 

Initialize the Logger

let logger = L4js.initialize(options) 

Log a Simple Info Message

logger.info("This is a Info Message");

Log a Warning Message

logger.warn("This is a Warning Message");

Log A Error Message

logger.error(new Error("I messed up Something"));

Log a Debug Message

logger.debug("This is a Debug Message, In some app.. What is going on? ");

Example Log Output:


# INFO Message 
2024-08-23 INFO (60103) "This is a Info Message"

# WARN Message
2024-08-23 WARN (60103) "This is a Warning Message"

# ERROR Message
2024-08-23 ERROR (60103)
["Error","I messed up Something","Error: I messed up Something\n    at Object.<anonymous> l4js/test/index.js:14:14)\n    at Module._compile (node:internal/modules/cjs/loader:1358:14)\n    at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)\n    at Module.load (node:internal/modules/cjs/loader:1208:32)\n    at Module._load (node:internal/modules/cjs/loader:1024:12)\n    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12)\n    at node:internal/main/run_main_module:28:49"]

# DEBUG Message
2024-08-23 DEBUG (60103) "This is a Debug Message, In some app.. What is going on? "

Options

There are couple of options you can provide when you instantiate a l4js instance

| name | description | | :------------ | :------------------------------------------------------------------------------------------- | | dateFormat | A Date Format Default is "yyyy-MM-dd" | | filePath | The File path where the log file file should be placed if logging to file is enabled | | logLevel | The Log Level Default is * (Supports All Levels). you can choose info|warn|error|debug | | logToFile | boolean flag to enable or disable logging to a file default is false | | fileName | Your desired log filename if logging to file is enabled Default is "l4js.yyyy-MM-dd.log" | | batchSize | Log Queue Batch size (default is 0) | | flushInterval | The Log Queue flush interval to clear and write logs from a log queue |

File Writes

Writing logs to file is a common use case with l4js it very easy to start logging your precious content to a file.

whenever you instantiate or create a new l4js object make sure you set the logToFile alway to true if you would like to log content to a given file.

l4js can either name the name file for you by using the default log file name l4js.yyyy-MM-dd.log or you van choose another name by providing your custom file name to with fileName parameter!

l4js provides 2 file Logging Strategies

  1. Write the Log immediately to file with every info(), warn(), error(), debug() invocation
  2. Store Logs in a Log Queue with a predefined size allocated once it exceed the the predefined size batchSize the queue is Flushed and written to log file.
  3. Flush the Queue at intervals flushInterval sometime its nice to not worry about anything if you provide a flushInterval (A interval in milliseconds) l4js will periodically check the LogQueue and flush it writing all Queue content to the given file.

Donations Welcome

Bitcoin address: bc1qs6rvwnx0wlrqlncm90kk7mu0xs6980t85avfll Ethereum address: 0x088667d218f5E5c4560cdcf21c4bd2b2377Df0C9