Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Commit 5907794

Browse files
committed
added feature to completely block the agile logcodemanager
1 parent 71648dd commit 5907794

File tree

7 files changed

+38
-20
lines changed

7 files changed

+38
-20
lines changed

benchmark/benchmarks/react/1000fields/bench/agilets/collection.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import React from 'react';
22
import ReactDom from 'react-dom';
3-
import { createCollection, shared } from '@agile-ts/core';
3+
import { createCollection, LogCodeManager, shared } from '@agile-ts/core';
44
import reactIntegration, { useAgile, useValue } from '@agile-ts/react';
5-
import { assignSharedAgileLoggerConfig } from '@agile-ts/logger';
65

7-
assignSharedAgileLoggerConfig({ active: false });
6+
LogCodeManager.setAllowLogging(false);
87
shared.integrate(reactIntegration);
98

109
export default function (target: HTMLElement, fieldsCount: number) {

benchmark/benchmarks/react/1000fields/bench/agilets/nestedState.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import * as React from 'react';
22
import * as ReactDom from 'react-dom';
3-
import { createState, shared, State } from '@agile-ts/core';
3+
import { createState, LogCodeManager, shared, State } from '@agile-ts/core';
44
import reactIntegration, { useAgile } from '@agile-ts/react';
5-
import { assignSharedAgileLoggerConfig } from '@agile-ts/logger';
65

7-
assignSharedAgileLoggerConfig({ active: false });
6+
LogCodeManager.setAllowLogging(false);
87
shared.integrate(reactIntegration);
98

109
export default function (target: HTMLElement, fieldsCount: number) {

benchmark/benchmarks/react/1000fields/bench/agilets/state.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import React from 'react';
22
import ReactDom from 'react-dom';
3-
import { createState, shared } from '@agile-ts/core';
3+
import { createState, LogCodeManager, shared } from '@agile-ts/core';
44
import reactIntegration, { useAgile } from '@agile-ts/react';
5-
import { assignSharedAgileLoggerConfig } from '@agile-ts/logger';
65

7-
assignSharedAgileLoggerConfig({ active: false });
6+
LogCodeManager.setAllowLogging(false);
87
shared.integrate(reactIntegration);
98

109
export default function (target: HTMLElement, fieldsCount: number) {

benchmark/benchmarks/react/computed/bench/agilets/autoTracking.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import React from 'react';
22
import ReactDom from 'react-dom';
3-
import { createComputed, createState, shared } from '@agile-ts/core';
3+
import {
4+
createComputed,
5+
createState,
6+
LogCodeManager,
7+
shared,
8+
} from '@agile-ts/core';
49
import reactIntegration, { useAgile } from '@agile-ts/react';
5-
import { assignSharedAgileLoggerConfig } from '@agile-ts/logger';
610

7-
assignSharedAgileLoggerConfig({ active: false });
11+
LogCodeManager.setAllowLogging(false);
812
shared.integrate(reactIntegration);
913

1014
const COUNT = createState(0);

benchmark/benchmarks/react/computed/bench/agilets/hardCoded.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import React from 'react';
22
import ReactDom from 'react-dom';
3-
import { createComputed, createState, shared } from '@agile-ts/core';
3+
import {
4+
createComputed,
5+
createState,
6+
LogCodeManager,
7+
shared,
8+
} from '@agile-ts/core';
49
import reactIntegration, { useAgile } from '@agile-ts/react';
5-
import { assignSharedAgileLoggerConfig } from '@agile-ts/logger';
610

7-
assignSharedAgileLoggerConfig({ active: false });
11+
LogCodeManager.setAllowLogging(false);
812
shared.integrate(reactIntegration);
913

1014
const COUNT = createState(0);

benchmark/benchmarks/react/counter/bench/agilets.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import React from 'react';
22
import ReactDom from 'react-dom';
3-
import { createState, shared } from '@agile-ts/core';
3+
import { createState, LogCodeManager, shared } from '@agile-ts/core';
44
import reactIntegration, { useAgile } from '@agile-ts/react';
5-
import { assignSharedAgileLoggerConfig } from '@agile-ts/logger';
65

7-
assignSharedAgileLoggerConfig({ active: false });
6+
LogCodeManager.setAllowLogging(false);
87
shared.integrate(reactIntegration);
98

109
const COUNT = createState(0);

packages/core/src/logCodeManager.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const logCodeTypes = {
2525
// ---
2626
// 00:00:|00| third digits are based on the Log Message (ascending counted)
2727

28+
let allowLogging = true;
2829
const niceLogCodeMessages = {
2930
// Agile
3031
'10:00:00': 'Created new AgileInstance.',
@@ -174,6 +175,16 @@ const logCodeMessages: typeof niceLogCodeMessages =
174175
? niceLogCodeMessages
175176
: ({} as any);
176177

178+
/**
179+
* Specifies whether the LogCodeManager is allowed to print any logs.
180+
*
181+
* @internal
182+
* @param logging - Whether the LogCodeManager is allowed to print any logs.
183+
*/
184+
function setAllowLogging(logging: boolean) {
185+
allowLogging = logging;
186+
}
187+
177188
/**
178189
* Returns the log message according to the specified log code.
179190
*
@@ -213,7 +224,7 @@ function log<T extends LogCodesArrayType<typeof logCodeMessages>>(
213224
...data: any[]
214225
): void {
215226
const logger = LogCodeManager.getLogger();
216-
if (logger != null && !logger.isActive) return;
227+
if ((logger != null && !logger.isActive) || !allowLogging) return;
217228
const logType = logCodeTypes[logCode.substr(3, 2)];
218229
if (typeof logType !== 'string') return;
219230

@@ -246,7 +257,7 @@ function logIfTags<T extends LogCodesArrayType<typeof logCodeMessages>>(
246257
...data: any[]
247258
): void {
248259
const logger = LogCodeManager.getLogger();
249-
if (logger != null && !logger.isActive) return;
260+
if ((logger != null && !logger.isActive) || !allowLogging) return;
250261
const logType = logCodeTypes[logCode.substr(3, 2)];
251262
if (typeof logType !== 'string') return;
252263

@@ -298,6 +309,7 @@ if (typeof process === 'object' && process.env.NODE_ENV !== 'production') {
298309
logCodeMessages: logCodeMessages,
299310
getLogger: loggerPackage.getLogger,
300311
logIfTags,
312+
setAllowLogging,
301313
};
302314
} else {
303315
tempLogCodeManager = {
@@ -312,6 +324,7 @@ if (typeof process === 'object' && process.env.NODE_ENV !== 'production') {
312324
logIfTags: (tags, logCode, replacers) => {
313325
/* empty because logs with tags can't be that important */
314326
},
327+
setAllowLogging,
315328
};
316329
}
317330

@@ -344,4 +357,5 @@ export interface LogCodeManagerInterface<T = typeof logCodeMessages> {
344357
replacers?: any[],
345358
...data: any[]
346359
) => void;
360+
setAllowLogging: (logging: boolean) => void;
347361
}

0 commit comments

Comments
 (0)