nelogconsole 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Mem U Sins
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # NoLogConsole
2
+
3
+ nelogconsole — console adapter for [nelog](https://github.com/memUsins/nelog)
4
+
5
+ ## Installation
6
+
7
+ ```shell
8
+ $ npm install nelog nelogconsole
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { Logger } from 'nelog'
15
+ import { ConsoleAdapter } from 'nelogconsole'
16
+
17
+ // simple
18
+ const logger = new Logger([new ConsoleAdapter({ enable: true, level: Level.DebugLevel })]);
19
+
20
+ // with custom config
21
+ const logger = new Logger([
22
+ new ConsoleAdapter({
23
+ enable: true,
24
+ level: Level.DebugLevel,
25
+ colorConfig: {
26
+ timestampColor: Color.FgBlack,
27
+ messageColor: Color.FgWhite,
28
+ levelsColor: {
29
+ [Level.DebugLevel]: Color.FgBrightBlack,
30
+ [Level.InfoLevel]: Color.FgCyan,
31
+ [Level.WarnLevel]: Color.FgYellow,
32
+ [Level.ErrorLevel]: Color.FgBrightRed,
33
+ [Level.FatalLevel]: Color.FgRed,
34
+ [Level.UnselectedLevel]: Color.FgBlack,
35
+ },
36
+ },
37
+ }),
38
+ ]);
39
+ ```
@@ -0,0 +1,8 @@
1
+ import { Log } from 'nelog';
2
+ import { ConsoleAdapterConfig, IConsoleAdapter } from './thirdparty';
3
+ export declare class ConsoleAdapter implements IConsoleAdapter {
4
+ config: ConsoleAdapterConfig;
5
+ constructor(config?: ConsoleAdapterConfig);
6
+ log(log: Log): void;
7
+ format(log: Log): void;
8
+ }
package/lib/adapter.js ADDED
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConsoleAdapter = void 0;
4
+ const nelog_1 = require("nelog");
5
+ const thirdparty_1 = require("./thirdparty");
6
+ class ConsoleAdapter {
7
+ config = {
8
+ enable: true,
9
+ level: nelog_1.Level.DebugLevel,
10
+ };
11
+ constructor(config) {
12
+ this.config = { ...this.config, ...config, colorConfig: (0, thirdparty_1.setupDefaultLoggerColors)(config?.colorConfig) };
13
+ }
14
+ log(log) {
15
+ if (!this.config.enable || !(0, nelog_1.isLevelEnabled)(this.config.level, log.level))
16
+ return;
17
+ this.format(log);
18
+ console.log(log.message);
19
+ }
20
+ format(log) {
21
+ if (!this.config.colorConfig)
22
+ return;
23
+ const levelColor = this.config.colorConfig.levelsColor[log.level];
24
+ const levelFormatted = setTextColor(levelColor, (0, nelog_1.levelToString)(log.level).toUpperCase() || 'UNSELECTED');
25
+ const dateFormatted = setTextColor(this.config.colorConfig.timestampColor, log.timestamp.toISOString());
26
+ const messageFormatted = setTextColor(this.config.colorConfig.messageColor, log.message);
27
+ let nameFormatted = '';
28
+ if (log.data?.name && log.data?.withName) {
29
+ nameFormatted = setTextColor(levelColor, `[${log.data?.name}]:`);
30
+ }
31
+ let errorFormatted = '';
32
+ if (log.data?.error)
33
+ errorFormatted = setTextColor(levelColor, `err=${log.data?.error.message}`);
34
+ const fieldsArray = [];
35
+ let fieldsFormatted = '';
36
+ if (log.data?.fields) {
37
+ for (const key of Object.keys(log.data?.fields)) {
38
+ fieldsArray.push(`${key}=${JSON.stringify(log.data?.fields?.[key])}`);
39
+ }
40
+ fieldsFormatted = setTextColor(levelColor, fieldsArray.join(' '));
41
+ }
42
+ log.message = [dateFormatted, levelFormatted, nameFormatted, messageFormatted, errorFormatted, fieldsFormatted].filter(Boolean).join(' ');
43
+ }
44
+ }
45
+ exports.ConsoleAdapter = ConsoleAdapter;
46
+ const setTextColor = (color, text) => `${color}${text}${thirdparty_1.Color.Reset}`;
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './thirdparty';
2
+ export * from './adapter';
package/lib/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./thirdparty"), exports);
18
+ __exportStar(require("./adapter"), exports);
@@ -0,0 +1,3 @@
1
+ import { ConsoleAdapterColorConfig, ConsoleAdapterLevelColorConfig } from './types';
2
+ export declare const setupDefaultLoggerColors: (config?: ConsoleAdapterColorConfig) => ConsoleAdapterColorConfig;
3
+ export declare const setupStyles: (config?: ConsoleAdapterLevelColorConfig) => ConsoleAdapterLevelColorConfig;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setupStyles = exports.setupDefaultLoggerColors = void 0;
4
+ const nelog_1 = require("nelog");
5
+ const types_1 = require("./types");
6
+ const setupDefaultLoggerColors = (config) => {
7
+ if (!config) {
8
+ return {
9
+ timestampColor: types_1.Color.FgBrightBlack,
10
+ messageColor: types_1.Color.FgWhite,
11
+ levelsColor: (0, exports.setupStyles)(),
12
+ };
13
+ }
14
+ return {
15
+ timestampColor: config?.timestampColor ?? types_1.Color.FgBrightBlack,
16
+ messageColor: config?.messageColor ?? types_1.Color.FgWhite,
17
+ levelsColor: (0, exports.setupStyles)(config?.levelsColor),
18
+ };
19
+ };
20
+ exports.setupDefaultLoggerColors = setupDefaultLoggerColors;
21
+ const setupStyles = (config) => {
22
+ const defaultColors = {
23
+ [nelog_1.Level.DebugLevel]: types_1.Color.FgBrightBlack,
24
+ [nelog_1.Level.InfoLevel]: types_1.Color.FgCyan,
25
+ [nelog_1.Level.WarnLevel]: types_1.Color.FgYellow,
26
+ [nelog_1.Level.ErrorLevel]: types_1.Color.FgBrightRed,
27
+ [nelog_1.Level.FatalLevel]: types_1.Color.FgRed,
28
+ [nelog_1.Level.UnselectedLevel]: types_1.Color.FgBlack,
29
+ };
30
+ return { ...defaultColors, ...config };
31
+ };
32
+ exports.setupStyles = setupStyles;
@@ -0,0 +1,2 @@
1
+ export * from './config';
2
+ export * from './types';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./config"), exports);
18
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,53 @@
1
+ import { IAdapter, Level } from 'nelog';
2
+ export interface IConsoleAdapter extends IAdapter {
3
+ }
4
+ export type ConsoleAdapterLevelColorConfig = Record<Level, Color>;
5
+ export type ConsoleAdapterColorConfig = {
6
+ timestampColor: Color;
7
+ messageColor: Color;
8
+ levelsColor: ConsoleAdapterLevelColorConfig;
9
+ };
10
+ export type ConsoleAdapterConfig = {
11
+ enable: boolean;
12
+ level: Level;
13
+ colorConfig?: ConsoleAdapterColorConfig;
14
+ };
15
+ export declare enum Color {
16
+ Reset = "\u001B[0m",
17
+ Bright = "\u001B[1m",
18
+ Dim = "\u001B[2m",
19
+ Underscore = "\u001B[4m",
20
+ Blink = "\u001B[5m",
21
+ Reverse = "\u001B[7m",
22
+ Hidden = "\u001B[8m",
23
+ FgBlack = "\u001B[30m",
24
+ FgBrightBlack = "\u001B[90m",
25
+ FgRed = "\u001B[31m",
26
+ FgBrightRed = "\u001B[91m",
27
+ FgGreen = "\u001B[32m",
28
+ FgBrightGreen = "\u001B[92m",
29
+ FgYellow = "\u001B[33m",
30
+ FgBrightYellow = "\u001B[93m",
31
+ FgBlue = "\u001B[34m",
32
+ FgBrightBlue = "\u001B[94m",
33
+ FgMagenta = "\u001B[35m",
34
+ FgBrightMagenta = "\u001B[95m",
35
+ FgCyan = "\u001B[36m",
36
+ FgBrightCyan = "\u001B[96m",
37
+ FgWhite = "\u001B[37m",
38
+ BgBlack = "\u001B[40m",
39
+ BgBrightBlack = "\u001B[100m",
40
+ BgRed = "\u001B[41m",
41
+ BgBrightRed = "\u001B[101m",
42
+ BgGreen = "\u001B[42m",
43
+ BgBrightGreen = "\u001B[102m",
44
+ BgYellow = "\u001B[43m",
45
+ BgBrightYellow = "\u001B[103m",
46
+ BgBlue = "\u001B[44m",
47
+ BgBrightBlue = "\u001B[104m",
48
+ BgMagenta = "\u001B[45m",
49
+ BgBrightMagenta = "\u001B[105m",
50
+ BgCyan = "\u001B[46m",
51
+ BgBrightCyan = "\u001B[106m",
52
+ BgWhite = "\u001B[47m"
53
+ }
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Color = void 0;
4
+ var Color;
5
+ (function (Color) {
6
+ Color["Reset"] = "\u001B[0m";
7
+ Color["Bright"] = "\u001B[1m";
8
+ Color["Dim"] = "\u001B[2m";
9
+ Color["Underscore"] = "\u001B[4m";
10
+ Color["Blink"] = "\u001B[5m";
11
+ Color["Reverse"] = "\u001B[7m";
12
+ Color["Hidden"] = "\u001B[8m";
13
+ Color["FgBlack"] = "\u001B[30m";
14
+ Color["FgBrightBlack"] = "\u001B[90m";
15
+ Color["FgRed"] = "\u001B[31m";
16
+ Color["FgBrightRed"] = "\u001B[91m";
17
+ Color["FgGreen"] = "\u001B[32m";
18
+ Color["FgBrightGreen"] = "\u001B[92m";
19
+ Color["FgYellow"] = "\u001B[33m";
20
+ Color["FgBrightYellow"] = "\u001B[93m";
21
+ Color["FgBlue"] = "\u001B[34m";
22
+ Color["FgBrightBlue"] = "\u001B[94m";
23
+ Color["FgMagenta"] = "\u001B[35m";
24
+ Color["FgBrightMagenta"] = "\u001B[95m";
25
+ Color["FgCyan"] = "\u001B[36m";
26
+ Color["FgBrightCyan"] = "\u001B[96m";
27
+ Color["FgWhite"] = "\u001B[37m";
28
+ Color["BgBlack"] = "\u001B[40m";
29
+ Color["BgBrightBlack"] = "\u001B[100m";
30
+ Color["BgRed"] = "\u001B[41m";
31
+ Color["BgBrightRed"] = "\u001B[101m";
32
+ Color["BgGreen"] = "\u001B[42m";
33
+ Color["BgBrightGreen"] = "\u001B[102m";
34
+ Color["BgYellow"] = "\u001B[43m";
35
+ Color["BgBrightYellow"] = "\u001B[103m";
36
+ Color["BgBlue"] = "\u001B[44m";
37
+ Color["BgBrightBlue"] = "\u001B[104m";
38
+ Color["BgMagenta"] = "\u001B[45m";
39
+ Color["BgBrightMagenta"] = "\u001B[105m";
40
+ Color["BgCyan"] = "\u001B[46m";
41
+ Color["BgBrightCyan"] = "\u001B[106m";
42
+ Color["BgWhite"] = "\u001B[47m";
43
+ })(Color || (exports.Color = Color = {}));
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "nelogconsole",
3
+ "version": "0.0.1",
4
+ "description": "Logger console adapter",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "files": [
8
+ "lib/**/*"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsc && tsc-alias",
12
+ "format": "prettier -w ./src",
13
+ "lint": "eslint . --ext .ts"
14
+ },
15
+ "keywords": [
16
+ "Logger"
17
+ ],
18
+ "type": "commonjs",
19
+ "author": "memUsins",
20
+ "devDependencies": {
21
+ "@types/chalk": "^0.4.31",
22
+ "eslint": "^9.39.1",
23
+ "prettier": "^3.7.3"
24
+ },
25
+ "dependencies": {
26
+ "chalk": "^5.6.2",
27
+ "nelog": "^0.0.1"
28
+ }
29
+ }