是否可以在React Native中隐藏“ BugReporting extraData”? (使用博览会)

时间:2018-07-26 13:46:14

标签: javascript reactjs react-native expo

每次我使用Expo打开React Native应用程序时,都会在控制台中收到有关该应用程序的元数据的大量消息,但实际上并不能帮助我进行调试。特别是因为每次都具有相同的信息,并且每次重新加载应用程序时都会显示该信息(即使是热加载或实时重新加载):

Running application "main"
with appParams: {
    "rootTag": 171,
    "initialProps": {
        "exp": {
            "manifest": {
                "splash": {
                    "backgroundColor": "#1c2d3c"
                },
                "packagerOpts": {
                    "lanType": "ip",
                    "urlRandomness": "e4-nfi",
                    "hostType": "tunnel",
                    "dev": true,
                    "minify": false
                },
                "debuggerHost": "localhost:19001",
                "bundleUrl": "http://localhost:19001/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false&assetPlugin=pathToProjectFiles",
                "facebookAppId": "FBAppIdGoesHere",
                "android": {
                    "splash": {
                        "xxhdpi": "./src/assets/img/splash-android.png",
                        "backgroundColor": "#1c2d3c",
                        "xxxhdpiUrl": "http://localhost:19001/assets/./src/assets/img/splash-android.png",
                        "xhdpi": "./src/assets/img/splash-android.png",
                        "hdpi": "./src/assets/img/splash-android.png",
                        "xxxhdpi": "./src/assets/img/splash-android.png",
                        "resizeMode": "cover",
                        "ldpi": "./src/assets/img/splash-android.png",
                        "xxhdpiUrl": "http://localhost:19001/assets/./src/assets/img/splash-android.png",
                        "ldpiUrl": "http://localhost:19001/assets/./src/assets/img/splash-android.png",
                        "xhdpiUrl": "http://localhost:19001/assets/./src/assets/img/splash-android.png",
                        "hdpiUrl": "http://localhost:19001/assets/./src/assets/img/splash-android.png",
                        "mdpi": "./src/assets/img/splash-android.png",
                        "mdpiUrl": "http://localhost:19001/assets/./src/assets/img/splash-android.png"
                    },
                    "config": {
                        "googleSignIn": {
                            "apiKey": "APIKeyGoesHere",
                            "certificateHash": "HashGoesHere"
                        }
                    },
                    "iconUrl": "http://localhost:19001/assets/./src/assets/img/icon-android.png",
                    "package": "com.organizationName.apps",
                    "permissions": ["CAMERA", "INTERNET", "LOCATION", "READ_EXTERNAL_STORAGE", "READ_INTERNAL_STORAGE", "WRITE_EXTERNAL_STORAGE", "com.anddoes.launcher.permission.UPDATE_COUNT", "com.android.launcher.permission.INSTALL_SHORTCUT", "com.google.android.c2dm.permission.RECEIVE", "com.google.android.gms.permission.ACTIVITY_RECOGNITION", "com.google.android.providers.gsf.permission.READ_GSERVICES", "com.htc.launcher.permission.READ_SETTINGS", "com.htc.launcher.permission.UPDATE_SHORTCUT", "com.majeur.launcher.permission.UPDATE_BADGE", "com.sec.android.provider.badge.permission.READ", "com.sec.android.provider.badge.permission.WRITE", "com.sonyericsson.home.permission.BROADCAST_BADGE"],
                    "icon": "./src/assets/img/icon-android.png",
                    "versionCode": 10
                },
                "slug": "app-name-goes-here",
                "facebookDisplayName": "NameOfApp",
                "icon": "./src/assets/img/icon-android.png",
                "primaryColor": "#cccccc",
                "isVerified": true,
                "version": "1.1.5",
                "xde": true,
                "name": "NameOfApp",
                "facebookScheme": "SomeFBSchemeCodeGoesHere",
                "iconUrl": "http://localhost:19001/assets/./src/assets/img/icon-android.png",
                "id": "@jhwheeler/name-of-app",
                "hostUri": "localhost:19000",
                "orientation": "portrait",
                "sdkVersion": "27.0.0",
                "env": {},
                "hooks": {
                    "postPublish": [{
                        "config": {
                            "organization": "organizationNameHere",
                            "project": "projectNameHere",
                            "authToken": "authTokenGoesHere"
                        },
                        "file": "sentry-expo/upload-sourcemaps"
                    }]
                },
                "loadedFromCache": false,
                "ios": {
                    "splash": {
                        "resizeMode": "cover",
                        "imageUrl": "http://localhost:19001/assets/./src/assets/img/splash-ios.png",
                        "backgroundColor": "#1c2d3c",
                        "image": "./src/assets/img/splash-ios.png"
                    },
                    "supportsTablet": false,
                    "iconUrl": "http://localhost:19001/assets/./src/assets/img/icon-ios.png",
                    "infoPlist": {
                        "NSLocationAlwaysUsageDescription": "Nice message goes here",
                        "NSLocationWhenInUseUsageDescription": "Nice message goes here"
                    },
                    "bundleIdentifier": "com.orgName.apps",
                    "buildNumber": "1",
                    "icon": "./src/assets/img/icon-ios.png"
                },
                "logUrl": "http://localhost:19000/logs",
                "privacy": "unlisted",
                "mainModuleName": "node_modules/expo/AppEntry",
                "developer": {
                    "projectRoot": "/path/to/project",
                    "tool": "xde"
                },
                "description": "descriptionOfApp"
            },
            "appOwnership": "expo",
            "initialUri": "exp://localhost:19000",
            "shell": 0
        }
    }
}.__DEV__ === true, development - level warning are ON, performance optimizations are OFF

如果我正在查看Expo控制台,它以BugReporting extraData:开头,并将以上内容包装在JS对象中。我不知道这是Expo还是React Native消息所独有的,但是无论哪种方式:

有什么方法可以消除此消息?如此之大,以至于发现实际错误变得更加费力。

2 个答案:

答案 0 :(得分:2)

我不熟悉Expo,但是最近在一个普通的RN项目中遇到了此日志消息。通过将以下内容添加到索引文件中,我可以将其删除:

   console.ignoredYellowBox = ['react-native BugReporting extraData:'];

答案 1 :(得分:1)

我通过添加到项目根目录解决了类似的问题:

const ignoreConsoleMessages = [
  'Running "main" with'
]
const origLog = console.log
console.log = (...params) => (
  typeof params[0] === 'string' &&
  ignoreConsoleMessages.reduce((acc, i) => acc + ~params[0].indexOf(i), 0)
    ? null
    : origLog(...params)
)