@sjts/lib-log 31.1.7 → 31.2.0

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.
@@ -0,0 +1,19 @@
1
+ import { Logger } from './Logger.js';
2
+ type ConstructorOf<CLASS> = new (...params: any[]) => CLASS;
3
+ export type WithLogging = {
4
+ logPrefix: string;
5
+ $$shout(msg: string, data?: any): void;
6
+ $$info(msg: string, data?: any): void;
7
+ $$warn(msg: string, data?: any): void;
8
+ $$error(msg: string, data?: any): void;
9
+ $$debug(msg: string, data?: any): void;
10
+ $$startProfiling(key: string): void;
11
+ $$stopProfiling(key: string): void;
12
+ };
13
+ export type WithLoggingable = {
14
+ logPrefix: string;
15
+ logger: Logger;
16
+ };
17
+ export declare const WithLoggingMixin: () => <T extends WithLoggingable>(Base: ConstructorOf<T>) => ConstructorOf<WithLogging & T>;
18
+ export {};
19
+ //# sourceMappingURL=WithLogging.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WithLogging.d.ts","sourceRoot":"","sources":["../src/WithLogging.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,KAAK,aAAa,CAAC,KAAK,IAAI,KAAK,GAAG,MAAM,EAAE,GAAG,EAAE,KAAK,KAAK,CAAA;AAG3D,MAAM,MAAM,WAAW,GAAG;IACzB,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI,CAAA;IACtC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI,CAAA;IACrC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI,CAAA;IACrC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI,CAAA;IACtC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI,CAAA;IACtC,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;IACnC,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;CAClC,CAAA;AAGD,MAAM,MAAM,eAAe,GAAG;IAC7B,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;CACd,CAAA;AAGD,eAAO,MAAM,gBAAgB,SAE3B,CAAC,SAAS,eAAe,EAAE,MAAM,aAAa,CAAC,CAAC,CAAC,KA0BtB,aAAa,CAAC,WAAW,GAAG,CAAC,CACxD,CAAA"}
@@ -0,0 +1,29 @@
1
+ // The mixin function
2
+ export const WithLoggingMixin = () => (Base) => {
3
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
4
+ // @ts-ignore
5
+ class WithLoggingClass extends Base {
6
+ $$shout(msg, data) {
7
+ this.logger.shout(`${this.logPrefix} - ${msg}`, data);
8
+ }
9
+ $$info(msg, data) {
10
+ this.logger.info(`${this.logPrefix} - ${msg}`, data);
11
+ }
12
+ $$warn(msg, data) {
13
+ this.logger.warn(`${this.logPrefix} - ${msg}`, data);
14
+ }
15
+ $$error(msg, data) {
16
+ this.logger.error(`${this.logPrefix} - ${msg}`, data);
17
+ }
18
+ $$debug(msg, data) {
19
+ this.logger.debug(`${this.logPrefix} - ${msg}`, data);
20
+ }
21
+ $$startProfiling(key) {
22
+ this.logger.startProfiling(key);
23
+ }
24
+ $$stopProfiling(key) {
25
+ this.logger.stopProfiling(key);
26
+ }
27
+ }
28
+ return WithLoggingClass;
29
+ };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './Logger.js';
2
2
  export * from './LoggerLevel.js';
3
+ export * from './WithLogging.js';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA"}
package/dist/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './Logger.js';
2
2
  export * from './LoggerLevel.js';
3
+ export * from './WithLogging.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sjts/lib-log",
3
3
  "description": "The Steve James Typescript Log package",
4
- "version": "31.1.7",
4
+ "version": "31.2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "prettier": "@sjts/lib-devops/prettier.json",
26
26
  "devDependencies": {
27
- "@sjts/lib-devops": "31.1.1",
27
+ "@sjts/lib-devops": "31.2.0",
28
28
  "tsx": "^4.20.6",
29
29
  "typescript": "^5.8.3"
30
30
  },
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=Logger.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Logger.test.d.ts","sourceRoot":"","sources":["../src/Logger.test.ts"],"names":[],"mappings":""}
@@ -1,15 +0,0 @@
1
- import { Logger } from './Logger';
2
- const test = () => {
3
- Logger.startProfiling('Speed Test');
4
- Logger.info('ABC');
5
- Logger.startProfiling('Something');
6
- Logger.info('DEF');
7
- Logger.debug('GHI');
8
- Logger.stopProfiling('Something');
9
- Logger.info('JKL');
10
- Logger.startProfiling('Something Else');
11
- Logger.stopProfiling('Something Else');
12
- Logger.stopProfiling('Speed Test');
13
- return 100;
14
- };
15
- test();
@@ -1,11 +0,0 @@
1
- export type ProfilerOptions = {
2
- logAtStart?: boolean;
3
- };
4
- export declare class Profiler {
5
- private label;
6
- private o;
7
- private startTime;
8
- constructor(label: string, o?: ProfilerOptions);
9
- stop(): void;
10
- }
11
- //# sourceMappingURL=Profiler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Profiler.d.ts","sourceRoot":"","sources":["../src/Profiler.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,eAAe,GAAG;IAC7B,UAAU,CAAC,EAAE,OAAO,CAAA;CACpB,CAAA;AAED,qBAAa,QAAQ;IAInB,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,CAAC;IAJV,OAAO,CAAC,SAAS,CAAQ;gBAGhB,KAAK,EAAE,MAAM,EACb,CAAC,GAAE,eAAuC;IAUnD,IAAI;CAUJ"}
package/dist/Profiler.js DELETED
@@ -1,25 +0,0 @@
1
- import { DateTime } from 'luxon';
2
- import { Logger } from './Logger';
3
- export class Profiler {
4
- label;
5
- o;
6
- startTime;
7
- constructor(label, o = { logAtStart: false }) {
8
- this.label = label;
9
- this.o = o;
10
- this.label = label;
11
- this.startTime = DateTime.now().toMillis();
12
- if (o.logAtStart) {
13
- Logger.info(`${label}`);
14
- Logger.indent();
15
- }
16
- }
17
- stop() {
18
- const endTime = Date.now();
19
- const duration = endTime - this.startTime;
20
- if (this.o.logAtStart) {
21
- Logger.outdent();
22
- }
23
- Logger.info(`${this.label} - ${duration}ms`);
24
- }
25
- }