Skip to content

Commit

Permalink
Add a possibility to disable some logs
Browse files Browse the repository at this point in the history
  • Loading branch information
MatiPl01 committed Aug 13, 2024
1 parent 0c20e83 commit 70fd267
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 20 deletions.
4 changes: 2 additions & 2 deletions apps/common-app/src/examples/EmptyExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import Animated, {
} from 'react-native-reanimated';

Animated.configureLogger({
level: 'error',
// level: 'error',
});

const SHOW_EXAMPLE: number = -2;
const SHOW_EXAMPLE: number = 14;

/** [-1]
* Error: [Reanimated] Property `text` was whitelisted both as UI and native prop. Please remove it from
Expand Down
4 changes: 4 additions & 0 deletions apps/common-app/src/examples/InvalidValueAccessExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import Animated, {
withTiming,
} from 'react-native-reanimated';

Animated.configureLogger({
strict: true,
});

export default function InvalidValueAccessExample() {
const [counter, setCounter] = React.useState(0);
const [updateFromUseEffect, setUpdateFromUseEffect] = React.useState(false);
Expand Down
10 changes: 4 additions & 6 deletions packages/react-native-reanimated/src/ConfigHelper.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
'use strict';
import { PropsAllowlists } from './propsAllowlists';
import { jsiConfigureProps, makeShareableCloneRecursive } from './core';
import { logger } from './logger';
import { jsiConfigureProps } from './core';
import { config as loggerConfig } from './logger';
import type { LoggerConfig } from './logger';
import { shareableMappingCache } from './shareableMappingCache';

function assertNoOverlapInLists() {
for (const key in PropsAllowlists.NATIVE_THREAD_PROPS_WHITELIST) {
Expand Down Expand Up @@ -55,9 +54,8 @@ export function addWhitelistedUIProps(props: Record<string, boolean>): void {
}

export function configureLogger(config: LoggerConfig) {
config.level = config.level ?? 'warn';
config.strict = config.strict ?? false;
shareableMappingCache.set(logger, makeShareableCloneRecursive(logger));
loggerConfig.level = config.level ?? 'warn';
loggerConfig.strict = config.strict ?? false;
}

const PROCESSED_VIEW_NAMES = new Set();
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-reanimated/src/logger/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export type LoggerConfig = {

type LogFunction = (data: LogData) => void;

const config: Required<LoggerConfig> & { logFunction: LogFunction } = {
export const config: Required<LoggerConfig> & { logFunction: LogFunction } = {
logFunction: logToConsole,
level: 'warn',
strict: false,
Expand Down
11 changes: 7 additions & 4 deletions packages/react-native-reanimated/src/mutables.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
import { shouldBeUseWeb } from './PlatformChecker';
import type { Mutable } from './commonTypes';
import { logger } from './logger';
import { isFirstReactRender, isReactRendering } from './reactUtils';
import { shareableMappingCache } from './shareableMappingCache';
import { makeShareableCloneRecursive } from './shareables';
Expand All @@ -15,16 +16,18 @@ function shouldWarnAboutAccessDuringRender() {

function checkInvalidReadDuringRender() {
if (shouldWarnAboutAccessDuringRender()) {
console.warn(
'[Reanimated] Reading from `value` during component render. Please ensure that you do not access the `value` property while React is rendering a component.'
logger.warn(
'Reading from `value` during component render. Please ensure that you do not access the `value` property while React is rendering a component.',
{ strict: true }
);
}
}

function checkInvalidWriteDuringRender() {
if (shouldWarnAboutAccessDuringRender()) {
console.warn(
'[Reanimated] Writing to `value` during component render. Please ensure that you do not access the `value` property while React is rendering a component.'
logger.warn(
'Writing to `value` during component render. Please ensure that you do not access the `value` property while React is rendering a component.',
{ strict: true }
);
}
}
Expand Down
8 changes: 1 addition & 7 deletions packages/react-native-reanimated/src/threads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@ import {
} from './shareables';
import { isWorkletFunction } from './commonTypes';
import type { LogData } from './logger';
import {
logger,
logToLogBoxAndConsole,
replaceLoggerImplementation,
} from './logger';
import { logToLogBoxAndConsole, replaceLoggerImplementation } from './logger';
import { registerReanimatedError } from './errors';
import { shareableMappingCache } from './shareableMappingCache';

const IS_JEST = isJest();
const SHOULD_BE_USE_WEB = shouldBeUseWeb();
Expand Down Expand Up @@ -271,7 +266,6 @@ replaceLoggerImplementation((data: LogData) => {
'worklet';
runOnJS(logToLogBoxAndConsole)(data);
});
shareableMappingCache.set(logger, makeShareableCloneRecursive(logger));

// Register ReanimatedError in the UI global scope
if (!shouldBeUseWeb()) {
Expand Down

0 comments on commit 70fd267

Please sign in to comment.