@wgtechlabs/log-engine 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,12 +1,12 @@
1
- # Log Engine 📝 ![gitHub actions workflow status](https://img.shields.io/github/actions/workflow/status/wgtechlabs/log-engine/test.yml?branch=main&style=flat-square&logo=github&labelColor=181717&link=https%3A%2F%2Fgithub.com%2Fwgtechlabs%2Flog-engine%2Factions%2Fworkflows%2Ftest.yml) ![codecov](https://img.shields.io/codecov/c/github/wgtechlabs/log-engine?token=PWRJTBVKQ9&style=flat-square&logo=codecov&labelColor=181717&link=https%3A%2F%2Fcodecov.io%2Fgh%2Fwgtechlabs%2Flog-engine)
1
+ # Log Engine 📜🚂 [![made by](https://img.shields.io/badge/made%20by-WG%20Tech%20Labs-0060a0.svg?logo=github&longCache=true&labelColor=181717&style=flat-square)](https://github.com/wgtechlabs)
2
2
 
3
- [![made by](https://img.shields.io/badge/made%20by-WG%20Technology%20Labs-0060a0.svg?logo=github&longCache=true&labelColor=181717&style=flat-square)](https://github.com/wgtechlabs) [![sponsors](https://img.shields.io/badge/sponsor-%E2%9D%A4-%23db61a2.svg?&logo=github&logoColor=white&labelColor=181717&style=flat-square)](https://github.com/sponsors/wgtechlabs) [![release](https://img.shields.io/github/release/wgtechlabs/log-engine.svg?logo=github&labelColor=181717&color=green&style=flat-square)](https://github.com/wgtechlabs/log-engine/releases) [![star](https://img.shields.io/github/stars/wgtechlabs/log-engine.svg?&logo=github&labelColor=181717&color=yellow&style=flat-square)](https://github.com/wgtechlabs/log-engine/stargazers) [![license](https://img.shields.io/github/license/wgtechlabs/log-engine.svg?&logo=github&labelColor=181717&style=flat-square)](https://github.com/wgtechlabs/log-engine/blob/main/license)
3
+ [![github actions workflow status](https://img.shields.io/github/actions/workflow/status/wgtechlabs/log-engine/test.yml?branch=main&style=flat-square&logo=github&labelColor=181717)](https://github.com/wgtechlabs/log-engine/actions/workflows/test.yml) [![codecov](https://img.shields.io/codecov/c/github/wgtechlabs/log-engine?token=PWRJTBVKQ9&style=flat-square&logo=codecov&labelColor=181717)](https://codecov.io/gh/wgtechlabs/log-engine) [![npm downloads](https://img.shields.io/npm/d18m/%40wgtechlabs%2Flog-engine?style=flat-square&logo=npm&label=installs&labelColor=181717&color=%23CD0000)](https://www.npmjs.com/package/@wgtechlabs/log-engine) [![sponsors](https://img.shields.io/badge/sponsor-%E2%9D%A4-%23db61a2.svg?&logo=github&logoColor=white&labelColor=181717&style=flat-square)](https://github.com/sponsors/wgtechlabs) [![release](https://img.shields.io/github/release/wgtechlabs/log-engine.svg?logo=github&labelColor=181717&color=green&style=flat-square)](https://github.com/wgtechlabs/log-engine/releases) [![star](https://img.shields.io/github/stars/wgtechlabs/log-engine.svg?&logo=github&labelColor=181717&color=yellow&style=flat-square)](https://github.com/wgtechlabs/log-engine/stargazers) [![license](https://img.shields.io/github/license/wgtechlabs/log-engine.svg?&logo=github&labelColor=181717&style=flat-square)](https://github.com/wgtechlabs/log-engine/blob/main/license)
4
4
 
5
5
  [![banner](https://raw.githubusercontent.com/wgtechlabs/log-engine/main/.github/assets/repo_banner.jpg)](https://github.com/wgtechlabs/log-engine)
6
6
 
7
- WG's Log Engine is the **ultimate logging solution for Node.js developers** - a lightweight, battle-tested utility specifically engineered for Discord bots, Telegram bots, web servers, APIs, and server-side applications. Born from real-world development challenges and proven in production environments like the [Unthread Discord Bot](https://github.com/wgtechlabs/unthread-discord-bot/), Log Engine delivers enterprise-grade logging with zero complexity.
7
+ WG's Log Engine is the **ultimate logging solution for Node.js developers** - a lightweight, battle-tested utility specifically engineered for Discord bots, Telegram bots, web servers, APIs, and server-side applications. Born from real-world development challenges and proven in production environments like the [Unthread Discord Bot](https://github.com/wgtechlabs/unthread-discord-bot/), Log Engine delivers enterprise-grade logging with zero complexity and beautiful color-coded console output.
8
8
 
9
- **Stop wrestling with logging configurations and start building amazing applications.** Whether you're creating the next viral Discord community bot, building high-performance APIs, developing microservices, or deploying production servers, Log Engine provides intelligent terminal-based logging that scales with your application's growth - from your first "Hello World" to handling millions of requests across distributed systems.
9
+ **Stop wrestling with logging configurations and start building amazing applications.** Whether you're creating the next viral Discord community bot, building high-performance APIs, developing microservices, or deploying production servers, Log Engine provides intelligent terminal-based logging with vibrant colors that scales with your application's growth - from your first "Hello World" to handling millions of requests across distributed systems.
10
10
 
11
11
  ## âŖī¸ Motivation
12
12
 
@@ -18,22 +18,24 @@ Log Engine transforms your development experience from chaotic debugging session
18
18
 
19
19
  - **Lightweight & Fast**: Minimal overhead with maximum performance - designed to enhance your application, not slow it down.
20
20
  - **No Learning Curve**: Dead simple API that you can master in seconds. No extensive documentation, complex configurations, or setup required - Log Engine works instantly.
21
+ - **Colorized Console Output**: Beautiful ANSI color-coded log levels with intelligent terminal formatting - instantly identify message severity at a glance with color-coded output.
21
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
23
  - **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.
23
- - **Timestamp Support**: Formatted timestamps with both ISO and human-readable formats - all the formatting you need built right in.
24
+ - **Enhanced Formatting**: Structured log entries with dual timestamps (ISO + human-readable) and colored level indicators for maximum readability.
24
25
  - **TypeScript Ready**: Full TypeScript support with comprehensive type definitions for a seamless development experience.
25
26
  - **Zero Dependencies**: No external dependencies for maximum compatibility and security - keeps your bundle clean and your project simple.
26
27
  - **Easy Integration**: Simple API that works seamlessly with existing Node.js applications. Just `import` and start logging - no middleware, plugins, or configuration required.
27
28
 
28
29
  ## 🤔 How It Works
29
-
30
+ <!-- markdownlint-disable MD051 -->
30
31
  1. Log Engine automatically detects your environment using `NODE_ENV` and sets appropriate log levels for optimal performance
31
32
  2. When you call logging methods, messages are filtered based on the configured severity level (only messages at or above the set level are displayed)
32
33
  3. Each log message is instantly formatted with precise timestamps in both ISO and human-readable formats
33
- 4. Messages are output to the console with clear level indicators, making debugging and monitoring effortless
34
+ 4. Messages are output to the console with **colorized level indicators and timestamps**, making debugging and monitoring effortless - errors show in red, warnings in yellow, info in blue, and debug in purple
35
+ 5. ANSI color codes ensure compatibility across different terminal environments while maintaining beautiful, readable output
34
36
 
35
37
  Ready to streamline your application logging? Get started in seconds with our [simple installation](#đŸ“Ļ-installation)!
36
-
38
+ <!-- markdownlint-enable MD051 -->
37
39
  ## 🤗 Special Thanks
38
40
 
39
41
  <!-- markdownlint-disable MD033 -->
@@ -43,6 +45,12 @@ Ready to streamline your application logging? Get started in seconds with our [s
43
45
  | <div align="center"><a href="https://unthread.com" target="_blank"><b>Unthread</b></a><br/>Streamlined support ticketing for modern teams.</div> |
44
46
  <!-- markdownlint-enable MD033 -->
45
47
 
48
+ ## 💸 Sponsored Ads
49
+
50
+ Open source development is resource-intensive. These **sponsored ads help keep Log Engine free and actively maintained** while connecting you with tools and services that support open-source development.
51
+
52
+ [![sponsored ads](https://gitads.dev/v1/ad-serve?source=wgtechlabs/log-engine@github)](https://gitads.dev/v1/ad-track?source=wgtechlabs/log-engine@github)
53
+
46
54
  ## đŸ“Ļ Installation
47
55
 
48
56
  Install the package using npm:
@@ -94,6 +102,27 @@ LogEngine.warn('Warning message');
94
102
  LogEngine.error('Error message');
95
103
  ```
96
104
 
105
+ ### Color-Coded Output 🎨
106
+
107
+ Log Engine now features beautiful, color-coded console output that makes debugging and monitoring a breeze:
108
+
109
+ ```typescript
110
+ import { LogEngine } from '@wgtechlabs/log-engine';
111
+
112
+ // Each log level gets its own distinct color for instant recognition
113
+ LogEngine.debug('🔍 Debugging user authentication flow'); // Purple/Magenta
114
+ LogEngine.info('â„šī¸ User successfully logged in'); // Blue
115
+ LogEngine.warn('âš ī¸ API rate limit at 80% capacity'); // Yellow
116
+ LogEngine.error('❌ Database connection timeout'); // Red
117
+ ```
118
+
119
+ **Why Colors Matter:**
120
+
121
+ - **Instant Recognition**: Quickly spot errors, warnings, and debug info without reading every line
122
+ - **Better Debugging**: Visually separate different types of messages during development
123
+ - **Production Monitoring**: Easily scan logs for critical issues in terminal environments
124
+ - **Enhanced Readability**: Color-coded timestamps and level indicators reduce eye strain
125
+
97
126
  ### Log Levels
98
127
 
99
128
  Log Engine supports the following levels (in order of severity):
@@ -115,12 +144,24 @@ Log Engine automatically configures itself based on the `NODE_ENV` environment v
115
144
 
116
145
  ### Log Format
117
146
 
118
- Log messages are formatted with timestamps and levels:
147
+ Log messages are beautifully formatted with colorized timestamps, levels, and smart terminal output:
119
148
 
120
- ```
121
- [2025-05-20T16:57:45.678Z] [4:57 PM] [INFO] Message here.
149
+ ```bash
150
+ # Example colorized output (colors visible in terminal)
151
+ [2025-05-29T16:57:45.678Z][4:57 PM][DEBUG]: Debugging application flow
152
+ [2025-05-29T16:57:46.123Z][4:57 PM][INFO]: Server started successfully
153
+ [2025-05-29T16:57:47.456Z][4:57 PM][WARN]: API rate limit approaching
154
+ [2025-05-29T16:57:48.789Z][4:57 PM][ERROR]: Database connection failed
122
155
  ```
123
156
 
157
+ **Color Scheme:**
158
+
159
+ - đŸŸŖ **DEBUG**: Magenta/Purple - Detailed debugging information
160
+ - đŸ”ĩ **INFO**: Blue - General informational messages
161
+ - 🟡 **WARN**: Yellow - Warning messages that need attention
162
+ - 🔴 **ERROR**: Red - Error messages requiring immediate action
163
+ - âšĢ **Timestamps**: Gray (ISO) and Cyan (local time) for easy scanning
164
+
124
165
  ## đŸ’Ŧ Community Discussions
125
166
 
126
167
  Join our community discussions to get help, share ideas, and connect with other users:
@@ -136,11 +177,12 @@ Join our community discussions to get help, share ideas, and connect with other
136
177
  ### Getting Help
137
178
 
138
179
  Need assistance with the library? Here's how to get help:
139
-
180
+ <!-- markdownlint-disable MD051 -->
140
181
  - **Community Support**: Check the [Help & Support](https://github.com/wgtechlabs/log-engine/discussions/categories/help-support) category in our GitHub Discussions for answers to common questions.
141
182
  - **Ask a Question**: Create a [new discussion](https://github.com/wgtechlabs/log-engine/discussions/new?category=help-support) if you can't find answers to your specific issue.
142
183
  - **Documentation**: Review the [usage instructions](#đŸ•šī¸-usage) in this README for common examples and configurations.
143
184
  - **Known Issues**: Browse [existing issues](https://github.com/wgtechlabs/log-engine/issues) to see if your problem has already been reported.
185
+ <!-- markdownlint-enable MD051 -->
144
186
 
145
187
  ### Reporting Issues
146
188
 
@@ -187,4 +229,6 @@ This project is created by **[Waren Gonzaga](https://github.com/warengonzaga)**
187
229
 
188
230
  ---
189
231
 
190
- đŸ’ģ with â¤ī¸ by [Waren Gonzaga](https://warengonzaga.com) under [WG Technology Labs](https://wgtechlabs.com), and [Him](https://www.youtube.com/watch?v=HHrxS4diLew&t=44s) 🙏
232
+ đŸ’ģ with â¤ī¸ by [Waren Gonzaga](https://warengonzaga.com) under [WG Technology Labs](https://wgtechlabs.com), and [Him](https://www.youtube.com/watch?v=HHrxS4diLew&t=44s) 🙏
233
+
234
+ <!-- GitAds-Verify: O4MESJK7VTBCELWNTFQAWB5HDX57H9MS -->
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Log message formatter that provides colorized console output with timestamps
3
+ * Handles ANSI color codes and structured log message formatting
4
+ */
5
+ import { LogLevel } from './types';
6
+ /**
7
+ * LogFormatter class responsible for formatting log messages with colors and timestamps
8
+ * Creates readable, colored console output with ISO timestamps and local time
9
+ */
10
+ export declare class LogFormatter {
11
+ private static readonly colors;
12
+ /**
13
+ * Formats a log message with timestamp, level indicator, and appropriate coloring
14
+ * Creates a structured log entry: [ISO_TIMESTAMP][LOCAL_TIME][LEVEL]: message
15
+ * @param level - The log level to format for
16
+ * @param message - The message content to format
17
+ * @returns Formatted string with ANSI colors and timestamps
18
+ */
19
+ static format(level: LogLevel, message: string): string;
20
+ /**
21
+ * Converts LogLevel enum to human-readable string
22
+ * @param level - The LogLevel to convert
23
+ * @returns String representation of the log level
24
+ */
25
+ private static getLevelName;
26
+ /**
27
+ * Maps LogLevel to appropriate ANSI color code
28
+ * Colors help quickly identify message severity in console output
29
+ * @param level - The LogLevel to get color for
30
+ * @returns ANSI color escape sequence
31
+ */
32
+ private static getLevelColor;
33
+ }
34
+ //# sourceMappingURL=formatter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../src/formatter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC;;;GAGG;AACH,qBAAa,YAAY;IAErB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAU5B;IAEF;;;;;;OAMG;IACH,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM;IAoBvD;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,YAAY;IAW3B;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,aAAa;CAU/B"}
package/dist/formatter.js CHANGED
@@ -1,8 +1,23 @@
1
1
  "use strict";
2
+ /**
3
+ * Log message formatter that provides colorized console output with timestamps
4
+ * Handles ANSI color codes and structured log message formatting
5
+ */
2
6
  Object.defineProperty(exports, "__esModule", { value: true });
3
7
  exports.LogFormatter = void 0;
4
8
  const types_1 = require("./types");
9
+ /**
10
+ * LogFormatter class responsible for formatting log messages with colors and timestamps
11
+ * Creates readable, colored console output with ISO timestamps and local time
12
+ */
5
13
  class LogFormatter {
14
+ /**
15
+ * Formats a log message with timestamp, level indicator, and appropriate coloring
16
+ * Creates a structured log entry: [ISO_TIMESTAMP][LOCAL_TIME][LEVEL]: message
17
+ * @param level - The log level to format for
18
+ * @param message - The message content to format
19
+ * @returns Formatted string with ANSI colors and timestamps
20
+ */
6
21
  static format(level, message) {
7
22
  const now = new Date();
8
23
  const isoTimestamp = now.toISOString();
@@ -12,8 +27,18 @@ class LogFormatter {
12
27
  hour12: true
13
28
  });
14
29
  const levelName = this.getLevelName(level);
15
- return `[${isoTimestamp}] [${timeString}] [${levelName}] ${message}`;
30
+ const levelColor = this.getLevelColor(level);
31
+ // Apply colors to each component for better readability
32
+ const coloredTimestamp = `${this.colors.gray}[${isoTimestamp}]${this.colors.reset}`;
33
+ const coloredTimeString = `${this.colors.cyan}[${timeString}]${this.colors.reset}`;
34
+ const coloredLevel = `${levelColor}[${levelName}]${this.colors.reset}`;
35
+ return `${coloredTimestamp}${coloredTimeString}${coloredLevel}: ${message}`;
16
36
  }
37
+ /**
38
+ * Converts LogLevel enum to human-readable string
39
+ * @param level - The LogLevel to convert
40
+ * @returns String representation of the log level
41
+ */
17
42
  static getLevelName(level) {
18
43
  switch (level) {
19
44
  case types_1.LogLevel.DEBUG: return 'DEBUG';
@@ -24,5 +49,33 @@ class LogFormatter {
24
49
  default: return 'UNKNOWN';
25
50
  }
26
51
  }
52
+ /**
53
+ * Maps LogLevel to appropriate ANSI color code
54
+ * Colors help quickly identify message severity in console output
55
+ * @param level - The LogLevel to get color for
56
+ * @returns ANSI color escape sequence
57
+ */
58
+ static getLevelColor(level) {
59
+ switch (level) {
60
+ case types_1.LogLevel.DEBUG: return this.colors.magenta; // Purple for debug info
61
+ case types_1.LogLevel.INFO: return this.colors.blue; // Blue for general info
62
+ case types_1.LogLevel.WARN: return this.colors.yellow; // Yellow for warnings
63
+ case types_1.LogLevel.ERROR: return this.colors.red; // Red for errors
64
+ case types_1.LogLevel.SILENT: return this.colors.dim; // Dim for silent (shouldn't be used)
65
+ default: return this.colors.white; // White for unknown levels
66
+ }
67
+ }
27
68
  }
28
69
  exports.LogFormatter = LogFormatter;
70
+ // ANSI color codes for terminal output styling
71
+ LogFormatter.colors = {
72
+ reset: '\x1b[0m', // Reset all formatting
73
+ dim: '\x1b[2m', // Dim/faded text
74
+ red: '\x1b[31m', // Red text (errors)
75
+ yellow: '\x1b[33m', // Yellow text (warnings)
76
+ blue: '\x1b[34m', // Blue text (info)
77
+ magenta: '\x1b[35m', // Magenta text (debug)
78
+ cyan: '\x1b[36m', // Cyan text (timestamps)
79
+ white: '\x1b[37m', // White text (default)
80
+ gray: '\x1b[90m' // Gray text (timestamps)
81
+ };
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Main entry point for the Log Engine library
3
+ * Provides a simple, configurable logging interface with environment-based auto-configuration
4
+ */
5
+ import { LoggerConfig } from './types';
6
+ /**
7
+ * Main LogEngine API - provides all logging functionality with a clean interface
8
+ * Auto-configured based on NODE_ENV, but can be reconfigured at runtime
9
+ */
10
+ export declare const LogEngine: {
11
+ /**
12
+ * Configure the logger with custom settings
13
+ * @param config - Partial configuration object containing level and/or environment
14
+ * @example
15
+ * ```typescript
16
+ * LogEngine.configure({ level: LogLevel.DEBUG });
17
+ * LogEngine.configure({ level: LogLevel.WARN, environment: 'staging' });
18
+ * ```
19
+ */
20
+ configure: (config: Partial<LoggerConfig>) => void;
21
+ /**
22
+ * Log a debug message (lowest priority)
23
+ * Only shown when log level is DEBUG or lower
24
+ * Useful for detailed diagnostic information during development
25
+ * @param message - The debug message to log
26
+ * @example
27
+ * ```typescript
28
+ * LogEngine.debug('User authentication flow started');
29
+ * LogEngine.debug(`Processing ${items.length} items`);
30
+ * ```
31
+ */
32
+ debug: (message: string) => void;
33
+ /**
34
+ * Log an informational message
35
+ * General information about application flow and state
36
+ * Shown when log level is INFO or lower
37
+ * @param message - The info message to log
38
+ * @example
39
+ * ```typescript
40
+ * LogEngine.info('Application started successfully');
41
+ * LogEngine.info('User logged in: john@example.com');
42
+ * ```
43
+ */
44
+ info: (message: string) => void;
45
+ /**
46
+ * Log a warning message
47
+ * Indicates potential issues that don't prevent operation
48
+ * Shown when log level is WARN or lower
49
+ * @param message - The warning message to log
50
+ * @example
51
+ * ```typescript
52
+ * LogEngine.warn('API rate limit approaching');
53
+ * LogEngine.warn('Deprecated function called');
54
+ * ```
55
+ */
56
+ warn: (message: string) => void;
57
+ /**
58
+ * Log an error message (highest priority)
59
+ * Indicates serious problems that need attention
60
+ * Always shown unless log level is SILENT
61
+ * @param message - The error message to log
62
+ * @example
63
+ * ```typescript
64
+ * LogEngine.error('Database connection failed');
65
+ * LogEngine.error('Authentication token expired');
66
+ * ```
67
+ */
68
+ error: (message: string) => void;
69
+ };
70
+ export { LogLevel, LoggerConfig } from './types';
71
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAY,YAAY,EAAE,MAAM,SAAS,CAAC;AA8BjD;;;GAGG;AACH,eAAO,MAAM,SAAS;IAClB;;;;;;;;OAQG;wBACiB,OAAO,CAAC,YAAY,CAAC;IAEzC;;;;;;;;;;OAUG;qBACc,MAAM;IAEvB;;;;;;;;;;OAUG;oBACa,MAAM;IAEtB;;;;;;;;;;OAUG;oBACa,MAAM;IAEtB;;;;;;;;;;OAUG;qBACc,MAAM;CAC1B,CAAC;AAEF,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -1,10 +1,22 @@
1
1
  "use strict";
2
+ /**
3
+ * Main entry point for the Log Engine library
4
+ * Provides a simple, configurable logging interface with environment-based auto-configuration
5
+ */
2
6
  Object.defineProperty(exports, "__esModule", { value: true });
3
7
  exports.LogLevel = exports.LogEngine = void 0;
4
8
  const logger_1 = require("./logger");
5
9
  const types_1 = require("./types");
10
+ // Create singleton logger instance
6
11
  const logger = new logger_1.Logger();
7
- // Auto-configure based on NODE_ENV if available
12
+ /**
13
+ * Determines the appropriate default log level based on NODE_ENV
14
+ * - production: WARN (reduce noise in production)
15
+ * - development: DEBUG (verbose logging for development)
16
+ * - test: ERROR (minimal logging during tests)
17
+ * - default: INFO (balanced logging for other environments)
18
+ * @returns The appropriate LogLevel for the current environment
19
+ */
8
20
  const getDefaultLogLevel = () => {
9
21
  const nodeEnv = process.env.NODE_ENV;
10
22
  switch (nodeEnv) {
@@ -18,12 +30,70 @@ const getDefaultLogLevel = () => {
18
30
  return types_1.LogLevel.INFO;
19
31
  }
20
32
  };
33
+ // Initialize logger with environment-appropriate default level
21
34
  logger.configure({ level: getDefaultLogLevel() });
35
+ /**
36
+ * Main LogEngine API - provides all logging functionality with a clean interface
37
+ * Auto-configured based on NODE_ENV, but can be reconfigured at runtime
38
+ */
22
39
  exports.LogEngine = {
40
+ /**
41
+ * Configure the logger with custom settings
42
+ * @param config - Partial configuration object containing level and/or environment
43
+ * @example
44
+ * ```typescript
45
+ * LogEngine.configure({ level: LogLevel.DEBUG });
46
+ * LogEngine.configure({ level: LogLevel.WARN, environment: 'staging' });
47
+ * ```
48
+ */
23
49
  configure: (config) => logger.configure(config),
50
+ /**
51
+ * Log a debug message (lowest priority)
52
+ * Only shown when log level is DEBUG or lower
53
+ * Useful for detailed diagnostic information during development
54
+ * @param message - The debug message to log
55
+ * @example
56
+ * ```typescript
57
+ * LogEngine.debug('User authentication flow started');
58
+ * LogEngine.debug(`Processing ${items.length} items`);
59
+ * ```
60
+ */
24
61
  debug: (message) => logger.debug(message),
62
+ /**
63
+ * Log an informational message
64
+ * General information about application flow and state
65
+ * Shown when log level is INFO or lower
66
+ * @param message - The info message to log
67
+ * @example
68
+ * ```typescript
69
+ * LogEngine.info('Application started successfully');
70
+ * LogEngine.info('User logged in: john@example.com');
71
+ * ```
72
+ */
25
73
  info: (message) => logger.info(message),
74
+ /**
75
+ * Log a warning message
76
+ * Indicates potential issues that don't prevent operation
77
+ * Shown when log level is WARN or lower
78
+ * @param message - The warning message to log
79
+ * @example
80
+ * ```typescript
81
+ * LogEngine.warn('API rate limit approaching');
82
+ * LogEngine.warn('Deprecated function called');
83
+ * ```
84
+ */
26
85
  warn: (message) => logger.warn(message),
86
+ /**
87
+ * Log an error message (highest priority)
88
+ * Indicates serious problems that need attention
89
+ * Always shown unless log level is SILENT
90
+ * @param message - The error message to log
91
+ * @example
92
+ * ```typescript
93
+ * LogEngine.error('Database connection failed');
94
+ * LogEngine.error('Authentication token expired');
95
+ * ```
96
+ */
27
97
  error: (message) => logger.error(message)
28
98
  };
29
99
  var types_2 = require("./types");
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Core Logger class that handles log message output with configurable levels
3
+ * Supports DEBUG, INFO, WARN, ERROR levels with intelligent filtering
4
+ * Uses colorized console output with timestamps for better readability
5
+ */
6
+ import { LoggerConfig } from './types';
7
+ /**
8
+ * Logger class responsible for managing log output and configuration
9
+ * Provides level-based filtering and formatted console output
10
+ */
11
+ export declare class Logger {
12
+ private config;
13
+ /**
14
+ * Updates logger configuration with new settings
15
+ * Merges provided config with existing settings (partial update)
16
+ * @param config - Partial configuration object to apply
17
+ */
18
+ configure(config: Partial<LoggerConfig>): void;
19
+ /**
20
+ * Determines if a message should be logged based on current log level
21
+ * Messages are shown only if their level >= configured minimum level
22
+ * @param level - The log level of the message to check
23
+ * @returns true if message should be logged, false otherwise
24
+ */
25
+ private shouldLog;
26
+ /**
27
+ * Log a debug message with DEBUG level formatting
28
+ * Uses console.log for output with purple/magenta coloring
29
+ * @param message - The debug message to log
30
+ */
31
+ debug(message: string): void;
32
+ /**
33
+ * Log an informational message with INFO level formatting
34
+ * Uses console.log for output with blue coloring
35
+ * @param message - The info message to log
36
+ */
37
+ info(message: string): void;
38
+ /**
39
+ * Log a warning message with WARN level formatting
40
+ * Uses console.warn for output with yellow coloring
41
+ * @param message - The warning message to log
42
+ */
43
+ warn(message: string): void;
44
+ /**
45
+ * Log an error message with ERROR level formatting
46
+ * Uses console.error for output with red coloring
47
+ * @param message - The error message to log
48
+ */
49
+ error(message: string): void;
50
+ }
51
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAY,YAAY,EAAE,MAAM,SAAS,CAAC;AAGjD;;;GAGG;AACH,qBAAa,MAAM;IAEf,OAAO,CAAC,MAAM,CAEZ;IAEF;;;;OAIG;IACH,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI;IAI9C;;;;;OAKG;IACH,OAAO,CAAC,SAAS;IAIjB;;;;OAIG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAO5B;;;;OAIG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAO3B;;;;OAIG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAO3B;;;;OAIG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;CAM/B"}
package/dist/logger.js CHANGED
@@ -1,38 +1,79 @@
1
1
  "use strict";
2
+ /**
3
+ * Core Logger class that handles log message output with configurable levels
4
+ * Supports DEBUG, INFO, WARN, ERROR levels with intelligent filtering
5
+ * Uses colorized console output with timestamps for better readability
6
+ */
2
7
  Object.defineProperty(exports, "__esModule", { value: true });
3
8
  exports.Logger = void 0;
4
9
  const types_1 = require("./types");
5
10
  const formatter_1 = require("./formatter");
11
+ /**
12
+ * Logger class responsible for managing log output and configuration
13
+ * Provides level-based filtering and formatted console output
14
+ */
6
15
  class Logger {
7
16
  constructor() {
17
+ // Internal configuration state with sensible defaults
8
18
  this.config = {
9
19
  level: types_1.LogLevel.INFO
10
20
  };
11
21
  }
22
+ /**
23
+ * Updates logger configuration with new settings
24
+ * Merges provided config with existing settings (partial update)
25
+ * @param config - Partial configuration object to apply
26
+ */
12
27
  configure(config) {
13
28
  this.config = { ...this.config, ...config };
14
29
  }
30
+ /**
31
+ * Determines if a message should be logged based on current log level
32
+ * Messages are shown only if their level >= configured minimum level
33
+ * @param level - The log level of the message to check
34
+ * @returns true if message should be logged, false otherwise
35
+ */
15
36
  shouldLog(level) {
16
37
  return level >= this.config.level;
17
38
  }
39
+ /**
40
+ * Log a debug message with DEBUG level formatting
41
+ * Uses console.log for output with purple/magenta coloring
42
+ * @param message - The debug message to log
43
+ */
18
44
  debug(message) {
19
45
  if (this.shouldLog(types_1.LogLevel.DEBUG)) {
20
46
  const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.DEBUG, message);
21
47
  console.log(formatted);
22
48
  }
23
49
  }
50
+ /**
51
+ * Log an informational message with INFO level formatting
52
+ * Uses console.log for output with blue coloring
53
+ * @param message - The info message to log
54
+ */
24
55
  info(message) {
25
56
  if (this.shouldLog(types_1.LogLevel.INFO)) {
26
57
  const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.INFO, message);
27
58
  console.log(formatted);
28
59
  }
29
60
  }
61
+ /**
62
+ * Log a warning message with WARN level formatting
63
+ * Uses console.warn for output with yellow coloring
64
+ * @param message - The warning message to log
65
+ */
30
66
  warn(message) {
31
67
  if (this.shouldLog(types_1.LogLevel.WARN)) {
32
68
  const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.WARN, message);
33
69
  console.warn(formatted);
34
70
  }
35
71
  }
72
+ /**
73
+ * Log an error message with ERROR level formatting
74
+ * Uses console.error for output with red coloring
75
+ * @param message - The error message to log
76
+ */
36
77
  error(message) {
37
78
  if (this.shouldLog(types_1.LogLevel.ERROR)) {
38
79
  const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.ERROR, message);
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Type definitions for the Log Engine library
3
+ * Provides strongly-typed interfaces for configuration and log levels
4
+ */
5
+ /**
6
+ * Log levels in order of priority (lowest to highest)
7
+ * Higher numeric values represent higher priority levels
8
+ * When a level is set, only messages at that level or higher are shown
9
+ */
10
+ export declare enum LogLevel {
11
+ /** Detailed diagnostic information, typically only of interest during development */
12
+ DEBUG = 0,
13
+ /** General information about application flow and state */
14
+ INFO = 1,
15
+ /** Potentially harmful situations that don't prevent operation */
16
+ WARN = 2,
17
+ /** Error events that might still allow the application to continue */
18
+ ERROR = 3,
19
+ /** Completely disable all logging output */
20
+ SILENT = 4
21
+ }
22
+ /**
23
+ * Represents a single log entry with timestamp, level, and message
24
+ * Used internally for structured logging operations
25
+ */
26
+ export interface LogEntry {
27
+ /** When the log entry was created */
28
+ timestamp: Date;
29
+ /** The severity level of this log entry */
30
+ level: LogLevel;
31
+ /** The actual log message content */
32
+ message: string;
33
+ }
34
+ /**
35
+ * Configuration options for the logger
36
+ * All properties are optional to allow partial updates
37
+ */
38
+ export interface LoggerConfig {
39
+ /** Minimum log level to display (filters out lower priority messages) */
40
+ level: LogLevel;
41
+ /** Optional environment identifier for context (e.g., 'production', 'staging') */
42
+ environment?: string;
43
+ }
44
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AACH,oBAAY,QAAQ;IAChB,qFAAqF;IACrF,KAAK,IAAI;IACT,2DAA2D;IAC3D,IAAI,IAAI;IACR,kEAAkE;IAClE,IAAI,IAAI;IACR,sEAAsE;IACtE,KAAK,IAAI;IACT,4CAA4C;IAC5C,MAAM,IAAI;CACb;AAED;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACrB,qCAAqC;IACrC,SAAS,EAAE,IAAI,CAAC;IAChB,2CAA2C;IAC3C,KAAK,EAAE,QAAQ,CAAC;IAChB,qCAAqC;IACrC,OAAO,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IACzB,yEAAyE;IACzE,KAAK,EAAE,QAAQ,CAAC;IAChB,kFAAkF;IAClF,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB"}
@@ -1,11 +1,25 @@
1
1
  "use strict";
2
+ /**
3
+ * Type definitions for the Log Engine library
4
+ * Provides strongly-typed interfaces for configuration and log levels
5
+ */
2
6
  Object.defineProperty(exports, "__esModule", { value: true });
3
7
  exports.LogLevel = void 0;
8
+ /**
9
+ * Log levels in order of priority (lowest to highest)
10
+ * Higher numeric values represent higher priority levels
11
+ * When a level is set, only messages at that level or higher are shown
12
+ */
4
13
  var LogLevel;
5
14
  (function (LogLevel) {
15
+ /** Detailed diagnostic information, typically only of interest during development */
6
16
  LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
17
+ /** General information about application flow and state */
7
18
  LogLevel[LogLevel["INFO"] = 1] = "INFO";
19
+ /** Potentially harmful situations that don't prevent operation */
8
20
  LogLevel[LogLevel["WARN"] = 2] = "WARN";
21
+ /** Error events that might still allow the application to continue */
9
22
  LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
23
+ /** Completely disable all logging output */
10
24
  LogLevel[LogLevel["SILENT"] = 4] = "SILENT";
11
25
  })(LogLevel || (exports.LogLevel = LogLevel = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wgtechlabs/log-engine",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "A lightweight and efficient logging utility designed specifically for bot applications running on Node.js.",
5
5
  "keywords": [
6
6
  "logging",