A lightweight, hierarchical logging library for Node.js with configurable log levels and tag-based organization. TimberJ provides a clean, builder-pattern API for structured logging with automatic level filtering.
- π― Configurable Log Levels: 6 different log levels (DEBUG, LOG, INFO, WARN, ERROR, NOT_PLANTED)
- π·οΈ Tag-based Organization: Organize logs with meaningful tags for better debugging
- π± Plant & Grow Pattern: Initialize once, use everywhere with automatic level inheritance
- π Zero Dependencies: Lightweight with no external dependencies
- π TypeScript Support: Full TypeScript support with type definitions
- π§ Builder Pattern: Fluent API for easy configuration
npm install timberjimport { TimberJ, LEVEL_I } from 'timberj';
// Plant TimberJ with your desired log level
TimberJ.plant(LEVEL_I);
// Use it with tags
TimberJ.tag('UserService').i('User logged in successfully');
TimberJ.tag('Database').w('Connection timeout, retrying...');
TimberJ.tag('API').e('Failed to fetch user data');TimberJ supports 6 log levels, each with a specific priority:
| Level | Constant | Priority | Description |
|---|---|---|---|
| DEBUG | LEVEL_D |
0 | Most verbose, shows all logs |
| LOG | LEVEL_L |
1 | Standard logging level |
| INFO | LEVEL_I |
2 | Informational messages |
| WARN | LEVEL_W |
3 | Warning messages |
| ERROR | LEVEL_E |
4 | Error messages only |
| NOT_PLANTED | LEVEL_NOT_PLANTED |
5 | Default state, no logs shown |
Important: Logs are shown based on priority - setting a level will show all logs of that level and higher priority.
Initialize TimberJ with a specific log level. This must be called before using any logging methods.
import { TimberJ, LEVEL_I } from 'timberj';
// Initialize with INFO level
TimberJ.plant(LEVEL_I);Create a new logger instance with a specific tag. Returns a builder object with logging methods.
const logger = TimberJ.tag('MyService');The builder object provides the following logging methods:
.d(message: string)- Debug logging.l(message: string)- Standard logging.i(message: string)- Info logging.w(message: string)- Warning logging.e(message: string)- Error logging
Each method automatically includes the tag and respects the configured log level.
import { TimberJ, LEVEL_D } from 'timberj';
// Initialize with DEBUG level (shows all logs)
TimberJ.plant(LEVEL_D);
// Simple logging
TimberJ.tag('App').i('Application started');
TimberJ.tag('Database').d('Connecting to database...');
TimberJ.tag('API').w('Rate limit approaching');
TimberJ.tag('Error').e('Failed to process request');import { TimberJ, LEVEL_I } from 'timberj';
class UserService {
private logger = TimberJ.tag('UserService');
async createUser(userData: any) {
this.logger.i('Creating new user');
try {
// ... user creation logic
this.logger.i('User created successfully');
} catch (error) {
this.logger.e(`Failed to create user: ${error.message}`);
throw error;
}
}
async getUser(id: string) {
this.logger.d(`Fetching user with ID: ${id}`);
// ... user fetching logic
this.logger.i('User retrieved successfully');
}
}import { TimberJ, LEVEL_D, LEVEL_W } from 'timberj';
// Configure based on environment
const logLevel = process.env.NODE_ENV === 'development' ? LEVEL_D : LEVEL_W;
TimberJ.plant(logLevel);
// In development: all logs shown
// In production: only warnings and errors shownimport { TimberJ, LEVEL_I } from 'timberJ';
TimberJ.plant(LEVEL_I);
// Chain multiple operations
TimberJ.tag('Auth')
.setTag('UserLogin')
.i('User authentication started');
TimberJ.tag('Database')
.setTag('Connection')
.w('Connection pool running low');- Plant Early: Always call
TimberJ.plant()at the start of your application - Use Meaningful Tags: Create tags that clearly identify the source of logs
- Choose Appropriate Levels: Use DEBUG for development, INFO for production
- Consistent Tagging: Use consistent tag patterns across your application
- Error Context: Always log errors with sufficient context for debugging
npm run buildnpm testnpm run lint- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
MIT License - see LICENSE file for details.
- Initial release
- Core logging functionality
- Tag-based organization
- Configurable log levels
- TypeScript support
TimberJ - Because every good forest needs a logger! π²π
I am inspired by Timber, which is a light weight logger created by Kotlin.