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 🙏

© 2025 – Pkg Stats / Ryan Hefner

logger-fluent

v1.0.1

Published

A flexible file logging library with TypeScript support, featuring log rotation, multiple log levels, and automatic directory creation

Readme

Logger Fluent

This directory contains example scripts that demonstrate how to use the logger-fluent npm library after it has been built.

Prerequisites

Before running any examples, make sure to:

  1. Build the library first:

    npm run build
  2. Install dependencies (if not already done):

    npm install

Available Examples

1. Basic JavaScript Usage (basic-usage.js)

A comprehensive JavaScript example that demonstrates:

  • Default logger usage
  • Custom logger configuration
  • All log levels (debug, info, warn, error)
  • Log level filtering
  • Metadata logging
  • Proper logger cleanup

To run:

node examples/basic-usage.js

Output directories:

  • ./logs/ - Default logger output
  • ./temp/ - Custom logger output
  • ./temp/warn-only/ - Log level filtering example

2. Multi-Type Logging (multi-type-usage.js)

NEW! Demonstrates the enhanced multi-type logging capabilities:

  • Console-only logging
  • File-only logging (default behavior)
  • Combined console + file logging
  • Backward compatibility with createFileLogger
  • New utility methods (getLoggerTypes(), hasLoggerType())

To run:

node examples/multi-type-usage.js

Output directories:

  • ./temp-multi/file-only/ - File-only logger output
  • ./temp-multi/combined/ - Combined logger file output (also shows in console)
  • ./temp-multi/legacy/ - Backward compatibility test
  • ./temp-multi/default/ - Default behavior test

3. TypeScript Usage (typescript-usage.ts)

A TypeScript example showcasing:

  • Full type safety with logger options
  • Typed metadata interfaces
  • Multiple specialized loggers
  • Advanced configuration patterns
  • IntelliSense support

To run with ts-node:

# Install ts-node globally if not already installed
npm install -g ts-node

# Run the TypeScript example
ts-node examples/typescript-usage.ts

Alternative - Compile and run:

# Compile TypeScript to JavaScript
npx tsc examples/typescript-usage.ts

# Run the compiled JavaScript
node examples/typescript-usage.js

Output directories:

  • ./logs/ - Default logger output
  • ./temp-ts/ - Main TypeScript example output
  • ./temp-ts/api/ - API logger output
  • ./temp-ts/database/ - Database logger output
  • ./temp-ts/security/ - Security logger output

What the Examples Demonstrate

Core Features

  • ✅ File logging with automatic directory creation
  • ✅ Log rotation (daily rotation with size limits)
  • ✅ Multiple log levels (debug, info, warn, error)
  • ✅ Separate error log files
  • ✅ Custom log directories
  • ✅ Metadata logging (structured data)
  • ✅ Log level filtering
  • ✅ Proper resource cleanup

Configuration Options

  • type - NEW! Output type(s): 'console', 'file', or ['console', 'file'] (default: 'file')
  • logDir - Custom log directory path
  • logLevel - Minimum log level to write
  • maxSize - Maximum file size before rotation
  • maxFiles - How long to keep old log files
  • datePattern - Date pattern for file rotation
  • separateErrorLogs - Whether to create separate error files

TypeScript Benefits

  • Full type safety for all logger methods
  • IntelliSense support in your IDE
  • Compile-time error checking
  • Better refactoring capabilities

Expected Output

After running the examples, you should see:

  1. Console output showing the progress of each test
  2. Log files created in the specified directories
  3. Formatted log entries with timestamps and levels

Sample Log File Content

[2024-01-15 10:30:45.123] INFO: General information about application flow
[2024-01-15 10:30:45.124] WARN: Something unexpected happened
[2024-01-15 10:30:45.125] ERROR: Something went wrong

Troubleshooting

Common Issues

  1. "Cannot find module '../lib/index'"

    • Make sure you've built the library first: npm run build
    • Check that the lib/ directory exists and contains the compiled files
  2. Permission errors when creating directories

    • Ensure you have write permissions in the project directory
    • The examples will attempt to create fallback directories if needed
  3. TypeScript compilation errors

    • Make sure TypeScript is installed: npm install -g typescript
    • Check that your TypeScript version is compatible (>= 4.0)
  4. No log files created

    • Check console output for error messages
    • Verify that the directories have write permissions
    • Log files may take a moment to appear due to buffering

Debugging Tips

  • Check the console output for detailed information about what's happening
  • Look for error messages that indicate configuration issues
  • Verify file permissions in the target directories
  • Use ls -la to check if log files were created with the correct timestamps

Integration with Your Project

To use logger-fluent in your own project:

// JavaScript
const {
  createLogger,
  createFileLogger,
  defaultLogger,
} = require('logger-fluent');

// TypeScript
import {
  createLogger,
  createFileLogger,
  defaultLogger,
  LoggerOptions,
} from 'logger-fluent';

// Create a console-only logger
const consoleLogger = createLogger({
  type: 'console',
  logLevel: 'debug',
});

// Create a combined console + file logger
const multiLogger = createLogger({
  type: ['console', 'file'],
  logDir: './my-app-logs',
  logLevel: 'info',
  maxSize: '50m',
  maxFiles: '30d',
});

// Create a file-only logger (backward compatible)
const fileLogger = createFileLogger({
  logDir: './my-app-logs',
  logLevel: 'info',
});

// Use the logger
multiLogger.info('Application started');
multiLogger.error('Something went wrong', { error: 'details here' });

// Check logger configuration
console.log('Logger types:', multiLogger.getLoggerTypes());
console.log('Has console output:', multiLogger.hasLoggerType('console'));
console.log('Has file output:', multiLogger.hasLoggerType('file'));

Next Steps

After running these examples:

  1. Examine the generated log files to understand the output format
  2. Try modifying the configuration options to see how they affect behavior
  3. Integrate the logger into your own applications
  4. Consider setting up log monitoring and analysis tools

For more information, check the main project README and API documentation.