Skip to content

Commit ed66134

Browse files
authored
🚀 release: v1.2.0 merge pull request #3 from wgtechlabs/dev
2 parents 34db06c + 680ac10 commit ed66134

File tree

12 files changed

+648
-146
lines changed

12 files changed

+648
-146
lines changed

README.md

Lines changed: 127 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Log Engine transforms your development experience from chaotic debugging session
1919
- **Lightweight & Fast**: Minimal overhead with maximum performance - designed to enhance your application, not slow it down.
2020
- **No Learning Curve**: Dead simple API that you can master in seconds. No extensive documentation, complex configurations, or setup required - Log Engine works instantly.
2121
- **Colorized Console Output**: Beautiful ANSI color-coded log levels with intelligent terminal formatting - instantly identify message severity at a glance with color-coded output.
22-
- **Multiple Log Levels**: Support for DEBUG, INFO, WARN, ERROR, and SILENT levels with smart filtering - just set your level and let it handle the rest.
22+
- **Multiple Log Modes**: Support for DEBUG, INFO, WARN, ERROR, SILENT, OFF, and special LOG levels with smart filtering - just set your mode and let it handle the rest.
2323
- **Auto-Configuration**: Intelligent environment-based setup using NODE_ENV variables. No config files, initialization scripts, or manual setup - Log Engine works perfectly out of the box.
2424
- **Enhanced Formatting**: Structured log entries with dual timestamps (ISO + human-readable) and colored level indicators for maximum readability.
2525
- **TypeScript Ready**: Full TypeScript support with comprehensive type definitions for a seamless development experience.
@@ -70,38 +70,84 @@ yarn add @wgtechlabs/log-engine
7070
### Quick Start
7171

7272
```typescript
73-
import { LogEngine, LogLevel } from '@wgtechlabs/log-engine';
73+
import { LogEngine, LogMode } from '@wgtechlabs/log-engine';
7474

7575
// Basic usage with auto-configuration based on NODE_ENV
7676
LogEngine.debug('This is a debug message');
7777
LogEngine.info('This is an info message');
7878
LogEngine.warn('This is a warning message');
7979
LogEngine.error('This is an error message');
80+
LogEngine.log('This is a critical message that always shows');
8081
```
8182

82-
### Custom Configuration
83+
### Mode-Based Configuration (Recommended)
84+
85+
Log Engine now uses a modern **LogMode** system that separates message severity from output control:
8386

8487
```typescript
85-
import { LogEngine, LogLevel } from '@wgtechlabs/log-engine';
88+
import { LogEngine, LogMode } from '@wgtechlabs/log-engine';
8689

87-
// Configure based on your custom environment variable
88-
const env = process.env.APP_ENV || 'development';
90+
// Configure using LogMode (recommended approach)
91+
LogEngine.configure({ mode: LogMode.DEBUG }); // Most verbose
92+
LogEngine.configure({ mode: LogMode.INFO }); // Balanced
93+
LogEngine.configure({ mode: LogMode.WARN }); // Focused
94+
LogEngine.configure({ mode: LogMode.ERROR }); // Minimal
95+
LogEngine.configure({ mode: LogMode.SILENT }); // Critical only
96+
LogEngine.configure({ mode: LogMode.OFF }); // Complete silence
97+
98+
// Environment-based configuration example
99+
const env = process.env.NODE_ENV || 'development';
89100

90101
if (env === 'production') {
91-
LogEngine.configure({ level: LogLevel.ERROR });
102+
LogEngine.configure({ mode: LogMode.INFO });
92103
} else if (env === 'staging') {
93-
LogEngine.configure({ level: LogLevel.WARN });
104+
LogEngine.configure({ mode: LogMode.WARN });
94105
} else {
95-
LogEngine.configure({ level: LogLevel.DEBUG });
106+
LogEngine.configure({ mode: LogMode.DEBUG });
96107
}
97108

98-
// Now use Log Engine - only messages at or above the configured level will be shown
99-
LogEngine.debug('This will only show in development');
109+
// Now use Log Engine - only messages appropriate for the mode will be shown
110+
LogEngine.debug('This will only show in DEBUG mode');
100111
LogEngine.info('General information');
101112
LogEngine.warn('Warning message');
102113
LogEngine.error('Error message');
114+
LogEngine.log('Critical message that always shows');
115+
```
116+
117+
### Legacy Level-Based Configuration (Backwards Compatible)
118+
119+
For backwards compatibility, the old `LogLevel` API is still supported:
120+
121+
```typescript
122+
import { LogEngine, LogLevel } from '@wgtechlabs/log-engine';
123+
124+
// Legacy configuration (still works but LogMode is recommended)
125+
LogEngine.configure({ level: LogLevel.DEBUG });
126+
LogEngine.configure({ level: LogLevel.INFO });
127+
LogEngine.configure({ level: LogLevel.WARN });
128+
LogEngine.configure({ level: LogLevel.ERROR });
129+
```
130+
131+
### Migration Guide: LogLevel → LogMode
132+
133+
**Version 1.2.0+** introduces the new LogMode system for better separation of concerns. Here's how to migrate:
134+
135+
```typescript
136+
// OLD (v1.1.0 and earlier) - still works but deprecated
137+
import { LogEngine, LogLevel } from '@wgtechlabs/log-engine';
138+
LogEngine.configure({ level: LogLevel.DEBUG });
139+
140+
// NEW (v1.2.0+) - recommended approach
141+
import { LogEngine, LogMode } from '@wgtechlabs/log-engine';
142+
LogEngine.configure({ mode: LogMode.DEBUG });
103143
```
104144

145+
**Key Benefits of LogMode:**
146+
- **Clearer API**: Separates message severity (`LogLevel`) from output control (`LogMode`)
147+
- **Better Environment Defaults**: `development→DEBUG`, `staging→WARN`, `test→ERROR`
148+
- **Future-Proof**: New features will use the LogMode system
149+
- **100% Backwards Compatible**: Existing code continues to work unchanged
150+
105151
### Color-Coded Output 🎨
106152

107153
Log Engine now features beautiful, color-coded console output that makes debugging and monitoring a breeze:
@@ -114,6 +160,7 @@ LogEngine.debug('🔍 Debugging user authentication flow'); // Purple/Magenta
114160
LogEngine.info('ℹ️ User successfully logged in'); // Blue
115161
LogEngine.warn('⚠️ API rate limit at 80% capacity'); // Yellow
116162
LogEngine.error('❌ Database connection timeout'); // Red
163+
LogEngine.log('🚀 Application started successfully'); // Green
117164
```
118165

119166
**Why Colors Matter:**
@@ -123,24 +170,84 @@ LogEngine.error('❌ Database connection timeout'); // Red
123170
- **Production Monitoring**: Easily scan logs for critical issues in terminal environments
124171
- **Enhanced Readability**: Color-coded timestamps and level indicators reduce eye strain
125172

126-
### Log Levels
173+
### Log Modes
174+
175+
Log Engine uses a **LogMode** system that controls output verbosity and filtering:
127176

128-
Log Engine supports the following levels (in order of severity):
177+
- `LogMode.DEBUG` (0) - Most verbose: shows DEBUG, INFO, WARN, ERROR, LOG messages
178+
- `LogMode.INFO` (1) - Balanced: shows INFO, WARN, ERROR, LOG messages
179+
- `LogMode.WARN` (2) - Focused: shows WARN, ERROR, LOG messages
180+
- `LogMode.ERROR` (3) - Minimal: shows ERROR, LOG messages
181+
- `LogMode.SILENT` (4) - Critical only: shows LOG messages only
182+
- `LogMode.OFF` (5) - Complete silence: shows no messages at all
183+
184+
### Message Severity Levels
185+
186+
Individual log messages have severity levels that determine their importance:
129187

130188
- `LogLevel.DEBUG` (0) - Detailed information for debugging
131189
- `LogLevel.INFO` (1) - General information
132190
- `LogLevel.WARN` (2) - Warning messages
133191
- `LogLevel.ERROR` (3) - Error messages
134-
- `LogLevel.SILENT` (4) - No output
192+
- `LogLevel.LOG` (99) - Critical messages that always show (except when OFF mode is set)
135193

136194
### Auto-Configuration
137195

138196
Log Engine automatically configures itself based on the `NODE_ENV` environment variable:
139197

140-
- `production``LogLevel.WARN`
141-
- `development``LogLevel.DEBUG`
142-
- `test``LogLevel.ERROR`
143-
- `default``LogLevel.INFO`
198+
- `development``LogMode.DEBUG` (most verbose)
199+
- `production``LogMode.INFO` (balanced)
200+
- `staging``LogMode.WARN` (focused)
201+
- `test``LogMode.ERROR` (minimal)
202+
- `default``LogMode.INFO` (balanced)
203+
204+
### Special LOG Level
205+
206+
The `LOG` level is special and behaves differently from other levels:
207+
208+
- **Always Visible**: LOG messages are always displayed regardless of the configured log mode (except when OFF mode is set)
209+
- **Critical Information**: Perfect for essential system messages, application lifecycle events, and operational information that must never be filtered out
210+
- **Green Color**: Uses green coloring to distinguish it from other levels
211+
- **Use Cases**: Application startup/shutdown, server listening notifications, critical configuration changes, deployment information
212+
213+
```typescript
214+
import { LogEngine, LogMode } from '@wgtechlabs/log-engine';
215+
216+
// Even with SILENT mode, LOG messages still appear
217+
LogEngine.configure({ mode: LogMode.SILENT });
218+
219+
LogEngine.debug('Debug message'); // Hidden
220+
LogEngine.info('Info message'); // Hidden
221+
LogEngine.warn('Warning message'); // Hidden
222+
LogEngine.error('Error message'); // Hidden
223+
LogEngine.log('Server started on port 3000'); // ✅ Always visible!
224+
225+
// But with OFF mode, even LOG messages are hidden
226+
LogEngine.configure({ mode: LogMode.OFF });
227+
LogEngine.log('This LOG message is hidden'); // ❌ Hidden with OFF mode
228+
```
229+
230+
### Complete Silence with OFF Mode
231+
232+
The `OFF` mode provides complete logging silence when you need to disable all output:
233+
234+
- **Total Silence**: Disables ALL logging including the special LOG level messages
235+
- **Testing & CI/CD**: Perfect for automated testing environments where no console output is desired
236+
- **Performance**: Minimal overhead when logging is completely disabled
237+
- **Use Cases**: Unit tests, CI/CD pipelines, production environments requiring zero log output
238+
239+
```typescript
240+
import { LogEngine, LogMode } from '@wgtechlabs/log-engine';
241+
242+
// Comparison: SILENT vs OFF
243+
LogEngine.configure({ mode: LogMode.SILENT });
244+
LogEngine.info('Info message'); // Hidden
245+
LogEngine.log('Critical message'); // ✅ Still visible with SILENT
246+
247+
LogEngine.configure({ mode: LogMode.OFF });
248+
LogEngine.info('Info message'); // Hidden
249+
LogEngine.log('Critical message'); // ❌ Hidden with OFF - complete silence!
250+
```
144251

145252
### Log Format
146253

@@ -152,6 +259,7 @@ Log messages are beautifully formatted with colorized timestamps, levels, and sm
152259
[2025-05-29T16:57:46.123Z][4:57 PM][INFO]: Server started successfully
153260
[2025-05-29T16:57:47.456Z][4:57 PM][WARN]: API rate limit approaching
154261
[2025-05-29T16:57:48.789Z][4:57 PM][ERROR]: Database connection failed
262+
[2025-05-29T16:57:49.012Z][4:57 PM][LOG]: Application startup complete
155263
```
156264

157265
**Color Scheme:**
@@ -160,6 +268,7 @@ Log messages are beautifully formatted with colorized timestamps, levels, and sm
160268
- 🔵 **INFO**: Blue - General informational messages
161269
- 🟡 **WARN**: Yellow - Warning messages that need attention
162270
- 🔴 **ERROR**: Red - Error messages requiring immediate action
271+
- 🟢 **LOG**: Green - Critical messages that always display
163272
-**Timestamps**: Gray (ISO) and Cyan (local time) for easy scanning
164273

165274
## 💬 Community Discussions

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@wgtechlabs/log-engine",
3-
"version": "1.0.3",
3+
"version": "1.2.0",
44
"description": "A lightweight and efficient logging utility designed specifically for bot applications running on Node.js.",
55
"keywords": [
66
"logging",

src/__tests__/environment.test.ts

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Tests for environment-based auto-configuration
3-
* Verifies that LogEngine automatically sets appropriate log levels based on NODE_ENV
3+
* Verifies that LogEngine automatically sets appropriate log modes based on NODE_ENV
44
*/
55

66
import { setupConsoleMocks, restoreConsoleMocks, ConsoleMocks } from './test-utils';
@@ -20,23 +20,27 @@ describe('Environment-based configuration', () => {
2020
restoreConsoleMocks(mocks);
2121
});
2222

23-
it('should set WARN level for production environment', () => {
24-
// Test production environment auto-configuration (reduce noise in production)
23+
it('should set INFO mode for production environment', () => {
24+
// Test production environment auto-configuration (show important info and above)
2525
process.env.NODE_ENV = 'production';
2626

2727
// Re-import to trigger fresh environment-based configuration
2828
jest.resetModules();
2929
const { LogEngine: ProdLogEngine } = require('../index');
3030

31+
ProdLogEngine.debug('Debug message');
3132
ProdLogEngine.info('Info message');
3233
ProdLogEngine.warn('Warning message');
3334

34-
// INFO should be filtered, only WARN and above should show
35-
expect(mocks.mockConsoleLog).not.toHaveBeenCalled();
35+
// DEBUG should be filtered, INFO and above should show
36+
expect(mocks.mockConsoleLog).toHaveBeenCalledTimes(1);
37+
expect(mocks.mockConsoleLog).toHaveBeenCalledWith(
38+
expect.stringContaining('Info message')
39+
);
3640
expect(mocks.mockConsoleWarn).toHaveBeenCalledTimes(1);
3741
});
3842

39-
it('should set DEBUG level for development environment', () => {
43+
it('should set DEBUG mode for development environment', () => {
4044
// Test development environment auto-configuration (verbose logging for debugging)
4145
process.env.NODE_ENV = 'development';
4246

@@ -51,7 +55,23 @@ describe('Environment-based configuration', () => {
5155
);
5256
});
5357

54-
it('should set ERROR level for test environment', () => {
58+
it('should set WARN mode for staging environment', () => {
59+
// Test staging environment auto-configuration (focused logging)
60+
process.env.NODE_ENV = 'staging';
61+
62+
jest.resetModules();
63+
const { LogEngine: StagingLogEngine } = require('../index');
64+
65+
StagingLogEngine.debug('Debug message');
66+
StagingLogEngine.info('Info message');
67+
StagingLogEngine.warn('Warning message');
68+
69+
// Only WARN and above should show in staging
70+
expect(mocks.mockConsoleLog).not.toHaveBeenCalled();
71+
expect(mocks.mockConsoleWarn).toHaveBeenCalledTimes(1);
72+
});
73+
74+
it('should set ERROR mode for test environment', () => {
5575
// Test environment auto-configuration (minimal logging during tests)
5676
process.env.NODE_ENV = 'test';
5777

@@ -66,7 +86,7 @@ describe('Environment-based configuration', () => {
6686
expect(mocks.mockConsoleError).toHaveBeenCalledTimes(1);
6787
});
6888

69-
it('should set INFO level for unknown environments', () => {
89+
it('should set INFO mode for unknown environments', () => {
7090
// Test fallback behavior for unrecognized NODE_ENV values
7191
process.env.NODE_ENV = 'unknown';
7292

@@ -76,14 +96,14 @@ describe('Environment-based configuration', () => {
7696
UnknownLogEngine.debug('Debug message');
7797
UnknownLogEngine.info('Info message');
7898

79-
// Should default to INFO level (DEBUG filtered, INFO shown)
99+
// Should default to INFO mode (DEBUG filtered, INFO shown)
80100
expect(mocks.mockConsoleLog).toHaveBeenCalledTimes(1);
81101
expect(mocks.mockConsoleLog).toHaveBeenCalledWith(
82102
expect.stringContaining('Info message')
83103
);
84104
});
85105

86-
it('should set INFO level when NODE_ENV is undefined', () => {
106+
it('should set INFO mode when NODE_ENV is undefined', () => {
87107
// Test fallback behavior when NODE_ENV is not set at all
88108
delete process.env.NODE_ENV;
89109

@@ -93,7 +113,7 @@ describe('Environment-based configuration', () => {
93113
DefaultLogEngine.debug('Debug message');
94114
DefaultLogEngine.info('Info message');
95115

96-
// Should default to INFO level when NODE_ENV is undefined
116+
// Should default to INFO mode when NODE_ENV is undefined
97117
expect(mocks.mockConsoleLog).toHaveBeenCalledTimes(1);
98118
expect(mocks.mockConsoleLog).toHaveBeenCalledWith(
99119
expect.stringContaining('Info message')

0 commit comments

Comments
 (0)