@proteinjs/logger 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/CHANGELOG.md CHANGED
@@ -3,6 +3,28 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.0.3](https://github.com/proteinjs/util/compare/@proteinjs/logger@1.0.2...@proteinjs/logger@1.0.3) (2024-08-13)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * `Logger` now queries the `SourceRepository` for a `DefaultLogWriter` lazily. This way, if a `Logger` happens to be instantiated outside of a function or class, it will still be able to get the `DefaultLogWriter` if logging is done within a function or class. ([f9e0e90](https://github.com/proteinjs/util/commit/f9e0e9008e8f13543adef27500142b91bc959c5f))
12
+
13
+
14
+
15
+
16
+
17
+ ## [1.0.2](https://github.com/proteinjs/util/compare/@proteinjs/logger@1.0.1...@proteinjs/logger@1.0.2) (2024-08-13)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * `Logger` constructor arg now optional ([c85e337](https://github.com/proteinjs/util/commit/c85e3375d6a299d3d0b72fb0ba6d058e7798ab79))
23
+
24
+
25
+
26
+
27
+
6
28
  ## 1.0.1 (2024-08-13)
7
29
 
8
30
  **Note:** Version bump only for package @proteinjs/logger
@@ -17,7 +17,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  require("@proteinjs/reflection");
19
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\"}]}";
20
+ const sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"@proteinjs/logger/DefaultLogWriter\",\"value\":{\"packageName\":\"@proteinjs/logger\",\"name\":\"DefaultLogWriter\",\"filePath\":\"/home/runner/work/util/util/packages/logger/src/DefaultLogWriter.ts\",\"qualifiedName\":\"@proteinjs/logger/DefaultLogWriter\",\"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\"},{\"v\":\"/'debug' | 'info' | 'warn' | 'error'\"}],\"edges\":[{\"v\":\"@proteinjs/logger/DefaultLogWriter\",\"w\":\"@proteinjs/reflection/Loadable\",\"value\":\"extends interface\"}]}";
21
21
  /** Generate Source Links */
22
22
  const sourceLinks = {};
23
23
  /** Load Source Graph and Links */
@@ -1 +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"}
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,y1CAAy1C,CAAC;AAG92C,4BAA4B;AAG5B,MAAM,WAAW,GAAG,EACnB,CAAC;AAGF,kCAAkC;AAElC,sDAAyD;AACzD,6BAAgB,CAAC,KAAK,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;AAGjD,2CAAyB"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from './src/Logger';
2
2
  export * from './src/LogLevel';
3
- export * from './src/LogWriter';
3
+ export * from './src/DefaultLogWriter';
4
4
  export * from './src/DevLogWriter';
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC"}
package/dist/index.js CHANGED
@@ -16,6 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./src/Logger"), exports);
18
18
  __exportStar(require("./src/LogLevel"), exports);
19
- __exportStar(require("./src/LogWriter"), exports);
19
+ __exportStar(require("./src/DefaultLogWriter"), exports);
20
20
  __exportStar(require("./src/DevLogWriter"), exports);
21
21
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,iDAA+B;AAC/B,kDAAgC;AAChC,qDAAmC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,iDAA+B;AAC/B,yDAAuC;AACvC,qDAAmC"}
@@ -2,7 +2,7 @@
2
2
  import { Loadable } from '@proteinjs/reflection';
3
3
  import { LogLevel } from './LogLevel';
4
4
  import { InspectOptions } from 'util';
5
- export declare const getLogWriter: () => LogWriter;
5
+ export declare const getDefaultLogWriter: () => DefaultLogWriter;
6
6
  export type Log = {
7
7
  /** The name of the logger creating this log */
8
8
  loggerName?: string;
@@ -19,7 +19,17 @@ export type Log = {
19
19
  /** Object formatting options */
20
20
  inspectOptions?: InspectOptions;
21
21
  };
22
- export interface LogWriter extends Loadable {
22
+ /**
23
+ * Every `Logger` instance will use the implementation of `DefaultLogWriter` unless
24
+ * a log writer is explicitly passed in when instantiating `Logger`.
25
+ *
26
+ * If this is not implemented, and no `LogWriter` is passed into `Logger`, `Logger`
27
+ * will default to using `DevLogWriter`.
28
+ *
29
+ * Note: this should only be implemented once. If there are multiple implementations,
30
+ * `Logger` will choose the first one that shows up in the package dependency tree.
31
+ * */
32
+ export interface DefaultLogWriter extends Loadable {
23
33
  write(log: Log): void;
24
34
  }
25
- //# sourceMappingURL=LogWriter.d.ts.map
35
+ //# sourceMappingURL=DefaultLogWriter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DefaultLogWriter.d.ts","sourceRoot":"","sources":["../../src/DefaultLogWriter.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,mBAAmB,wBACuD,CAAC;AAExF,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;;;;;;;;;KASK;AACL,MAAM,WAAW,gBAAiB,SAAQ,QAAQ;IAChD,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.getDefaultLogWriter = void 0;
4
+ const reflection_1 = require("@proteinjs/reflection");
5
+ const getDefaultLogWriter = () => reflection_1.SourceRepository.get().object('@proteinjs/logger/DefaultLogWriter');
6
+ exports.getDefaultLogWriter = getDefaultLogWriter;
7
+ //# sourceMappingURL=DefaultLogWriter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DefaultLogWriter.js","sourceRoot":"","sources":["../../src/DefaultLogWriter.ts"],"names":[],"mappings":";;;AAAA,sDAAmE;AAI5D,MAAM,mBAAmB,GAAG,GAAG,EAAE,CACtC,6BAAgB,CAAC,GAAG,EAAE,CAAC,MAAM,CAAmB,oCAAoC,CAAC,CAAC;AAD3E,QAAA,mBAAmB,uBACwD"}
@@ -1,4 +1,4 @@
1
- import { Log } from './LogWriter';
1
+ import { Log } from './DefaultLogWriter';
2
2
  export declare class DevLogWriter {
3
3
  private static COLORS;
4
4
  write({ loggerName, logLevel, timestamp, message, obj, inspectOptions, error }: Log): void;
@@ -1 +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"}
1
+ {"version":3,"file":"DevLogWriter.d.ts","sourceRoot":"","sources":["../../src/DevLogWriter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAEzC,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"}
@@ -1,11 +1,11 @@
1
1
  /// <reference types="node" />
2
2
  import { InspectOptions } from 'util';
3
3
  import { LogLevel } from './LogLevel';
4
- import { LogWriter } from './LogWriter';
4
+ import { DefaultLogWriter } from './DefaultLogWriter';
5
5
  type LoggerParams = {
6
6
  name?: string;
7
7
  logLevel?: LogLevel;
8
- logWriter?: LogWriter;
8
+ logWriter?: DefaultLogWriter;
9
9
  };
10
10
  type Log = {
11
11
  message?: string;
@@ -18,8 +18,9 @@ type ErrorLog = Log & {
18
18
  export declare class Logger {
19
19
  private name?;
20
20
  private logLevel;
21
- private logWriter;
22
- constructor({ name, logLevel, logWriter }: LoggerParams);
21
+ private logWriter?;
22
+ constructor({ name, logLevel, logWriter }?: LoggerParams);
23
+ private getLogWriter;
23
24
  log({ message, obj, inspectOptions }: Log): void;
24
25
  debug({ message, obj, inspectOptions }: Log): void;
25
26
  info({ message, obj, inspectOptions }: Log): void;
@@ -1 +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,OA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G,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,CAAC,CAAmB;gBAEzB,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAE,YAAiB;IAQ5D,OAAO,CAAC,YAAY;IAQpB,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"}
@@ -1,15 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Logger = void 0;
4
+ const DefaultLogWriter_1 = require("./DefaultLogWriter");
4
5
  const DevLogWriter_1 = require("./DevLogWriter");
5
6
  class Logger {
6
- constructor({ name, logLevel = 'info', logWriter = new DevLogWriter_1.DevLogWriter() }) {
7
- this.name = name;
8
- this.logLevel = logLevel;
7
+ constructor({ name, logLevel, logWriter } = {}) {
8
+ if (name) {
9
+ this.name = name;
10
+ }
11
+ this.logLevel = logLevel !== null && logLevel !== void 0 ? logLevel : 'info';
9
12
  this.logWriter = logWriter;
10
13
  }
14
+ getLogWriter() {
15
+ var _a;
16
+ if (!this.logWriter) {
17
+ this.logWriter = (_a = (0, DefaultLogWriter_1.getDefaultLogWriter)()) !== null && _a !== void 0 ? _a : new DevLogWriter_1.DevLogWriter();
18
+ }
19
+ return this.logWriter;
20
+ }
11
21
  log({ message, obj, inspectOptions }) {
12
- this.logWriter.write({
22
+ this.getLogWriter().write({
13
23
  loggerName: this.name,
14
24
  logLevel: 'info',
15
25
  timestamp: new Date(),
@@ -22,7 +32,7 @@ class Logger {
22
32
  if (this.logLevel == 'info' || this.logLevel == 'warn' || this.logLevel == 'error') {
23
33
  return;
24
34
  }
25
- this.logWriter.write({
35
+ this.getLogWriter().write({
26
36
  loggerName: this.name,
27
37
  logLevel: 'debug',
28
38
  timestamp: new Date(),
@@ -35,7 +45,7 @@ class Logger {
35
45
  if (this.logLevel == 'warn' || this.logLevel == 'error') {
36
46
  return;
37
47
  }
38
- this.logWriter.write({
48
+ this.getLogWriter().write({
39
49
  loggerName: this.name,
40
50
  logLevel: 'info',
41
51
  timestamp: new Date(),
@@ -48,7 +58,7 @@ class Logger {
48
58
  if (this.logLevel == 'error') {
49
59
  return;
50
60
  }
51
- this.logWriter.write({
61
+ this.getLogWriter().write({
52
62
  loggerName: this.name,
53
63
  logLevel: 'warn',
54
64
  timestamp: new Date(),
@@ -58,7 +68,7 @@ class Logger {
58
68
  });
59
69
  }
60
70
  error({ message, obj, inspectOptions, error }) {
61
- this.logWriter.write({
71
+ this.getLogWriter().write({
62
72
  loggerName: this.name,
63
73
  logLevel: 'error',
64
74
  timestamp: new Date(),
@@ -1 +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,S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E,KAAK,EAAY;QACrD,IAAI,CAAC,YAAY,EAAE,CAAC,KAAK,CAAC;YACxB,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;AAxFD,wBAwFC"}
@@ -5,7 +5,7 @@ import '@proteinjs/reflection';
5
5
  /** Generate Source Graph */
6
6
 
7
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"}]}';
8
+ '{"options":{"directed":true,"multigraph":false,"compound":false},"nodes":[{"v":"@proteinjs/logger/DefaultLogWriter","value":{"packageName":"@proteinjs/logger","name":"DefaultLogWriter","filePath":"/home/runner/work/util/util/packages/logger/src/DefaultLogWriter.ts","qualifiedName":"@proteinjs/logger/DefaultLogWriter","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"},{"v":"/\'debug\' | \'info\' | \'warn\' | \'error\'"}],"edges":[{"v":"@proteinjs/logger/DefaultLogWriter","w":"@proteinjs/reflection/Loadable","value":"extends interface"}]}';
9
9
 
10
10
  /** Generate Source Links */
11
11
 
package/index.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './src/Logger';
2
2
  export * from './src/LogLevel';
3
- export * from './src/LogWriter';
3
+ export * from './src/DefaultLogWriter';
4
4
  export * from './src/DevLogWriter';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proteinjs/logger",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "A simple logger",
5
5
  "main": "./dist/generated/index.js",
6
6
  "types": "./dist/generated/index.d.ts",
@@ -38,5 +38,5 @@
38
38
  "ts-jest": "29.1.1",
39
39
  "typescript": "5.2.2"
40
40
  },
41
- "gitHead": "f14c87eefacbcfcb708dbaf711316519482a8923"
41
+ "gitHead": "a5d651a78b57502774d7c20c59a1d6cbdb14470b"
42
42
  }
@@ -0,0 +1,37 @@
1
+ import { Loadable, SourceRepository } from '@proteinjs/reflection';
2
+ import { LogLevel } from './LogLevel';
3
+ import { InspectOptions } from 'util';
4
+
5
+ export const getDefaultLogWriter = () =>
6
+ SourceRepository.get().object<DefaultLogWriter>('@proteinjs/logger/DefaultLogWriter');
7
+
8
+ export type Log = {
9
+ /** The name of the logger creating this log */
10
+ loggerName?: string;
11
+ /** The log level of this log */
12
+ logLevel: LogLevel;
13
+ /** The time the log was created */
14
+ timestamp: Date;
15
+ /** The log message */
16
+ message?: string;
17
+ /** The object being logged */
18
+ obj?: any;
19
+ /** The error being logged */
20
+ error?: Error;
21
+ /** Object formatting options */
22
+ inspectOptions?: InspectOptions;
23
+ };
24
+
25
+ /**
26
+ * Every `Logger` instance will use the implementation of `DefaultLogWriter` unless
27
+ * a log writer is explicitly passed in when instantiating `Logger`.
28
+ *
29
+ * If this is not implemented, and no `LogWriter` is passed into `Logger`, `Logger`
30
+ * will default to using `DevLogWriter`.
31
+ *
32
+ * Note: this should only be implemented once. If there are multiple implementations,
33
+ * `Logger` will choose the first one that shows up in the package dependency tree.
34
+ * */
35
+ export interface DefaultLogWriter extends Loadable {
36
+ write(log: Log): void;
37
+ }
@@ -1,6 +1,6 @@
1
1
  import { inspect, InspectOptions } from 'util';
2
2
  import { LogLevel } from './LogLevel';
3
- import { Log } from './LogWriter';
3
+ import { Log } from './DefaultLogWriter';
4
4
 
5
5
  export class DevLogWriter {
6
6
  private static COLORS = {
package/src/Logger.ts CHANGED
@@ -1,25 +1,35 @@
1
1
  import { InspectOptions } from 'util';
2
2
  import { LogLevel } from './LogLevel';
3
- import { LogWriter } from './LogWriter';
3
+ import { getDefaultLogWriter, DefaultLogWriter } from './DefaultLogWriter';
4
4
  import { DevLogWriter } from './DevLogWriter';
5
5
 
6
- type LoggerParams = { name?: string; logLevel?: LogLevel; logWriter?: LogWriter };
6
+ type LoggerParams = { name?: string; logLevel?: LogLevel; logWriter?: DefaultLogWriter };
7
7
  type Log = { message?: string; obj?: any; inspectOptions?: InspectOptions };
8
8
  type ErrorLog = Log & { error?: Error };
9
9
 
10
10
  export class Logger {
11
11
  private name?: string;
12
12
  private logLevel: LogLevel;
13
- private logWriter: LogWriter;
13
+ private logWriter?: DefaultLogWriter;
14
14
 
15
- constructor({ name, logLevel = 'info', logWriter = new DevLogWriter() }: LoggerParams) {
16
- this.name = name;
17
- this.logLevel = logLevel;
15
+ constructor({ name, logLevel, logWriter }: LoggerParams = {}) {
16
+ if (name) {
17
+ this.name = name;
18
+ }
19
+ this.logLevel = logLevel ?? 'info';
18
20
  this.logWriter = logWriter;
19
21
  }
20
22
 
23
+ private getLogWriter() {
24
+ if (!this.logWriter) {
25
+ this.logWriter = getDefaultLogWriter() ?? new DevLogWriter();
26
+ }
27
+
28
+ return this.logWriter;
29
+ }
30
+
21
31
  log({ message, obj, inspectOptions }: Log) {
22
- this.logWriter.write({
32
+ this.getLogWriter().write({
23
33
  loggerName: this.name,
24
34
  logLevel: 'info',
25
35
  timestamp: new Date(),
@@ -34,7 +44,7 @@ export class Logger {
34
44
  return;
35
45
  }
36
46
 
37
- this.logWriter.write({
47
+ this.getLogWriter().write({
38
48
  loggerName: this.name,
39
49
  logLevel: 'debug',
40
50
  timestamp: new Date(),
@@ -49,7 +59,7 @@ export class Logger {
49
59
  return;
50
60
  }
51
61
 
52
- this.logWriter.write({
62
+ this.getLogWriter().write({
53
63
  loggerName: this.name,
54
64
  logLevel: 'info',
55
65
  timestamp: new Date(),
@@ -64,7 +74,7 @@ export class Logger {
64
74
  return;
65
75
  }
66
76
 
67
- this.logWriter.write({
77
+ this.getLogWriter().write({
68
78
  loggerName: this.name,
69
79
  logLevel: 'warn',
70
80
  timestamp: new Date(),
@@ -75,7 +85,7 @@ export class Logger {
75
85
  }
76
86
 
77
87
  error({ message, obj, inspectOptions, error }: ErrorLog) {
78
- this.logWriter.write({
88
+ this.getLogWriter().write({
79
89
  loggerName: this.name,
80
90
  logLevel: 'error',
81
91
  timestamp: new Date(),
@@ -1 +0,0 @@
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"}
@@ -1,7 +0,0 @@
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
@@ -1 +0,0 @@
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"}
package/src/LogWriter.ts DELETED
@@ -1,26 +0,0 @@
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
- }