@proteinjs/logger 1.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/.eslintrc.js ADDED
@@ -0,0 +1,20 @@
1
+ module.exports = {
2
+ extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended', 'prettier'],
3
+ parser: '@typescript-eslint/parser',
4
+ plugins: ['@typescript-eslint', 'prettier'],
5
+ root: true,
6
+ ignorePatterns: ['**/dist/*', '**/node_modules/*', '*.md'],
7
+
8
+ rules: {
9
+ 'prettier/prettier': ['warn'],
10
+ curly: ['warn'],
11
+ 'eol-last': ['warn', 'always'],
12
+ 'keyword-spacing': ['warn', { before: true }],
13
+ 'no-undef': 'off',
14
+ '@typescript-eslint/no-unused-vars': 'off',
15
+ '@typescript-eslint/no-var-requires': 'off',
16
+ '@typescript-eslint/no-explicit-any': 'off',
17
+ '@typescript-eslint/prefer-as-const': 'off',
18
+ '@typescript-eslint/ban-types': 'off',
19
+ },
20
+ };
@@ -0,0 +1,4 @@
1
+ node_modules/
2
+ dist/
3
+ .DS_Store
4
+ *.md
package/.prettierrc ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "trailingComma": "es5",
3
+ "tabWidth": 2,
4
+ "semi": true,
5
+ "singleQuote": true,
6
+ "jsxSingleQuote": true,
7
+ "printWidth": 120
8
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## 1.0.1 (2024-08-13)
7
+
8
+ **Note:** Version bump only for package @proteinjs/logger
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Brent Bahry
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.
@@ -0,0 +1,4 @@
1
+ /** Load Dependency Source Graphs */
2
+ import '@proteinjs/reflection';
3
+ export * from '../index';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":"AAAA,oCAAoC;AAEpC,OAAO,uBAAuB,CAAC;AAqB/B,cAAc,UAAU,CAAC"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ /** Load Dependency Source Graphs */
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ require("@proteinjs/reflection");
19
+ /** Generate Source Graph */
20
+ const sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"/'debug' | 'info' | 'warn' | 'error'\"},{\"v\":\"@proteinjs/logger/LogWriter\",\"value\":{\"packageName\":\"@proteinjs/logger\",\"name\":\"LogWriter\",\"filePath\":\"/home/runner/work/util/util/packages/logger/src/LogWriter.ts\",\"qualifiedName\":\"@proteinjs/logger/LogWriter\",\"properties\":[],\"methods\":[{\"name\":\"write\",\"returnType\":{\"packageName\":\"\",\"name\":\"void\",\"filePath\":null,\"qualifiedName\":\"/void\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":true,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"log\",\"type\":{\"packageName\":\"@proteinjs/logger\",\"name\":\"Log\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/logger/Log\",\"typeParameters\":null,\"directParents\":null}}]}],\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/reflection\",\"name\":\"Loadable\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/reflection/Loadable\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"sourceType\":3}},{\"v\":\"@proteinjs/reflection/Loadable\"}],\"edges\":[{\"v\":\"@proteinjs/logger/LogWriter\",\"w\":\"@proteinjs/reflection/Loadable\",\"value\":\"extends interface\"}]}";
21
+ /** Generate Source Links */
22
+ const sourceLinks = {};
23
+ /** Load Source Graph and Links */
24
+ const reflection_1 = require("@proteinjs/reflection");
25
+ reflection_1.SourceRepository.merge(sourceGraph, sourceLinks);
26
+ __exportStar(require("../index"), exports);
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;;;;;AAEpC,iCAA+B;AAG/B,4BAA4B;AAE5B,MAAM,WAAW,GAAG,szCAAszC,CAAC;AAG30C,4BAA4B;AAG5B,MAAM,WAAW,GAAG,EACnB,CAAC;AAGF,kCAAkC;AAElC,sDAAyD;AACzD,6BAAgB,CAAC,KAAK,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;AAGjD,2CAAyB"}
@@ -0,0 +1,5 @@
1
+ export * from './src/Logger';
2
+ export * from './src/LogLevel';
3
+ export * from './src/LogWriter';
4
+ export * from './src/DevLogWriter';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
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("./src/Logger"), exports);
18
+ __exportStar(require("./src/LogLevel"), exports);
19
+ __exportStar(require("./src/LogWriter"), exports);
20
+ __exportStar(require("./src/DevLogWriter"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,iDAA+B;AAC/B,kDAAgC;AAChC,qDAAmC"}
@@ -0,0 +1,9 @@
1
+ import { Log } from './LogWriter';
2
+ export declare class DevLogWriter {
3
+ private static COLORS;
4
+ write({ loggerName, logLevel, timestamp, message, obj, inspectOptions, error }: Log): void;
5
+ private prefix;
6
+ private formatDate;
7
+ private colorMessage;
8
+ }
9
+ //# sourceMappingURL=DevLogWriter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DevLogWriter.d.ts","sourceRoot":"","sources":["../../src/DevLogWriter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAC,MAAM,CAMnB;IAEF,KAAK,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,EAAE,cAAc,EAAE,KAAK,EAAE,EAAE,GAAG,GAAG,IAAI;IAkC1F,OAAO,CAAC,MAAM;IAMd,OAAO,CAAC,UAAU;IAclB,OAAO,CAAC,YAAY;CAQrB"}
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DevLogWriter = void 0;
4
+ const util_1 = require("util");
5
+ class DevLogWriter {
6
+ write({ loggerName, logLevel, timestamp, message, obj, inspectOptions, error }) {
7
+ let formattedMessage;
8
+ if (message) {
9
+ const prefixedMessage = `${this.prefix(timestamp, loggerName)} ${message}`;
10
+ formattedMessage = this.colorMessage(prefixedMessage, logLevel);
11
+ }
12
+ const defaultInspectOptions = {
13
+ depth: 10,
14
+ colors: true,
15
+ compact: false,
16
+ breakLength: 80,
17
+ maxStringLength: 1000,
18
+ };
19
+ const formatObj = (o) => (0, util_1.inspect)(o, Object.assign(Object.assign({}, defaultInspectOptions), inspectOptions));
20
+ const logParts = [formattedMessage, obj && formatObj(obj), error && formatObj({ error })].filter(Boolean);
21
+ switch (logLevel) {
22
+ case 'info':
23
+ console.info(...logParts);
24
+ break;
25
+ case 'warn':
26
+ console.warn(...logParts);
27
+ break;
28
+ case 'error':
29
+ console.error(...logParts);
30
+ break;
31
+ default:
32
+ console.log(...logParts);
33
+ }
34
+ }
35
+ prefix(timestamp, loggerName) {
36
+ const formattedTimestamp = this.formatDate(timestamp);
37
+ const namePrefix = loggerName ? ` [${loggerName}]` : '';
38
+ return `${formattedTimestamp}${namePrefix}`;
39
+ }
40
+ formatDate(date) {
41
+ const pad = (num) => num.toString().padStart(2, '0');
42
+ const padMs = (num) => num.toString().padStart(3, '0');
43
+ const hours = date.getHours();
44
+ const minutes = pad(date.getMinutes());
45
+ const seconds = pad(date.getSeconds());
46
+ const milliseconds = padMs(date.getMilliseconds());
47
+ const ampm = hours >= 12 ? 'PM' : 'AM';
48
+ const formattedHours = hours % 12 || 12; // Convert to 12-hour format
49
+ return `${formattedHours}:${minutes}:${seconds}.${milliseconds} ${ampm}`;
50
+ }
51
+ colorMessage(message, logLevel) {
52
+ if (logLevel === 'info') {
53
+ return message;
54
+ }
55
+ const color = DevLogWriter.COLORS[logLevel === 'error' ? 'red' : logLevel === 'warn' ? 'yellow' : 'green'];
56
+ return `${color}${message}${DevLogWriter.COLORS.reset}`;
57
+ }
58
+ }
59
+ exports.DevLogWriter = DevLogWriter;
60
+ DevLogWriter.COLORS = {
61
+ reset: '\x1b[0m',
62
+ green: '\x1b[32m',
63
+ cyan: '\x1b[36m',
64
+ yellow: '\x1b[33m',
65
+ red: '\x1b[31m',
66
+ };
67
+ //# sourceMappingURL=DevLogWriter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DevLogWriter.js","sourceRoot":"","sources":["../../src/DevLogWriter.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AQ,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QAC3G,OAAO,GAAG,KAAK,GAAG,OAAO,GAAG,YAAY,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAC1D,CAAC;;AAtEH,oCAuEC;AAtEgB,mBAAM,GAAG;IACtB,KAAK,EAAE,SAAS;IAChB,KAAK,EAAE,UAAU;IACjB,IAAI,EAAE,UAAU;IAChB,MAAM,EAAE,UAAU;IAClB,GAAG,EAAE,UAAU;CAChB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
2
+ //# sourceMappingURL=LogLevel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LogLevel.d.ts","sourceRoot":"","sources":["../../src/LogLevel.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=LogLevel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LogLevel.js","sourceRoot":"","sources":["../../src/LogLevel.ts"],"names":[],"mappings":""}
@@ -0,0 +1,25 @@
1
+ /// <reference types="node" />
2
+ import { Loadable } from '@proteinjs/reflection';
3
+ import { LogLevel } from './LogLevel';
4
+ import { InspectOptions } from 'util';
5
+ export declare const getLogWriter: () => LogWriter;
6
+ export type Log = {
7
+ /** The name of the logger creating this log */
8
+ loggerName?: string;
9
+ /** The log level of this log */
10
+ logLevel: LogLevel;
11
+ /** The time the log was created */
12
+ timestamp: Date;
13
+ /** The log message */
14
+ message?: string;
15
+ /** The object being logged */
16
+ obj?: any;
17
+ /** The error being logged */
18
+ error?: Error;
19
+ /** Object formatting options */
20
+ inspectOptions?: InspectOptions;
21
+ };
22
+ export interface LogWriter extends Loadable {
23
+ write(log: Log): void;
24
+ }
25
+ //# sourceMappingURL=LogWriter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LogWriter.d.ts","sourceRoot":"","sources":["../../src/LogWriter.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAoB,MAAM,uBAAuB,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAEtC,eAAO,MAAM,YAAY,iBAAgF,CAAC;AAE1G,MAAM,MAAM,GAAG,GAAG;IAChB,+CAA+C;IAC/C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gCAAgC;IAChC,QAAQ,EAAE,QAAQ,CAAC;IACnB,mCAAmC;IACnC,SAAS,EAAE,IAAI,CAAC;IAChB,sBAAsB;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,8BAA8B;IAC9B,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,6BAA6B;IAC7B,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,gCAAgC;IAChC,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC,CAAC;AAEF,MAAM,WAAW,SAAU,SAAQ,QAAQ;IACzC,KAAK,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC;CACvB"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLogWriter = void 0;
4
+ const reflection_1 = require("@proteinjs/reflection");
5
+ const getLogWriter = () => reflection_1.SourceRepository.get().object('@proteinjs/logger/LogWriter');
6
+ exports.getLogWriter = getLogWriter;
7
+ //# sourceMappingURL=LogWriter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LogWriter.js","sourceRoot":"","sources":["../../src/LogWriter.ts"],"names":[],"mappings":";;;AAAA,sDAAmE;AAI5D,MAAM,YAAY,GAAG,GAAG,EAAE,CAAC,6BAAgB,CAAC,GAAG,EAAE,CAAC,MAAM,CAAY,6BAA6B,CAAC,CAAC;AAA7F,QAAA,YAAY,gBAAiF"}
@@ -0,0 +1,30 @@
1
+ /// <reference types="node" />
2
+ import { InspectOptions } from 'util';
3
+ import { LogLevel } from './LogLevel';
4
+ import { LogWriter } from './LogWriter';
5
+ type LoggerParams = {
6
+ name?: string;
7
+ logLevel?: LogLevel;
8
+ logWriter?: LogWriter;
9
+ };
10
+ type Log = {
11
+ message?: string;
12
+ obj?: any;
13
+ inspectOptions?: InspectOptions;
14
+ };
15
+ type ErrorLog = Log & {
16
+ error?: Error;
17
+ };
18
+ export declare class Logger {
19
+ private name?;
20
+ private logLevel;
21
+ private logWriter;
22
+ constructor({ name, logLevel, logWriter }: LoggerParams);
23
+ log({ message, obj, inspectOptions }: Log): void;
24
+ debug({ message, obj, inspectOptions }: Log): void;
25
+ info({ message, obj, inspectOptions }: Log): void;
26
+ warn({ message, obj, inspectOptions }: Log): void;
27
+ error({ message, obj, inspectOptions, error }: ErrorLog): void;
28
+ }
29
+ export {};
30
+ //# sourceMappingURL=Logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,KAAK,YAAY,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAAC,SAAS,CAAC,EAAE,SAAS,CAAA;CAAE,CAAC;AAClF,KAAK,GAAG,GAAG;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,GAAG,CAAC;IAAC,cAAc,CAAC,EAAE,cAAc,CAAA;CAAE,CAAC;AAC5E,KAAK,QAAQ,GAAG,GAAG,GAAG;IAAE,KAAK,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC;AAExC,qBAAa,MAAM;IACjB,OAAO,CAAC,IAAI,CAAC,CAAS;IACtB,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,SAAS,CAAY;gBAEjB,EAAE,IAAI,EAAE,QAAiB,EAAE,SAA8B,EAAE,EAAE,YAAY;IAMrF,GAAG,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,cAAc,EAAE,EAAE,GAAG;IAWzC,KAAK,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,cAAc,EAAE,EAAE,GAAG;IAe3C,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,cAAc,EAAE,EAAE,GAAG;IAe1C,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,cAAc,EAAE,EAAE,GAAG;IAe1C,KAAK,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,cAAc,EAAE,KAAK,EAAE,EAAE,QAAQ;CAWxD"}
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Logger = void 0;
4
+ const DevLogWriter_1 = require("./DevLogWriter");
5
+ class Logger {
6
+ constructor({ name, logLevel = 'info', logWriter = new DevLogWriter_1.DevLogWriter() }) {
7
+ this.name = name;
8
+ this.logLevel = logLevel;
9
+ this.logWriter = logWriter;
10
+ }
11
+ log({ message, obj, inspectOptions }) {
12
+ this.logWriter.write({
13
+ loggerName: this.name,
14
+ logLevel: 'info',
15
+ timestamp: new Date(),
16
+ message,
17
+ obj,
18
+ inspectOptions,
19
+ });
20
+ }
21
+ debug({ message, obj, inspectOptions }) {
22
+ if (this.logLevel == 'info' || this.logLevel == 'warn' || this.logLevel == 'error') {
23
+ return;
24
+ }
25
+ this.logWriter.write({
26
+ loggerName: this.name,
27
+ logLevel: 'debug',
28
+ timestamp: new Date(),
29
+ message,
30
+ obj,
31
+ inspectOptions,
32
+ });
33
+ }
34
+ info({ message, obj, inspectOptions }) {
35
+ if (this.logLevel == 'warn' || this.logLevel == 'error') {
36
+ return;
37
+ }
38
+ this.logWriter.write({
39
+ loggerName: this.name,
40
+ logLevel: 'info',
41
+ timestamp: new Date(),
42
+ message,
43
+ obj,
44
+ inspectOptions,
45
+ });
46
+ }
47
+ warn({ message, obj, inspectOptions }) {
48
+ if (this.logLevel == 'error') {
49
+ return;
50
+ }
51
+ this.logWriter.write({
52
+ loggerName: this.name,
53
+ logLevel: 'warn',
54
+ timestamp: new Date(),
55
+ message,
56
+ obj,
57
+ inspectOptions,
58
+ });
59
+ }
60
+ error({ message, obj, inspectOptions, error }) {
61
+ this.logWriter.write({
62
+ loggerName: this.name,
63
+ logLevel: 'error',
64
+ timestamp: new Date(),
65
+ message,
66
+ obj,
67
+ inspectOptions,
68
+ error,
69
+ });
70
+ }
71
+ }
72
+ exports.Logger = Logger;
73
+ //# sourceMappingURL=Logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Logger.js","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":";;;AAGA,iDAA8C;AAM9C,MAAa,MAAM;IAKjB,YAAY,EAAE,IAAI,EAAE,QAAQ,GAAG,MAAM,EAAE,SAAS,GAAG,IAAI,2BAAY,EAAE,EAAgB;QACnF,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED,GAAG,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,cAAc,EAAO;QACvC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;YACnB,UAAU,EAAE,IAAI,CAAC,IAAI;YACrB,QAAQ,EAAE,MAAM;YAChB,SAAS,EAAE,IAAI,IAAI,EAAE;YACrB,OAAO;YACP,GAAG;YACH,cAAc;SAC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UAAU,EAAE,IAAI,CAAC,IAAI;YACrB,QAAQ,EAAE,OAAO;YACjB,SAAS,EAAE,IAAI,IAAI,EAAE;YACrB,OAAO;YACP,GAAG;YACH,cAAc;YACd,KAAK;SACN,CAAC,CAAC;IACL,CAAC;CACF;AA9ED,wBA8EC"}
@@ -0,0 +1,19 @@
1
+ /** Load Dependency Source Graphs */
2
+
3
+ import '@proteinjs/reflection';
4
+
5
+ /** Generate Source Graph */
6
+
7
+ const sourceGraph =
8
+ '{"options":{"directed":true,"multigraph":false,"compound":false},"nodes":[{"v":"/\'debug\' | \'info\' | \'warn\' | \'error\'"},{"v":"@proteinjs/logger/LogWriter","value":{"packageName":"@proteinjs/logger","name":"LogWriter","filePath":"/home/runner/work/util/util/packages/logger/src/LogWriter.ts","qualifiedName":"@proteinjs/logger/LogWriter","properties":[],"methods":[{"name":"write","returnType":{"packageName":"","name":"void","filePath":null,"qualifiedName":"/void","typeParameters":null,"directParents":null},"isAsync":false,"isOptional":false,"isAbstract":true,"isStatic":false,"visibility":"public","parameters":[{"name":"log","type":{"packageName":"@proteinjs/logger","name":"Log","filePath":null,"qualifiedName":"@proteinjs/logger/Log","typeParameters":null,"directParents":null}}]}],"typeParameters":[],"directParents":[{"packageName":"@proteinjs/reflection","name":"Loadable","filePath":null,"qualifiedName":"@proteinjs/reflection/Loadable","properties":[],"methods":[],"typeParameters":[],"directParents":[]}],"sourceType":3}},{"v":"@proteinjs/reflection/Loadable"}],"edges":[{"v":"@proteinjs/logger/LogWriter","w":"@proteinjs/reflection/Loadable","value":"extends interface"}]}';
9
+
10
+ /** Generate Source Links */
11
+
12
+ const sourceLinks = {};
13
+
14
+ /** Load Source Graph and Links */
15
+
16
+ import { SourceRepository } from '@proteinjs/reflection';
17
+ SourceRepository.merge(sourceGraph, sourceLinks);
18
+
19
+ export * from '../index';
package/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './src/Logger';
2
+ export * from './src/LogLevel';
3
+ export * from './src/LogWriter';
4
+ export * from './src/DevLogWriter';
package/jest.config.js ADDED
@@ -0,0 +1,9 @@
1
+ module.exports = {
2
+ roots: ['<rootDir>/test'],
3
+ transform: {
4
+ '^.+\\.tsx?$': 'ts-jest',
5
+ },
6
+ testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
7
+ moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
8
+ testEnvironment: 'node',
9
+ };
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@proteinjs/logger",
3
+ "version": "1.0.1",
4
+ "description": "A simple logger",
5
+ "main": "./dist/generated/index.js",
6
+ "types": "./dist/generated/index.d.ts",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/proteinjs/util.git"
13
+ },
14
+ "bugs": {
15
+ "url": "https://github.com/proteinjs/util/issues"
16
+ },
17
+ "homepage": "https://github.com/proteinjs/util#readme",
18
+ "author": "Brent Bahry",
19
+ "license": "MIT",
20
+ "scripts": {
21
+ "clean": "rm -rf dist/ generated/ node_modules/",
22
+ "build": "reflection-build && tsc",
23
+ "watch": "reflection-watch"
24
+ },
25
+ "dependencies": {
26
+ "@proteinjs/reflection": "1.1.8"
27
+ },
28
+ "devDependencies": {
29
+ "@proteinjs/reflection-build": "1.0.23",
30
+ "@types/jest": "29.5.5",
31
+ "@types/node": "20.8.2",
32
+ "@typescript-eslint/eslint-plugin": "7.8.0",
33
+ "@typescript-eslint/parser": "7.8.0",
34
+ "eslint": "8.57.0",
35
+ "eslint-config-prettier": "9.1.0",
36
+ "eslint-plugin-prettier": "5.1.3",
37
+ "jest": "29.7.0",
38
+ "ts-jest": "29.1.1",
39
+ "typescript": "5.2.2"
40
+ },
41
+ "gitHead": "f14c87eefacbcfcb708dbaf711316519482a8923"
42
+ }
@@ -0,0 +1,76 @@
1
+ import { inspect, InspectOptions } from 'util';
2
+ import { LogLevel } from './LogLevel';
3
+ import { Log } from './LogWriter';
4
+
5
+ export class DevLogWriter {
6
+ private static COLORS = {
7
+ reset: '\x1b[0m',
8
+ green: '\x1b[32m',
9
+ cyan: '\x1b[36m',
10
+ yellow: '\x1b[33m',
11
+ red: '\x1b[31m',
12
+ };
13
+
14
+ write({ loggerName, logLevel, timestamp, message, obj, inspectOptions, error }: Log): void {
15
+ let formattedMessage: string | undefined;
16
+ if (message) {
17
+ const prefixedMessage = `${this.prefix(timestamp, loggerName)} ${message}`;
18
+ formattedMessage = this.colorMessage(prefixedMessage, logLevel);
19
+ }
20
+
21
+ const defaultInspectOptions: InspectOptions = {
22
+ depth: 10,
23
+ colors: true,
24
+ compact: false,
25
+ breakLength: 80,
26
+ maxStringLength: 1000,
27
+ };
28
+
29
+ const formatObj = (o: any) => inspect(o, { ...defaultInspectOptions, ...inspectOptions });
30
+
31
+ const logParts = [formattedMessage, obj && formatObj(obj), error && formatObj({ error })].filter(Boolean);
32
+
33
+ switch (logLevel) {
34
+ case 'info':
35
+ console.info(...logParts);
36
+ break;
37
+ case 'warn':
38
+ console.warn(...logParts);
39
+ break;
40
+ case 'error':
41
+ console.error(...logParts);
42
+ break;
43
+ default:
44
+ console.log(...logParts);
45
+ }
46
+ }
47
+
48
+ private prefix(timestamp: Date, loggerName?: string) {
49
+ const formattedTimestamp = this.formatDate(timestamp);
50
+ const namePrefix = loggerName ? ` [${loggerName}]` : '';
51
+ return `${formattedTimestamp}${namePrefix}`;
52
+ }
53
+
54
+ private formatDate(date: Date) {
55
+ const pad = (num: number) => num.toString().padStart(2, '0');
56
+ const padMs = (num: number) => num.toString().padStart(3, '0');
57
+
58
+ const hours = date.getHours();
59
+ const minutes = pad(date.getMinutes());
60
+ const seconds = pad(date.getSeconds());
61
+ const milliseconds = padMs(date.getMilliseconds());
62
+ const ampm = hours >= 12 ? 'PM' : 'AM';
63
+ const formattedHours = hours % 12 || 12; // Convert to 12-hour format
64
+
65
+ return `${formattedHours}:${minutes}:${seconds}.${milliseconds} ${ampm}`;
66
+ }
67
+
68
+ private colorMessage(message: string, logLevel: LogLevel) {
69
+ if (logLevel === 'info') {
70
+ return message;
71
+ }
72
+
73
+ const color = DevLogWriter.COLORS[logLevel === 'error' ? 'red' : logLevel === 'warn' ? 'yellow' : 'green'];
74
+ return `${color}${message}${DevLogWriter.COLORS.reset}`;
75
+ }
76
+ }
@@ -0,0 +1 @@
1
+ export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
@@ -0,0 +1,26 @@
1
+ import { Loadable, SourceRepository } from '@proteinjs/reflection';
2
+ import { LogLevel } from './LogLevel';
3
+ import { InspectOptions } from 'util';
4
+
5
+ export const getLogWriter = () => SourceRepository.get().object<LogWriter>('@proteinjs/logger/LogWriter');
6
+
7
+ export type Log = {
8
+ /** The name of the logger creating this log */
9
+ loggerName?: string;
10
+ /** The log level of this log */
11
+ logLevel: LogLevel;
12
+ /** The time the log was created */
13
+ timestamp: Date;
14
+ /** The log message */
15
+ message?: string;
16
+ /** The object being logged */
17
+ obj?: any;
18
+ /** The error being logged */
19
+ error?: Error;
20
+ /** Object formatting options */
21
+ inspectOptions?: InspectOptions;
22
+ };
23
+
24
+ export interface LogWriter extends Loadable {
25
+ write(log: Log): void;
26
+ }
package/src/Logger.ts ADDED
@@ -0,0 +1,88 @@
1
+ import { InspectOptions } from 'util';
2
+ import { LogLevel } from './LogLevel';
3
+ import { LogWriter } from './LogWriter';
4
+ import { DevLogWriter } from './DevLogWriter';
5
+
6
+ type LoggerParams = { name?: string; logLevel?: LogLevel; logWriter?: LogWriter };
7
+ type Log = { message?: string; obj?: any; inspectOptions?: InspectOptions };
8
+ type ErrorLog = Log & { error?: Error };
9
+
10
+ export class Logger {
11
+ private name?: string;
12
+ private logLevel: LogLevel;
13
+ private logWriter: LogWriter;
14
+
15
+ constructor({ name, logLevel = 'info', logWriter = new DevLogWriter() }: LoggerParams) {
16
+ this.name = name;
17
+ this.logLevel = logLevel;
18
+ this.logWriter = logWriter;
19
+ }
20
+
21
+ log({ message, obj, inspectOptions }: Log) {
22
+ this.logWriter.write({
23
+ loggerName: this.name,
24
+ logLevel: 'info',
25
+ timestamp: new Date(),
26
+ message,
27
+ obj,
28
+ inspectOptions,
29
+ });
30
+ }
31
+
32
+ debug({ message, obj, inspectOptions }: Log) {
33
+ if (this.logLevel == 'info' || this.logLevel == 'warn' || this.logLevel == 'error') {
34
+ return;
35
+ }
36
+
37
+ this.logWriter.write({
38
+ loggerName: this.name,
39
+ logLevel: 'debug',
40
+ timestamp: new Date(),
41
+ message,
42
+ obj,
43
+ inspectOptions,
44
+ });
45
+ }
46
+
47
+ info({ message, obj, inspectOptions }: Log) {
48
+ if (this.logLevel == 'warn' || this.logLevel == 'error') {
49
+ return;
50
+ }
51
+
52
+ this.logWriter.write({
53
+ loggerName: this.name,
54
+ logLevel: 'info',
55
+ timestamp: new Date(),
56
+ message,
57
+ obj,
58
+ inspectOptions,
59
+ });
60
+ }
61
+
62
+ warn({ message, obj, inspectOptions }: Log) {
63
+ if (this.logLevel == 'error') {
64
+ return;
65
+ }
66
+
67
+ this.logWriter.write({
68
+ loggerName: this.name,
69
+ logLevel: 'warn',
70
+ timestamp: new Date(),
71
+ message,
72
+ obj,
73
+ inspectOptions,
74
+ });
75
+ }
76
+
77
+ error({ message, obj, inspectOptions, error }: ErrorLog) {
78
+ this.logWriter.write({
79
+ loggerName: this.name,
80
+ logLevel: 'error',
81
+ timestamp: new Date(),
82
+ message,
83
+ obj,
84
+ inspectOptions,
85
+ error,
86
+ });
87
+ }
88
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "compilerOptions": {
3
+ "rootDir": "./",
4
+ "target": "es6",
5
+ "module": "commonjs",
6
+ "declaration": true,
7
+ "declarationMap": true,
8
+ "sourceMap": true,
9
+ "outDir": "./dist/",
10
+ "strict": true,
11
+ "noImplicitAny": true,
12
+ "esModuleInterop": true,
13
+ "skipLibCheck": true,
14
+ "forceConsistentCasingInFileNames": true,
15
+ "resolveJsonModule": true,
16
+ "jsx": "react"
17
+ }
18
+ }