@codeleap/logger 7.0.1 → 7.1.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/dist/lib/Logger.js +4 -1
- package/dist/lib/Logger.js.map +1 -1
- package/dist/lib/Slack.js +40 -39
- package/dist/lib/Slack.js.map +1 -1
- package/dist/lib/performance/errors.js +1 -2
- package/dist/lib/performance/errors.js.map +1 -1
- package/dist/lib/performance/index.js +62 -61
- package/dist/lib/performance/index.js.map +1 -1
- package/dist/utils/createLogger.js +1 -0
- package/dist/utils/createLogger.js.map +1 -1
- package/package.json +6 -6
package/dist/lib/Logger.js
CHANGED
|
@@ -8,6 +8,10 @@ import { PerformanceService } from './performance';
|
|
|
8
8
|
* `initialize` must be called once before `patchConsole` or any Slack/perf functionality works.
|
|
9
9
|
*/
|
|
10
10
|
export class Logger {
|
|
11
|
+
static initialized = false;
|
|
12
|
+
config;
|
|
13
|
+
slack;
|
|
14
|
+
perf;
|
|
11
15
|
isIgnored(args) {
|
|
12
16
|
if (!Logger.initialized)
|
|
13
17
|
return false;
|
|
@@ -73,7 +77,6 @@ export class Logger {
|
|
|
73
77
|
throw new Error('Logger: implement the method "debug"');
|
|
74
78
|
}
|
|
75
79
|
}
|
|
76
|
-
Logger.initialized = false;
|
|
77
80
|
/**
|
|
78
81
|
* Shared `Logger` instance. Logging methods throw until the consuming app replaces them via
|
|
79
82
|
* {@link createLogger} and calls {@link Logger.initialize}.
|
package/dist/lib/Logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Logger.js","sourceRoot":"","sources":["../../src/lib/Logger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAElD;;;;;;GAMG;AACH,MAAM,OAAO,MAAM;
|
|
1
|
+
{"version":3,"file":"Logger.js","sourceRoot":"","sources":["../../src/lib/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A;QAGpB,IAAI,CAAC,KAAK,GAAG,IAAI,YAAY,CAAC,MAAM,CAAC,CAAA;QAErC,IAAI,CAAC,IAAI,GAAG,IAAI,kBAAkB,CAAC,MAAM,CAAC,CAAA;QAE1C,MAAM,CAAC,WAAW,GAAG,IAAI,CAAA;IAC3B,CAAC;IAED;;;OAGG;IACH,IAAI,CAAC,GAAG,IAAe;QACrB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;IACxD,CAAC;IAED,iCAAiC;IACjC,IAAI,CAAC,GAAG,IAAe;QACrB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;IACxD,CAAC;IAED,iCAAiC;IACjC,KAAK,CAAC,GAAG,IAAe;QACtB,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAA;IACzD,CAAC;IAED,iCAAiC;IACjC,IAAI,CAAC,GAAG,IAAe;QACrB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;IACxD,CAAC;IAED,iCAAiC;IACjC,GAAG,CAAC,GAAG,IAAe;QACpB,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAA;IACvD,CAAC;IAED,iCAAiC;IACjC,KAAK,CAAC,GAAG,IAAe;QACtB,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAA;IACzD,CAAC;;AAGH;;;GAGG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,MAAM,EAAE,CAAA"}
|
package/dist/lib/Slack.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
/// <reference types="node" />
|
|
11
2
|
import { inspect } from 'util';
|
|
12
3
|
import { TypeGuards } from '@codeleap/types';
|
|
@@ -20,13 +11,13 @@ const DEFAULT_BASE_URL = 'https://slack.com/api/chat.postMessage';
|
|
|
20
11
|
* the current environment does not match the caller-supplied `sendIn` filter.
|
|
21
12
|
*/
|
|
22
13
|
export class SlackService {
|
|
14
|
+
config;
|
|
15
|
+
echoConfig;
|
|
16
|
+
isDev;
|
|
17
|
+
appName;
|
|
18
|
+
api;
|
|
23
19
|
constructor(config) {
|
|
24
20
|
this.config = config;
|
|
25
|
-
this.serializers = {
|
|
26
|
-
version: (IsDev) => {
|
|
27
|
-
return IsDev ? 'debug' : 'release';
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
21
|
this.echoConfig = config.Slack.echo;
|
|
31
22
|
this.isDev = config.Environment.IsDev;
|
|
32
23
|
this.appName = config.AppName;
|
|
@@ -50,29 +41,37 @@ export class SlackService {
|
|
|
50
41
|
*
|
|
51
42
|
* Failures are caught and logged to `console.error` rather than propagated.
|
|
52
43
|
*/
|
|
53
|
-
echo(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
}
|
|
44
|
+
async echo(label, slackData, moduleName = undefined, messageOptions = {}) {
|
|
45
|
+
const options = this.parseOptions(messageOptions);
|
|
46
|
+
const slack = this.parseData(label, slackData, options.info, moduleName);
|
|
47
|
+
const enabled = TypeGuards.isBoolean(this.echoConfig.enabled) ? this.echoConfig.enabled : true;
|
|
48
|
+
if (!options.send || !this.api || !this.echoConfig || !enabled)
|
|
49
|
+
return;
|
|
50
|
+
const settingsData = this?.echoConfig?.options ?? {};
|
|
51
|
+
try {
|
|
52
|
+
const data = {
|
|
53
|
+
'channel': this?.echoConfig?.channel ?? DEFAULT_CHANNEL,
|
|
54
|
+
'text': slack,
|
|
55
|
+
'username': `${this.appName} Log`,
|
|
56
|
+
'icon_url': this?.echoConfig?.icon,
|
|
57
|
+
...settingsData,
|
|
58
|
+
};
|
|
59
|
+
await this.api.post('', data, {
|
|
60
|
+
baseURL: this?.echoConfig?.baseURL ?? DEFAULT_BASE_URL,
|
|
61
|
+
headers: {
|
|
62
|
+
Authorization: `Bearer ${this?.echoConfig?.token}`,
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
catch (err) {
|
|
67
|
+
console.error('Failed to echo', err, 'logger echoSlack');
|
|
68
|
+
}
|
|
75
69
|
}
|
|
70
|
+
serializers = {
|
|
71
|
+
version: (IsDev) => {
|
|
72
|
+
return IsDev ? 'debug' : 'release';
|
|
73
|
+
},
|
|
74
|
+
};
|
|
76
75
|
parseOptions(options) {
|
|
77
76
|
const { sendIn = [], include = [], } = options;
|
|
78
77
|
const hasSendIn = sendIn.length >= 1;
|
|
@@ -87,8 +86,7 @@ export class SlackService {
|
|
|
87
86
|
let str = '';
|
|
88
87
|
const separator = ' - ';
|
|
89
88
|
include.forEach(k => {
|
|
90
|
-
|
|
91
|
-
const data = (_b = (_a = this.serializers)[k]) === null || _b === void 0 ? void 0 : _b.call(_a, this.isDev);
|
|
89
|
+
const data = this.serializers[k]?.(this.isDev);
|
|
92
90
|
str = `${str}${str.length > 0 ? separator : ''}[${data}]`;
|
|
93
91
|
});
|
|
94
92
|
return {
|
|
@@ -97,7 +95,10 @@ export class SlackService {
|
|
|
97
95
|
};
|
|
98
96
|
}
|
|
99
97
|
parseData(label, data, info, module) {
|
|
100
|
-
const obj = !info ? data :
|
|
98
|
+
const obj = !info ? data : {
|
|
99
|
+
...data,
|
|
100
|
+
info,
|
|
101
|
+
};
|
|
101
102
|
const args = [`${!module ? '' : `(${module}) `}${label}: `, obj];
|
|
102
103
|
const slack = args.map(i => {
|
|
103
104
|
if (typeof i === 'object') {
|
package/dist/lib/Slack.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Slack.js","sourceRoot":"","sources":["../../src/lib/Slack.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Slack.js","sourceRoot":"","sources":["../../src/lib/Slack.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAmB5C,MAAM,eAAe,GAAG,YAAY,CAAA;AAEpC,MAAM,gBAAgB,GAAG,wCAAwC,CAAA;AAEjE;;;;;;GAMG;AACH,MAAM,OAAO,YAAY;IASH;IARZ,UAAU,CAA+B;IAEzC,KAAK,CAAsC;IAE3C,OAAO,CAAyB;IAEhC,GAAG,CAAK;IAEhB,YAAoB,MAAoB;QAApB,WAAM,GAAN,MAAM,CAAc;QACtC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAA;QACnC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,KAAK,CAAA;QACrC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAA;IAC/B,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,OAAY;QACjB,IAAI,CAAC,GAAG,GAAG,OAAO,CAAA;IACpB,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,IAAI,CACR,KAAyB,EACzB,SAA4B,EAC5B,aAAkC,SAAS,EAC3C,iBAAuC,EAAE;QAEzC,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CA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CAAC,IAAI,CAAC,CAAC,CAAC;YACzB,GAAG,IAAI;YACP,IAAI;SACL,CAAA;QAED,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,MAAM,IAAI,GAAG,KAAK,IAAI,EAAE,GAAG,CAAC,CAAA;QAEhE,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;YACzB,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;gBAC1B,IAAI,CAAC;oBACH,OAAO,OAAO,CAAC,CAAC,EAAE;wBAChB,KAAK,EAAE,CAAC;wBACR,OAAO,EAAE,KAAK;wBACd,UAAU,EAAE,IAAI;qBACjB,CAAC,CAAA;gBACJ,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACX,OAAO,GAAG,CAAC,yBAAyB,CAAA;gBACtC,CAAC;YACH,CAAC;YAED,OAAO,MAAM,CAAC,CAAC,CAAC,CAAA;QAClB,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAEZ,OAAO,KAAK,CAAA;IACd,CAAC;CACF"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
const defineError = (errorName, args) => {
|
|
2
|
-
var _a;
|
|
3
2
|
switch (errorName) {
|
|
4
3
|
case 'maxRenders':
|
|
5
|
-
return `${args.name} is rendering more than ${args.maxRenders}time per ${(
|
|
4
|
+
return `${args.name} is rendering more than ${args.maxRenders}time per ${(args.throttleInterval ?? 0) / 1000}second!
|
|
6
5
|
If you aware of this, you can disable it in the Settings.ts > Performancer.
|
|
7
6
|
`;
|
|
8
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/lib/performance/errors.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,GAAG,CAAC,SAAqB,EAAE,IAAwB,EAAE,EAAE
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/lib/performance/errors.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,GAAG,CAAC,SAAqB,EAAE,IAAwB,EAAE,EAAE;IACtE,QAAQ,SAAS,EAAE,CAAC;QAClB,KAAK,YAAY;YACf,OAAO,GAAG,IAAI,CAAC,IAAI,2BAA2B,IAAI,CAAC,UAAU,YAC3D,CAAC,IAAI,CAAC,gBAAgB,IAAI,CAAC,CAAC,GAAG,IACjC;;OAEC,CAAA;IACL,CAAC;AACH,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzC,YAAY,SAAqB,EAAE,IAAwB;QACzD,KAAK,CAAC,WAAW,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAA;QACnC,IAAI,CAAC,IAAI,GAAG,eAAe,CAAA;IAC7B,CAAC;CACF"}
|
|
@@ -8,69 +8,70 @@ export * from './types';
|
|
|
8
8
|
* `config.Logger.performanceInspector.enabled` is `false`.
|
|
9
9
|
*/
|
|
10
10
|
export class PerformanceService {
|
|
11
|
+
config;
|
|
12
|
+
renderCounter = {};
|
|
11
13
|
constructor(config) {
|
|
12
14
|
this.config = config;
|
|
13
|
-
this.renderCounter = {};
|
|
14
|
-
/**
|
|
15
|
-
* Tracks render frequency for a component and warns when it exceeds the configured threshold.
|
|
16
|
-
*
|
|
17
|
-
* Call this at the top of a function component body (not inside a hook). By default it also
|
|
18
|
-
* registers mount/unmount effects via `useEffect` — pass `noHooks: true` to skip those when
|
|
19
|
-
* the component cannot accept additional hooks.
|
|
20
|
-
*
|
|
21
|
-
* When the accumulated render count within a `throttleInterval` window exceeds `maxRenders`,
|
|
22
|
-
* the counter resets and a {@link PerformanceError} is thrown (surfacing as a React error
|
|
23
|
-
* boundary hit rather than a silent warning).
|
|
24
|
-
*
|
|
25
|
-
* Components whose names start with any entry in
|
|
26
|
-
* `config.Logger.performanceInspector.blacklist` are silently skipped.
|
|
27
|
-
*
|
|
28
|
-
* Has no effect outside a dev environment or when the inspector is disabled in config.
|
|
29
|
-
*/
|
|
30
|
-
this.inspectRender = (name, options = {
|
|
31
|
-
noHooks: false,
|
|
32
|
-
logMode: 'summarized',
|
|
33
|
-
throttleInterval: 1000,
|
|
34
|
-
}) => {
|
|
35
|
-
const config = this.config.Logger.performanceInspector;
|
|
36
|
-
const blacklist = config.blacklist || [];
|
|
37
|
-
if (blacklist.some((item) => name.startsWith(item)))
|
|
38
|
-
return;
|
|
39
|
-
const { noHooks, logMode, throttleInterval, maxRenders = config.maxRenders } = options;
|
|
40
|
-
if (!config.enabled || !this.config.Environment.IsDev) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
if (!noHooks) {
|
|
44
|
-
useEffect(() => {
|
|
45
|
-
console.log(`[PerformanceInspector] Mounted -> ${name}`);
|
|
46
|
-
return () => {
|
|
47
|
-
console.log(`[PerformanceInspector] Unmounted -> ${name}`);
|
|
48
|
-
};
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
this.renderCounter[name] = this.renderCounter[name] ? this.renderCounter[name] + 1 : 1;
|
|
52
|
-
const renders = this.renderCounter[name];
|
|
53
|
-
if (renders > maxRenders) {
|
|
54
|
-
this.renderCounter[name] = 0;
|
|
55
|
-
throw new PerformanceError('maxRenders', {
|
|
56
|
-
name,
|
|
57
|
-
throttleInterval,
|
|
58
|
-
maxRenders,
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
if (logMode === 'raw') {
|
|
62
|
-
console.log(`[PerformanceInspector] Rendered -> ${name}: ${renders}`);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
function logSummary() {
|
|
66
|
-
if (renders <= 0)
|
|
67
|
-
return;
|
|
68
|
-
console.log(`[PerformanceInspector] Render summary -> ${name}: ${renders}`);
|
|
69
|
-
this.renderCounter[name] = 0;
|
|
70
|
-
}
|
|
71
|
-
// @ts-ignore
|
|
72
|
-
throttle(logSummary, name, throttleInterval);
|
|
73
|
-
};
|
|
74
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Tracks render frequency for a component and warns when it exceeds the configured threshold.
|
|
18
|
+
*
|
|
19
|
+
* Call this at the top of a function component body (not inside a hook). By default it also
|
|
20
|
+
* registers mount/unmount effects via `useEffect` — pass `noHooks: true` to skip those when
|
|
21
|
+
* the component cannot accept additional hooks.
|
|
22
|
+
*
|
|
23
|
+
* When the accumulated render count within a `throttleInterval` window exceeds `maxRenders`,
|
|
24
|
+
* the counter resets and a {@link PerformanceError} is thrown (surfacing as a React error
|
|
25
|
+
* boundary hit rather than a silent warning).
|
|
26
|
+
*
|
|
27
|
+
* Components whose names start with any entry in
|
|
28
|
+
* `config.Logger.performanceInspector.blacklist` are silently skipped.
|
|
29
|
+
*
|
|
30
|
+
* Has no effect outside a dev environment or when the inspector is disabled in config.
|
|
31
|
+
*/
|
|
32
|
+
inspectRender = (name, options = {
|
|
33
|
+
noHooks: false,
|
|
34
|
+
logMode: 'summarized',
|
|
35
|
+
throttleInterval: 1000,
|
|
36
|
+
}) => {
|
|
37
|
+
const config = this.config.Logger.performanceInspector;
|
|
38
|
+
const blacklist = config.blacklist || [];
|
|
39
|
+
if (blacklist.some((item) => name.startsWith(item)))
|
|
40
|
+
return;
|
|
41
|
+
const { noHooks, logMode, throttleInterval, maxRenders = config.maxRenders } = options;
|
|
42
|
+
if (!config.enabled || !this.config.Environment.IsDev) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (!noHooks) {
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
console.log(`[PerformanceInspector] Mounted -> ${name}`);
|
|
48
|
+
return () => {
|
|
49
|
+
console.log(`[PerformanceInspector] Unmounted -> ${name}`);
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
this.renderCounter[name] = this.renderCounter[name] ? this.renderCounter[name] + 1 : 1;
|
|
54
|
+
const renders = this.renderCounter[name];
|
|
55
|
+
if (renders > maxRenders) {
|
|
56
|
+
this.renderCounter[name] = 0;
|
|
57
|
+
throw new PerformanceError('maxRenders', {
|
|
58
|
+
name,
|
|
59
|
+
throttleInterval,
|
|
60
|
+
maxRenders,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (logMode === 'raw') {
|
|
64
|
+
console.log(`[PerformanceInspector] Rendered -> ${name}: ${renders}`);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
function logSummary() {
|
|
68
|
+
if (renders <= 0)
|
|
69
|
+
return;
|
|
70
|
+
console.log(`[PerformanceInspector] Render summary -> ${name}: ${renders}`);
|
|
71
|
+
this.renderCounter[name] = 0;
|
|
72
|
+
}
|
|
73
|
+
// @ts-ignore
|
|
74
|
+
throttle(logSummary, name, throttleInterval);
|
|
75
|
+
};
|
|
75
76
|
}
|
|
76
77
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/performance/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAI3C,cAAc,SAAS,CAAA;AAEvB;;;;GAIG;AACH,MAAM,OAAO,kBAAkB;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/performance/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAI3C,cAAc,SAAS,CAAA;AAEvB;;;;GAIG;AACH,MAAM,OAAO,kBAAkB;IAGT;IAFpB,aAAa,GAA2B,EAAE,CAAA;IAE1C,YAAoB,MAAoB;QAApB,WAAM,GAAN,MAAM,C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ACzB,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;YAE5B,MAAM,IAAI,gBAAgB,CAAC,YAAY,EAAE;gBACvC,IAAI;gBACJ,gBAAgB;gBAChB,UAAU;aACX,CAAC,CAAA;QACJ,CAAC;QAED,IAAI,OAAO,KAAK,KAAK,EAAE,CAAC;YACtB,OAAO,CAAC,GAAG,CAAC,sCAAsC,IAAI,KAAK,OAAO,EAAE,CAAC,CAAA;YACrE,OAAM;QACR,CAAC;QAED,SAAS,UAAU;YACjB,IAAI,OAAO,IAAI,CAAC;gBAAE,OAAM;YAExB,OAAO,CAAC,GAAG,CAAC,4CAA4C,IAAI,KAAK,OAAO,EAAE,CAAC,CAAA;YAC3E,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAC9B,CAAC;QACD,aAAa;QACb,QAAQ,CAAC,UAAU,EAAE,IAAI,EAAE,gBAAgB,CAAC,CAAA;IAC9C,CAAC,CAAA;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createLogger.js","sourceRoot":"","sources":["../../src/utils/createLogger.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;GAWG;AACH,MAAM,YAAY;
|
|
1
|
+
{"version":3,"file":"createLogger.js","sourceRoot":"","sources":["../../src/utils/createLogger.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;GAWG;AACH,MAAM,YAAY;IAChB,MAAM,CAAC,SAAS,CAAqB;IAErC,MAAM,CAAC,cAAc,CAAC,KAAY,EAAE,GAAG,IAAe;QACpD,YAAY,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;YAC9B,EAAE,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,CAAA;QACpB,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,IAAI,CAAC,GAAG,IAAe;QACrB,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAA;QACrB,YAAY,CAAC,cAAc,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAA;IAC9C,CAAC;IAED,KAAK,CAAC,GAAG,IAAe;QACtB,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAA;QACtB,YAAY,CAAC,cAAc,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAA;IAC/C,CAAC;IAED,IAAI,CAAC,GAAG,IAAe;QACrB,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAA;QACrB,YAAY,CAAC,cAAc,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAA;IAC9C,CAAC;IAED,yFAAyF;IACzF,IAAI,CAAC,GAAG,IAAe;IAEvB,CAAC;IAED,GAAG,CAAC,GAAG,IAAe;QACpB,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAA;QACpB,YAAY,CAAC,cAAc,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,CAAA;IAC7C,CAAC;IAED,KAAK,CAAC,GAAG,IAAe;QACtB,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAA;QACtB,YAAY,CAAC,cAAc,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAA;IAC/C,CAAC;CACF;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,OAAsB,EAAE,EAAE;IACrD,YAAY,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;IAE1C,OAAO,IAAI,YAAY,EAAE,CAAA;AAC3B,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codeleap/logger",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.1.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"directory": "packages/logger"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@codeleap/types": "7.0.
|
|
26
|
-
"@codeleap/utils": "7.0.
|
|
27
|
-
"@codeleap/config": "7.0.
|
|
25
|
+
"@codeleap/types": "7.0.2",
|
|
26
|
+
"@codeleap/utils": "7.0.2",
|
|
27
|
+
"@codeleap/config": "7.0.2",
|
|
28
28
|
"ts-node-dev": "1.1.8",
|
|
29
29
|
"@sentry/types": "8.40.0"
|
|
30
30
|
},
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"typecheck": "bun tsc --noEmit -p ./tsconfig.json"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@codeleap/types": "7.0.
|
|
37
|
-
"@codeleap/utils": "7.0.
|
|
36
|
+
"@codeleap/types": "7.0.2",
|
|
37
|
+
"@codeleap/utils": "7.0.2",
|
|
38
38
|
"typescript": "6.0.3",
|
|
39
39
|
"react": "19.1.0"
|
|
40
40
|
},
|