Skip to content

Commit 4ac2e63

Browse files
committed
feat Examples
- Advanced Example - Custom Colors - Log to File and Suppress Console - Terminate on Fatal
1 parent 469efd1 commit 4ac2e63

File tree

6 files changed

+51
-8
lines changed

6 files changed

+51
-8
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,10 @@ logger.dir(sampleObject);
163163

164164
## Examples
165165

166+
- [Advanced Example](/examples/advanced-example.js)
166167
- [Custom Colors](/examples/custom-colors.js)
167168
- [Log to File and Suppress Console](/examples/log-to-file-and-suppress-console.js)
169+
- [Terminate on Fatal](/examples/terminate-on-fatal.js)
168170

169171
## Contribute
170172

examples/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22

33
## Examples
44

5+
- [Advanced Example](advanced-example.js)
56
- [Custom Colors](custom-colors.js)
67
- [Log to File and Suppress Console](log-to-file-and-suppress-console.js)
8+
- [Terminate on Fatal](terminate-on-fatal.js)

examples/advanced-example.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const ACL = require("../index");
2+
3+
// Create a logger instance with custom color configuration
4+
const logger = new ACL({
5+
includeTimestamps: true, // Include timestamps in all log messages.
6+
includeMemoryUsage: true, // Track and display memory usage information in the logs.
7+
memoryDisplayMode: 2, // Memory display mode: (1 = MB, 2 = %, 3 = both MB and %).
8+
generateReport: true, // Generate a report at the end of the logging session showing log method usage statistics.
9+
10+
// Caller Information Settings
11+
includeCallerInfo: 1, // Enable the inclusion of caller information (file, line, and column) in log messages.
12+
callerInfoLevel: 3, // Minimum log level to include caller information (0 = debug, 1 = log, 2 = info, 3 = warn, etc.).
13+
callerInfoDisplayMode: 2, // Format for caller information display:
14+
// 1 = Multi-line format (shows file, function, line, and column separately).
15+
// 2 = Inline format (compact single line: file:line:column).
16+
17+
// Inline Caller Information Settings
18+
includeInlineCallerInfo: 1, // Display inline caller information within the log message (quick debugging reference).
19+
inlineCallerInfoLevel: 3, // Minimum log level to include inline caller information (similar to `callerInfoLevel`).
20+
21+
terminateOnFatal: true, // Terminate the application on a `fatal` log message.
22+
});
23+
24+
// Logging with different levels to demonstrate color differences
25+
logger.debug("This is a debug message.");
26+
logger.log("This is a regular log message.");
27+
logger.info("This is an informational message.");
28+
logger.warn("This is a warning message, it will include caller information.");
29+
logger.error("This is an error message, it will include caller information.");
30+
logger.fatal("This is a fatal message, terminating the process.");

examples/custom-colors.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ const ACL = require("../index");
22

33
// Create a logger instance with custom color configuration
44
const logger = new ACL({
5-
logLevel: 1, // Show all log levels
6-
terminateOnFatal: true, // Terminate on fatal error message
75
color: {
86
debug: "\x1b[36m", // Cyan
97
log: "\x1b[32m", // Green
@@ -23,6 +21,3 @@ logger.info("This is an informational message.");
2321
logger.warn("This is a warning message.");
2422
logger.error("This is an error message.");
2523
logger.fatal("This is a fatal message, terminating the process.");
26-
logger.error(
27-
"This is an error message that isn't displayed because the process ended."
28-
);

examples/log-to-file-and-suppress-console.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ const logger = new ACL({
55
logLevel: 0, // Suppress console logs
66
outputFilename: "app.log", // Specify the file to save logs
77
outputFilenameLogLevel: 1, // Log all levels to file
8-
includeTimestamps: true, // Include timestamps in the logs
9-
includeCallerInfo: false, // Optional: disable caller info if not needed
10-
includeMemoryUsage: false, // Optional: disable memory usage if not needed
118
});
129

1310
// Use the logger as usual

examples/terminate-on-fatal.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const ACL = require("../index");
2+
3+
// Create a logger instance with custom color configuration
4+
const logger = new ACL({
5+
terminateOnFatal: true, // Terminate on fatal error message
6+
});
7+
8+
// Logging with different levels to demonstrate color differences
9+
logger.debug("This is a debug message.");
10+
logger.log("This is a regular log message.");
11+
logger.info("This is an informational message.");
12+
logger.warn("This is a warning message.");
13+
logger.error("This is an error message.");
14+
logger.fatal("This is a fatal message, terminating the process.");
15+
logger.error(
16+
"This is an error message that isn't displayed because the process ended."
17+
);

0 commit comments

Comments
 (0)