You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+56-22Lines changed: 56 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,7 @@
1
1
# Advanced Console Log (ACL)
2
2
3
-
[](https://github.com/samestrin/advanced-console-log/stargazers)[](https://github.com/samestrin/advanced-console-log/network/members)[](https://github.com/samestrin/advanced-console-log/watchers)
4
-
5
-
[](https://opensource.org/licenses/MIT)[](https://nodejs.org/)
3
+
[](https://github.com/samestrin/advanced-console-log/stargazers)[](https://github.com/samestrin/advanced-console-log/network/members)[](https:
4
+
[](https://opensource.org/licenses/MIT)[](https:
6
5
7
6
**Advanced Console Log (ACL)**, available as the `advanced-console-log` NPM package, is a lightweight logging module for Node.js applications. It supports console and file logging with various levels, colors, and additional features such as memory usage tracking and caller information.
8
7
@@ -16,6 +15,7 @@
16
15
-**Multiple Log Levels**: Supports six logging levels (debug, log, info, warn, error, fatal) to categorize and prioritize log messages.
17
16
-**Console Logging**: Outputs log messages to the console with color-coded and formatted output based on log level.
18
17
-**File Logging**: Optionally logs messages to a specified file, with separate control over the log level for file output.
18
+
-**Asynchronous Logging Modes**: Supports multiple asynchronous logging modes ("async", "async-queue", "worker") for non-blocking operations in high-throughput environments.
19
19
-**Timestamps**: Includes configurable timestamps for all log messages.
20
20
-**Custom Color Configuration**: Allows custom color settings for each log level to override default colors.
21
21
@@ -44,6 +44,10 @@
44
44
45
45
-**Log Reports**: Generates a report detailing the number of times each log method was called, with percentages.
46
46
47
+
### File Management
48
+
49
+
-**File Rotation and Retention**: Supports automatic log file rotation and retention strategies to manage log file sizes and disk space.
50
+
47
51
## Dependencies
48
52
49
53
This logging module utilizes the following built-in Node.js modules:
@@ -53,6 +57,7 @@ This logging module utilizes the following built-in Node.js modules:
53
57
-**`util`**: Used to format and inspect complex objects for pretty printing in log outputs.
54
58
-**`process`**: Provides access to the current Node.js process, enabling memory usage tracking and process termination.
55
59
-**`v8`**: Retrieves memory heap statistics to track memory usage within the application. _Lazy loaded for performance reasons._
60
+
-**`worker_threads`**: Used for worker thread operations in worker mode. _Lazy loaded for performance reasons._
56
61
57
62
_There are no external dependencies._
58
63
@@ -76,32 +81,52 @@ Then you can get a _single_ instance of ACL (recommended), created with your cus
76
81
77
82
```js
78
83
constlogger=ACL.getInstance({
79
-
logLevel:1,// Set console log level
84
+
logLevel:1,
80
85
});
81
86
```
82
87
83
88
or create a new ACL instance, using your custom [configuration options](docs/configuration-options.md).
84
89
85
90
```js
86
91
constlogger=newACL({
87
-
logLevel:1,// Set console log level
92
+
logLevel:1,
88
93
});
89
94
```
90
95
91
96
ACL supports a number of different [configuration options](docs/configuration-options.md). Here is another example using additional configuration options:
92
97
93
98
```js
94
99
constlogger=ACL.getInstance({
95
-
logLevel:1, // Set console log level
96
-
outputFilename:"app.log", // Specify log file name
97
-
outputFileLogLevel:2, // Set file log level
98
-
includeTimestamps:true, // Include timestamps in logs
99
-
includeMemoryUsage:true, // Track and display memory usage
|`color`|`object`|`{}`| Allows custom color configuration for log levels. See **[Example: Custom Colors](/examples/custom-colors.js)** for implementation details. |
20
22
21
23
### Timestamp and Caller Information Configuration
|`timestampFormat`|`string`|`HH:mm:ss.SSS`| Defines the timestamp format using date/time formatting tokens (`YYYY`, `MM`, `DD`, `HH`, `mm`, `ss`, `SSS`). |
28
+
|`includeCallerInfo`|`boolean`|`false`| If `true`, includes caller information (file, function, line, and column) in log messages. |
29
+
|`callerInfoLevel`|`number`|`2`| Sets the log level for caller information. Only logs of this level or higher include caller info. |
30
+
|`includeInlineCallerInfo`|`boolean`|`false`| If `true`, displays caller information inline within log messages for easier debugging. |
31
+
|`inlineCallerInfoLevel`|`number`|`1`| Sets the log level for inline caller information. Only logs of this level or higher include inline caller info. |
32
+
|`includeStackTrace`|`boolean`|`false`| If `true`, includes a stack trace in error and fatal messages. |
|`outputFilename`|`string`|`null`| Specifies the filename for file-based logging. If empty, file logging is disabled. |
36
-
|`outputFileLogLevel`|`number`|`1`| Sets the [log level](log-levels.md) for file logging. Accepts values from `0` (debug) to `5` (fatal). |
37
-
|`outputFileBatchOutput`|`boolean`|`false`| If `true`, enables batching of log entries for file output to improve performance. |
38
-
|`outputFileBatchOutputSize`|`number`|`25`| The number of log entries to batch before writing to the file. Applies only when `outputFileBatchOutput` is set to `true`. |
39
-
|`maxLogFileSizeMB`|`number`|`10`| Defines the maximum log file size in MB. When the file size is reached, a new log file is created. |
40
-
|`maxLogFiles`|`number`|`5`| Limits the number of log files retained. Older files are deleted when the limit is exceeded. |
|`useAsyncLogging`|`boolean`|`false`| If `true`, all standard log methods (`debug`, `info`, `warn`, etc.) are automatically converted to their asynchronous equivalents (`debugAsync`, `infoAsync`, etc.), enabling non-blocking logging for improved performance in high-throughput environments. |
Copy file name to clipboardExpand all lines: docs/methods.md
+14-2Lines changed: 14 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ The following are the core logging methods available in the `advanced-console-lo
6
6
7
7
### `debug(condition = true, ...args)`
8
8
9
-
Logs a debug message with a cyan color. It’s typically used for detailed debugging information. If `generateReport` is set to `true`, it counts the call in the report.
9
+
Logs a debug message with a cyan color. It’s typically used for detailed debugging information.
10
10
11
11
### `log(condition = true, ...args)`
12
12
@@ -30,7 +30,7 @@ Logs a fatal error message with a magenta color. It’s used for severe errors t
30
30
31
31
## Async Logging Methods
32
32
33
-
The following are the async logging methods available in the `advanced-console-log` module. These can be called directly or the instance of ACL can be configured to run in async mode and you can u8se the _Core Logging Methods_.
33
+
The following are the async logging methods available in the `advanced-console-log` module. These can be called directly, or you can configure the instance of ACL to run in an async mode (e.g., `mode: "async"`) and use the Core Logging Methods.
34
34
35
35
### `debugAsync(condition = true, ...args)`
36
36
@@ -78,6 +78,12 @@ An alias for `startTimer(label)`. Starts a timer with the given `label`.
78
78
79
79
An alias for `stopTimer(label)`. Stops the timer with the given `label` and logs the elapsed time.
80
80
81
+
### `clearAllTimers()`
82
+
83
+
Clears all active timers.
84
+
85
+
**Note:** If the `enableTimers` configuration option is not set to `true`, calling these timer methods will throw an error.
86
+
81
87
## Utility Methods
82
88
83
89
### `dir(obj)`
@@ -95,3 +101,9 @@ Logs the current stack trace of the application. It’s similar to `console.trac
95
101
Generates a detailed report if `generateReport` is set to `true`. The report includes the number of calls made to each log method (`debug`, `log`, `info`, etc.) and their respective percentages.
96
102
97
103
**Note:** If the `generateReport` configuration option is not set to `true`, calling this method will throw an error.
104
+
105
+
## Close Method
106
+
107
+
### `close()`
108
+
109
+
Closes any open resources, such as file streams or worker threads. Should be called when the logger is no longer needed, especially in asynchronous modes.
0 commit comments