From 002bfef0ca239077fcd5df65a98a598305b7753a Mon Sep 17 00:00:00 2001 From: Ionatan Wiznia Date: Fri, 23 Jul 2021 16:05:44 +0200 Subject: [PATCH 01/14] Update expensify common with new logging methods and improve logging --- package-lock.json | 4 ++-- package.json | 2 +- src/Expensify.js | 2 +- src/components/ErrorBoundary/index.js | 4 ++-- src/components/ErrorBoundary/index.native.js | 2 +- src/libs/API.js | 2 +- src/libs/Log.js | 14 ++++++------- src/libs/NetworkConnection.js | 2 +- src/libs/PusherConnectionManager.js | 14 ++++++------- src/libs/actions/Report.js | 22 ++++++++++---------- src/libs/actions/User.js | 2 +- src/libs/translate.js | 4 ++-- 12 files changed, 37 insertions(+), 37 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5436ff2b5e8..e3981ba5125 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23059,8 +23059,8 @@ } }, "expensify-common": { - "version": "git://github.com/Expensify/expensify-common.git#7d8408c5c78792394eee8e079f115b1380221a23", - "from": "git://github.com/Expensify/expensify-common.git#7d8408c5c78792394eee8e079f115b1380221a23", + "version": "git://github.com/Expensify/expensify-common.git#8e163a9b72c1bd33c83ee5ebef6b7a69ce6f54b4", + "from": "git://github.com/Expensify/expensify-common.git#8e163a9b72c1bd33c83ee5ebef6b7a69ce6f54b4", "requires": { "classnames": "2.3.1", "clipboard": "2.0.4", diff --git a/package.json b/package.json index ec2d90e8238..5d727c9ceaa 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "electron-log": "^4.3.5", "electron-serve": "^1.0.0", "electron-updater": "^4.3.4", - "expensify-common": "git://github.com/Expensify/expensify-common.git#7d8408c5c78792394eee8e079f115b1380221a23", + "expensify-common": "git://github.com/Expensify/expensify-common.git#8e163a9b72c1bd33c83ee5ebef6b7a69ce6f54b4", "expo-haptics": "^10.0.0", "file-loader": "^6.0.0", "html-entities": "^1.3.1", diff --git a/src/Expensify.js b/src/Expensify.js index d933be7ccc1..d90f79c15c6 100644 --- a/src/Expensify.js +++ b/src/Expensify.js @@ -42,7 +42,7 @@ Onyx.init({ }); Onyx.registerLogger(({level, message}) => { if (level === 'alert') { - Log.alert(message, 0, {}, false); + Log.alert(message, {}, false); } else { Log.client(message); } diff --git a/src/components/ErrorBoundary/index.js b/src/components/ErrorBoundary/index.js index 7e8fdfdc213..548a278fa52 100644 --- a/src/components/ErrorBoundary/index.js +++ b/src/components/ErrorBoundary/index.js @@ -3,7 +3,7 @@ import Log from '../../libs/Log'; BaseErrorBoundary.defaultProps.logError = (errorMessage, error, errorInfo) => { // Log the error to the server - Log.alert(errorMessage, 0, {error: error.message, errorInfo}, false); + Log.alert(errorMessage, {error: error.message, errorInfo}, false); }; - +window.Log = Log; export default BaseErrorBoundary; diff --git a/src/components/ErrorBoundary/index.native.js b/src/components/ErrorBoundary/index.native.js index d320b46984e..ae295a9d0c4 100644 --- a/src/components/ErrorBoundary/index.native.js +++ b/src/components/ErrorBoundary/index.native.js @@ -5,7 +5,7 @@ import Log from '../../libs/Log'; BaseErrorBoundary.defaultProps.logError = (errorMessage, error, errorInfo) => { // Log the error to the server - Log.alert(errorMessage, 0, {error: error.message, errorInfo}, false); + Log.alert(errorMessage, {error: error.message, errorInfo}, false); /* On native we also log the error to crashlytics * Since the error was handled we need to manually tell crashlytics about it */ diff --git a/src/libs/API.js b/src/libs/API.js index c885298411b..0ed7d9b8888 100644 --- a/src/libs/API.js +++ b/src/libs/API.js @@ -471,7 +471,7 @@ function GetRequestCountryCode() { */ function Log(parameters) { const commandName = 'Log'; - requireParameters(['message', 'parameters', 'expensifyCashAppVersion'], + requireParameters(['logPacket'], parameters, commandName); // Note: We are forcing Log to run since it requires no authToken and should only be queued when we are offline. diff --git a/src/libs/Log.js b/src/libs/Log.js index 1451ea25cc9..f24b68f88ad 100644 --- a/src/libs/Log.js +++ b/src/libs/Log.js @@ -11,15 +11,15 @@ import NetworkConnection from './NetworkConnection'; * @param {Object} params * @param {Object} params.parameters * @param {String} params.message + * @return {Promise} */ function serverLoggingCallback(params) { - const requestParams = { - message: params.message, - parameters: JSON.stringify(params.parameters || {}), - expensifyCashAppVersion: `expensifyCash[${getPlatform()}]${version}`, - }; - - API.Log(requestParams); + const requestParams = params; + requestParams.expensifyCashAppVersion = `expensifyCash[${getPlatform()}]${version}`; + if (requestParams.parameters) { + requestParams.parameters = JSON.stringify(params.parameters); + } + return API.Log(requestParams); } // Note: We are importing Logger from expensify-common because it is diff --git a/src/libs/NetworkConnection.js b/src/libs/NetworkConnection.js index cb104b18d86..5bc66855e92 100644 --- a/src/libs/NetworkConnection.js +++ b/src/libs/NetworkConnection.js @@ -49,7 +49,7 @@ function setOfflineStatus(isCurrentlyOffline) { * `disconnected` event which takes about 10-15 seconds to emit. */ function listenForReconnect() { - logInfo('[NetworkConnection] listenForReconnect called', true); + logInfo('[NetworkConnection] listenForReconnect called'); unsubscribeFromAppState = AppStateMonitor.addBecameActiveListener(() => { triggerReconnectionCallbacks('app became active'); diff --git a/src/libs/PusherConnectionManager.js b/src/libs/PusherConnectionManager.js index 164efb40d7b..e5a778632c7 100644 --- a/src/libs/PusherConnectionManager.js +++ b/src/libs/PusherConnectionManager.js @@ -7,7 +7,7 @@ import Log from './Log'; // reconnect each time when we only need to reconnect once. This way, if an authToken is expired and we try to // subscribe to a bunch of channels at once we will only reauthenticate and force reconnect Pusher once. const reauthenticate = _.throttle(() => { - Log.info('[Pusher] Re-authenticating and then reconnecting', true); + Log.info('[Pusher] Re-authenticating and then reconnecting'); API.reauthenticate('Push_Authenticate') .then(() => Pusher.reconnect()) .catch(() => { @@ -27,7 +27,7 @@ function init() { */ Pusher.registerCustomAuthorizer(channel => ({ authorize: (socketID, callback) => { - Log.info('[PusherConnectionManager] Attempting to authorize Pusher', true); + Log.info('[PusherConnectionManager] Attempting to authorize Pusher', false, {channelName: channel.name}); API.Push_Authenticate({ socket_id: socketID, @@ -44,11 +44,11 @@ function init() { return; } - Log.info('[PusherConnectionManager] Pusher authenticated successfully', true); + Log.info('[PusherConnectionManager] Pusher authenticated successfully', false, {channelName: channel.name}); callback(null, data); }) .catch((error) => { - Log.info('[PusherConnectionManager] Unhandled error: ', error); + Log.info('[PusherConnectionManager] Unhandled error: ', false, {channelName: channel.name}); callback(error, {auth: ''}); }); }, @@ -63,14 +63,14 @@ function init() { Pusher.registerSocketEventCallback((eventName, data) => { switch (eventName) { case 'error': - Log.info('[PusherConnectionManager] error event', true, {error: data}); + Log.info('[PusherConnectionManager] error event', false, {error: data}); reauthenticate(); break; case 'connected': - Log.info('[PusherConnectionManager] connected event', true); + Log.info('[PusherConnectionManager] connected event'); break; case 'disconnected': - Log.info('[PusherConnectionManager] disconnected event', true); + Log.info('[PusherConnectionManager] disconnected event'); break; default: break; diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 94347c7608c..b412d6cac1e 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -322,7 +322,7 @@ function fetchChatReportsByIDs(chatList, shouldRedirectIfInacessible = false) { const simplifiedReports = {}; return API.GetReportSummaryList({reportIDList: chatList.join(',')}) .then(({reportSummaryList, jsonCode}) => { - Log.info('[Report] successfully fetched report data', true); + Log.info('[Report] successfully fetched report data', false, {chatList}); fetchedReports = reportSummaryList; // If we receive a 404 response while fetching a single report, treat that report as inacessible. @@ -342,7 +342,7 @@ function fetchChatReportsByIDs(chatList, shouldRedirectIfInacessible = false) { return; } if (participants.length === 0) { - Log.alert('[Report] Report with IOU action but does not have any participant.', true, { + Log.alert('[Report] Report with IOU action but does not have any participant.', { reportID: chatReport.reportID, participants, }); @@ -690,7 +690,7 @@ function subscribeToUserEvents() { // Live-update a report's actions when a 'report comment' event is received. Pusher.subscribe(pusherChannelName, Pusher.TYPE.REPORT_COMMENT, (pushJSON) => { Log.info( - `[Report] Handled ${Pusher.TYPE.REPORT_COMMENT} event sent by Pusher`, true, {reportID: pushJSON.reportID}, + `[Report] Handled ${Pusher.TYPE.REPORT_COMMENT} event sent by Pusher`, false, {reportID: pushJSON.reportID}, ); updateReportWithNewAction(pushJSON.reportID, pushJSON.reportAction, pushJSON.notificationPreference); }, false, @@ -700,7 +700,7 @@ function subscribeToUserEvents() { .catch((error) => { Log.info( '[Report] Failed to subscribe to Pusher channel', - true, + false, {error, pusherChannelName, eventName: Pusher.TYPE.REPORT_COMMENT}, ); }); @@ -708,7 +708,7 @@ function subscribeToUserEvents() { // Live-update a report's actions when an 'edit comment' event is received. Pusher.subscribe(pusherChannelName, Pusher.TYPE.REPORT_COMMENT_EDIT, (pushJSON) => { Log.info( - `[Report] Handled ${Pusher.TYPE.REPORT_COMMENT_EDIT} event sent by Pusher`, true, { + `[Report] Handled ${Pusher.TYPE.REPORT_COMMENT_EDIT} event sent by Pusher`, false, { reportActionID: pushJSON.reportActionID, }, ); @@ -720,7 +720,7 @@ function subscribeToUserEvents() { .catch((error) => { Log.info( '[Report] Failed to subscribe to Pusher channel', - true, + false, {error, pusherChannelName, eventName: Pusher.TYPE.REPORT_COMMENT_EDIT}, ); }); @@ -729,7 +729,7 @@ function subscribeToUserEvents() { Pusher.subscribe(pusherChannelName, Pusher.TYPE.REPORT_TOGGLE_PINNED, (pushJSON) => { Log.info( `[Report] Handled ${Pusher.TYPE.REPORT_TOGGLE_PINNED} event sent by Pusher`, - true, + false, {reportID: pushJSON.reportID}, ); updateReportPinnedState(pushJSON.reportID, pushJSON.isPinned); @@ -740,13 +740,13 @@ function subscribeToUserEvents() { .catch((error) => { Log.info( '[Report] Failed to subscribe to Pusher channel', - true, + false, {error, pusherChannelName, eventName: Pusher.TYPE.REPORT_TOGGLE_PINNED}, ); }); PushNotification.onReceived(PushNotification.TYPE.REPORT_COMMENT, ({reportID, reportAction}) => { - Log.info('[Report] Handled event sent by Airship', true, {reportID}); + Log.info('[Report] Handled event sent by Airship', false, {reportID}); updateReportWithNewAction(reportID, reportAction); }); @@ -818,7 +818,7 @@ function subscribeToReportTypingEvents(reportID) { }, 1500); }) .catch((error) => { - Log.info('[Report] Failed to initially subscribe to Pusher channel', true, {error, pusherChannelName}); + Log.info('[Report] Failed to initially subscribe to Pusher channel', false, {error, pusherChannelName}); }); } @@ -884,7 +884,7 @@ function fetchActions(reportID, offset) { const reportActionsOffset = !_.isUndefined(offset) ? offset : -1; if (!_.isNumber(reportActionsOffset)) { - Log.alert('[Report] Offset provided is not a number', true, { + Log.alert('[Report] Offset provided is not a number', { offset, reportActionsOffset, }); diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index 6e7c895b655..c03b20e05c8 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -262,7 +262,7 @@ function subscribeToUserEvents() { .catch((error) => { Log.info( '[User] Failed to subscribe to Pusher channel', - true, + false, {error, pusherChannelName, eventName: Pusher.TYPE.PREFERRED_LOCALE}, ); }); diff --git a/src/libs/translate.js b/src/libs/translate.js index 4716a25841e..5985dcdd806 100644 --- a/src/libs/translate.js +++ b/src/libs/translate.js @@ -46,7 +46,7 @@ function translate(locale = CONST.DEFAULT_LOCALE, phrase, variables = {}) { return Str.result(translationValue, variables); } if (localeLanguage !== 'en') { - Log.alert(`${phrase} was not found in the ${localeLanguage} locale`, 0, {}, false); + Log.alert(`${phrase} was not found in the ${localeLanguage} locale`, {}, false); } // Phrase is not translated, search it in default language (en) @@ -59,7 +59,7 @@ function translate(locale = CONST.DEFAULT_LOCALE, phrase, variables = {}) { // on development throw an error if (Config.IS_IN_PRODUCTION) { const phraseString = Array.isArray(phrase) ? phrase.join('.') : phrase; - Log.alert(`${phraseString} was not found in the en locale`, 0, {}, false); + Log.alert(`${phraseString} was not found in the en locale`, {}, false); return phraseString; } throw new Error(`${phrase} was not found in the default language`); From 2aa3b9090b914d3f6dd94cd79c08f8be157d318f Mon Sep 17 00:00:00 2001 From: Ionatan Wiznia Date: Fri, 23 Jul 2021 17:38:41 +0200 Subject: [PATCH 02/14] More log improvements: log navigations, improve logs, flush on logout and app inactive --- package-lock.json | 4 +-- package.json | 2 +- src/App.js | 48 +++++++++++++++++++++++------ src/libs/Log.js | 7 +++++ src/libs/Navigation/Navigation.js | 2 ++ src/libs/PusherConnectionManager.js | 6 +++- src/libs/actions/Session.js | 2 ++ 7 files changed, 57 insertions(+), 14 deletions(-) diff --git a/package-lock.json b/package-lock.json index e3981ba5125..09d03bf7fe3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23059,8 +23059,8 @@ } }, "expensify-common": { - "version": "git://github.com/Expensify/expensify-common.git#8e163a9b72c1bd33c83ee5ebef6b7a69ce6f54b4", - "from": "git://github.com/Expensify/expensify-common.git#8e163a9b72c1bd33c83ee5ebef6b7a69ce6f54b4", + "version": "git://github.com/Expensify/expensify-common.git#5ddf00f89e78ab22a50977eb367d4c2805555b93", + "from": "git://github.com/Expensify/expensify-common.git#5ddf00f89e78ab22a50977eb367d4c2805555b93", "requires": { "classnames": "2.3.1", "clipboard": "2.0.4", diff --git a/package.json b/package.json index 5d727c9ceaa..49290e9bc24 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "electron-log": "^4.3.5", "electron-serve": "^1.0.0", "electron-updater": "^4.3.4", - "expensify-common": "git://github.com/Expensify/expensify-common.git#8e163a9b72c1bd33c83ee5ebef6b7a69ce6f54b4", + "expensify-common": "git://github.com/Expensify/expensify-common.git#5ddf00f89e78ab22a50977eb367d4c2805555b93", "expo-haptics": "^10.0.0", "file-loader": "^6.0.0", "html-entities": "^1.3.1", diff --git a/src/App.js b/src/App.js index 0ac8e0ac8e6..2c4b6d33174 100644 --- a/src/App.js +++ b/src/App.js @@ -1,9 +1,10 @@ -import React from 'react'; -import {LogBox} from 'react-native'; +import React, {Component} from 'react'; +import {AppState, LogBox} from 'react-native'; import {SafeAreaProvider} from 'react-native-safe-area-context'; import CustomStatusBar from './components/CustomStatusBar'; import ErrorBoundary from './components/ErrorBoundary'; import Expensify from './Expensify'; +import Log from './libs/Log'; LogBox.ignoreLogs([ // Basically it means that if the app goes in the background and back to foreground on Android, @@ -15,14 +16,41 @@ LogBox.ignoreLogs([ 'Require cycle: node_modules/rn-fetch-blob', ]); -const App = () => ( - - - - - - -); +class App extends Component { + constructor(props) { + super(props); + this.state = { + appState: AppState.currentState, + }; + this.handleAppStateChange = this.handleAppStateChange.bind(this); + } + + componentDidMount() { + AppState.addEventListener('change', this.handleAppStateChange); + } + + componentWillUnmount() { + AppState.removeEventListener('change', this.handleAppStateChange); + } + + handleAppStateChange(nextAppState) { + if (nextAppState.match(/inactive|background/) && this.state.appState === 'active') { + Log.info('Flushing logs as app is going inactive', true); + } + this.setState({appState: nextAppState}); + } + + render() { + return ( + + + + + + + ); + } +} App.displayName = 'App'; diff --git a/src/libs/Log.js b/src/libs/Log.js index f24b68f88ad..22f7988ae85 100644 --- a/src/libs/Log.js +++ b/src/libs/Log.js @@ -5,6 +5,9 @@ import getPlatform from './getPlatform'; import {version} from '../../package.json'; import NetworkConnection from './NetworkConnection'; +let timeout = null; +let info; + /** * Network interface for logger. * @@ -19,6 +22,8 @@ function serverLoggingCallback(params) { if (requestParams.parameters) { requestParams.parameters = JSON.stringify(params.parameters); } + clearTimeout(timeout); + timeout = setTimeout(() => info('Flushing logs older than 10 minutes', true), 10 * 60 * 1000); return API.Log(requestParams); } @@ -33,6 +38,8 @@ const Log = new Logger({ }, isDebug: !CONFIG.IS_IN_PRODUCTION, }); +info = Log.info; +timeout = setTimeout(() => info('Flushing logs older than 10 minutes', true), 10 * 60 * 1000); NetworkConnection.registerLogInfoCallback(Log.info); export default Log; diff --git a/src/libs/Navigation/Navigation.js b/src/libs/Navigation/Navigation.js index 894974fbc05..f5a048dc97c 100644 --- a/src/libs/Navigation/Navigation.js +++ b/src/libs/Navigation/Navigation.js @@ -4,6 +4,7 @@ import {StackActions, DrawerActions} from '@react-navigation/native'; import PropTypes from 'prop-types'; import Onyx from 'react-native-onyx'; import linkTo from './linkTo'; +import Log from '../Log'; import ROUTES from '../../ROUTES'; import SCREENS from '../../SCREENS'; import CustomActions from './CustomActions'; @@ -54,6 +55,7 @@ function goBack(shouldOpenDrawer = true) { * @param {String} route */ function navigate(route = ROUTES.HOME) { + Log.info('Navigating to route', false, {route}); if (route === ROUTES.HOME) { if (isLoggedIn) { openDrawer(); diff --git a/src/libs/PusherConnectionManager.js b/src/libs/PusherConnectionManager.js index e5a778632c7..9873ed33d20 100644 --- a/src/libs/PusherConnectionManager.js +++ b/src/libs/PusherConnectionManager.js @@ -44,7 +44,11 @@ function init() { return; } - Log.info('[PusherConnectionManager] Pusher authenticated successfully', false, {channelName: channel.name}); + Log.info( + '[PusherConnectionManager] Pusher authenticated successfully', + false, + {channelName: channel.name}, + ); callback(null, data); }) .catch((error) => { diff --git a/src/libs/actions/Session.js b/src/libs/actions/Session.js index 3540939041f..b1008a39d16 100644 --- a/src/libs/actions/Session.js +++ b/src/libs/actions/Session.js @@ -5,6 +5,7 @@ import ONYXKEYS from '../../ONYXKEYS'; import redirectToSignIn from './SignInRedirect'; import * as API from '../API'; import CONFIG from '../../CONFIG'; +import Log from '../Log'; import PushNotification from '../Notification/PushNotification'; import Timing from './Timing'; import CONST from '../../CONST'; @@ -61,6 +62,7 @@ function createAccount(login) { * Clears the Onyx store and redirects user to the sign in page */ function signOut() { + Log.info('Flushing logs before signing out', true); if (credentials && credentials.autoGeneratedLogin) { // Clean up the login that we created API.DeleteLogin({ From 4a61d6ff5e4cff0c128ffa177dcc0557d4c95527 Mon Sep 17 00:00:00 2001 From: Ionatan Wiznia Date: Mon, 26 Jul 2021 13:30:05 +0200 Subject: [PATCH 03/14] Log API requests --- src/App.js | 2 +- src/libs/HttpUtils.js | 23 ++++++++++++++++++++++- src/libs/Log.js | 7 +++++-- src/libs/Network.js | 1 + src/libs/actions/Session.js | 2 +- 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/App.js b/src/App.js index 2c4b6d33174..2d027264087 100644 --- a/src/App.js +++ b/src/App.js @@ -35,7 +35,7 @@ class App extends Component { handleAppStateChange(nextAppState) { if (nextAppState.match(/inactive|background/) && this.state.appState === 'active') { - Log.info('Flushing logs as app is going inactive', true); + Log.info('Flushing logs as app is going inactive', true, {}, true); } this.setState({appState: nextAppState}); } diff --git a/src/libs/HttpUtils.js b/src/libs/HttpUtils.js index 3e71518d0d3..e0093b016ab 100644 --- a/src/libs/HttpUtils.js +++ b/src/libs/HttpUtils.js @@ -2,6 +2,8 @@ import _ from 'underscore'; import CONFIG from '../CONFIG'; import CONST from '../CONST'; +let info = () => {}; + /** * Send an HTTP request, and attempt to resolve the json response. * If there is a network error, we'll set the application offline. @@ -28,10 +30,24 @@ function processHTTPRequest(url, method = 'get', body = null) { * @returns {Promise} */ function xhr(command, data, type = CONST.NETWORK.METHOD.POST, shouldUseSecure = false) { + if (command !== 'Log') { + info('Making API request', false, {command, type, shouldUseSecure, rvl: data.returnValueList}); + } const formData = new FormData(); _.each(data, (val, key) => formData.append(key, val)); const apiRoot = shouldUseSecure ? CONFIG.EXPENSIFY.URL_EXPENSIFY_SECURE : CONFIG.EXPENSIFY.URL_API_ROOT; - return processHTTPRequest(`${apiRoot}api?command=${command}`, type, formData); + return processHTTPRequest(`${apiRoot}api?command=${command}`, type, formData) + .then((response) => { + if (command !== 'Log') { + info('Finished API request', false, { + command, + type, + shouldUseSecure, + jsonCode: response.jsonCode, + requestID: response.requestID, + }); + } + }); } /** @@ -51,7 +67,12 @@ function download(relativePath) { return processHTTPRequest(`${siteRoot}${strippedRelativePath}`); } +function setLogger(logger) { + info = logger.info; +} + export default { + setLogger, download, xhr, }; diff --git a/src/libs/Log.js b/src/libs/Log.js index 22f7988ae85..782a3cd2792 100644 --- a/src/libs/Log.js +++ b/src/libs/Log.js @@ -4,6 +4,7 @@ import CONFIG from '../CONFIG'; import getPlatform from './getPlatform'; import {version} from '../../package.json'; import NetworkConnection from './NetworkConnection'; +import HttpUtils from './HttpUtils'; let timeout = null; let info; @@ -23,7 +24,7 @@ function serverLoggingCallback(params) { requestParams.parameters = JSON.stringify(params.parameters); } clearTimeout(timeout); - timeout = setTimeout(() => info('Flushing logs older than 10 minutes', true), 10 * 60 * 1000); + timeout = setTimeout(() => info('Flushing logs older than 10 minutes', true, {}, true), 10 * 60 * 1000); return API.Log(requestParams); } @@ -39,7 +40,9 @@ const Log = new Logger({ isDebug: !CONFIG.IS_IN_PRODUCTION, }); info = Log.info; -timeout = setTimeout(() => info('Flushing logs older than 10 minutes', true), 10 * 60 * 1000); +timeout = setTimeout(() => info('Flushing logs older than 10 minutes', true, {}, true), 10 * 60 * 1000); NetworkConnection.registerLogInfoCallback(Log.info); +HttpUtils.setLogger(Log); + export default Log; diff --git a/src/libs/Network.js b/src/libs/Network.js index 5116cc2d002..fce1a21182e 100644 --- a/src/libs/Network.js +++ b/src/libs/Network.js @@ -1,6 +1,7 @@ import _ from 'underscore'; import lodashGet from 'lodash/get'; import Onyx from 'react-native-onyx'; +// eslint-disable-next-line import/no-cycle import HttpUtils from './HttpUtils'; import ONYXKEYS from '../ONYXKEYS'; import CONST from '../CONST'; diff --git a/src/libs/actions/Session.js b/src/libs/actions/Session.js index b1008a39d16..58503738f52 100644 --- a/src/libs/actions/Session.js +++ b/src/libs/actions/Session.js @@ -62,7 +62,7 @@ function createAccount(login) { * Clears the Onyx store and redirects user to the sign in page */ function signOut() { - Log.info('Flushing logs before signing out', true); + Log.info('Flushing logs before signing out', true, {}, true); if (credentials && credentials.autoGeneratedLogin) { // Clean up the login that we created API.DeleteLogin({ From 96c962f00dbf5a7ad320d5dd01ddd899ecded7eb Mon Sep 17 00:00:00 2001 From: Ionatan Wiznia Date: Thu, 29 Jul 2021 15:20:10 +0200 Subject: [PATCH 04/14] Use latest npm lib version --- package-lock.json | 4 ++-- package.json | 2 +- src/libs/translate.js | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index e20302e62bd..f8e3b8177ed 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23070,8 +23070,8 @@ } }, "expensify-common": { - "version": "git://github.com/Expensify/expensify-common.git#5ddf00f89e78ab22a50977eb367d4c2805555b93", - "from": "git://github.com/Expensify/expensify-common.git#5ddf00f89e78ab22a50977eb367d4c2805555b93", + "version": "git://github.com/Expensify/expensify-common.git#5d69f59ad2e916edf15ecb879e3ca27746cb274a", + "from": "git://github.com/Expensify/expensify-common.git#5d69f59ad2e916edf15ecb879e3ca27746cb274a", "requires": { "classnames": "2.3.1", "clipboard": "2.0.4", diff --git a/package.json b/package.json index bbc2d7880a8..52eb3d7e05c 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "electron-log": "^4.3.5", "electron-serve": "^1.0.0", "electron-updater": "^4.3.4", - "expensify-common": "git://github.com/Expensify/expensify-common.git#5ddf00f89e78ab22a50977eb367d4c2805555b93", + "expensify-common": "git://github.com/Expensify/expensify-common.git#5d69f59ad2e916edf15ecb879e3ca27746cb274a", "expo-haptics": "^10.0.0", "file-loader": "^6.0.0", "html-entities": "^1.3.1", diff --git a/src/libs/translate.js b/src/libs/translate.js index 5985dcdd806..d8f2e82bb04 100644 --- a/src/libs/translate.js +++ b/src/libs/translate.js @@ -46,7 +46,7 @@ function translate(locale = CONST.DEFAULT_LOCALE, phrase, variables = {}) { return Str.result(translationValue, variables); } if (localeLanguage !== 'en') { - Log.alert(`${phrase} was not found in the ${localeLanguage} locale`, {}, false); + Log.alert(`${phrase} was not found in the ${localeLanguage} locale`); } // Phrase is not translated, search it in default language (en) @@ -59,7 +59,7 @@ function translate(locale = CONST.DEFAULT_LOCALE, phrase, variables = {}) { // on development throw an error if (Config.IS_IN_PRODUCTION) { const phraseString = Array.isArray(phrase) ? phrase.join('.') : phrase; - Log.alert(`${phraseString} was not found in the en locale`, {}, false); + Log.alert(`${phraseString} was not found in the en locale`); return phraseString; } throw new Error(`${phrase} was not found in the default language`); From 88884f03a2fb7146820e3f4b9ff60a00dbfed67c Mon Sep 17 00:00:00 2001 From: Ionatan Wiznia Date: Thu, 29 Jul 2021 15:37:20 +0200 Subject: [PATCH 05/14] Style --- src/libs/HttpUtils.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libs/HttpUtils.js b/src/libs/HttpUtils.js index e0093b016ab..dccb4948bc9 100644 --- a/src/libs/HttpUtils.js +++ b/src/libs/HttpUtils.js @@ -31,7 +31,12 @@ function processHTTPRequest(url, method = 'get', body = null) { */ function xhr(command, data, type = CONST.NETWORK.METHOD.POST, shouldUseSecure = false) { if (command !== 'Log') { - info('Making API request', false, {command, type, shouldUseSecure, rvl: data.returnValueList}); + info('Making API request', false, { + command, + type, + shouldUseSecure, + rvl: data.returnValueList, + }); } const formData = new FormData(); _.each(data, (val, key) => formData.append(key, val)); From fb6660e531aa4a9ead730fcc14e144e71bc589ad Mon Sep 17 00:00:00 2001 From: Ionatan Wiznia Date: Thu, 29 Jul 2021 17:59:13 +0200 Subject: [PATCH 06/14] Use new package, fix httputils --- package-lock.json | 4 ++-- package.json | 2 +- src/libs/HttpUtils.js | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index f8e3b8177ed..4eedf511db4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23070,8 +23070,8 @@ } }, "expensify-common": { - "version": "git://github.com/Expensify/expensify-common.git#5d69f59ad2e916edf15ecb879e3ca27746cb274a", - "from": "git://github.com/Expensify/expensify-common.git#5d69f59ad2e916edf15ecb879e3ca27746cb274a", + "version": "git://github.com/Expensify/expensify-common.git#1861959834592db064d4cf1ecbaedc34e3a16432", + "from": "git://github.com/Expensify/expensify-common.git#1861959834592db064d4cf1ecbaedc34e3a16432", "requires": { "classnames": "2.3.1", "clipboard": "2.0.4", diff --git a/package.json b/package.json index 52eb3d7e05c..7f96784d8f0 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "electron-log": "^4.3.5", "electron-serve": "^1.0.0", "electron-updater": "^4.3.4", - "expensify-common": "git://github.com/Expensify/expensify-common.git#5d69f59ad2e916edf15ecb879e3ca27746cb274a", + "expensify-common": "git://github.com/Expensify/expensify-common.git#1861959834592db064d4cf1ecbaedc34e3a16432", "expo-haptics": "^10.0.0", "file-loader": "^6.0.0", "html-entities": "^1.3.1", diff --git a/src/libs/HttpUtils.js b/src/libs/HttpUtils.js index dccb4948bc9..c986fde3165 100644 --- a/src/libs/HttpUtils.js +++ b/src/libs/HttpUtils.js @@ -52,6 +52,7 @@ function xhr(command, data, type = CONST.NETWORK.METHOD.POST, shouldUseSecure = requestID: response.requestID, }); } + return response; }); } From 8be321d8ff577a9fa7071ad1bd4719940630e1b5 Mon Sep 17 00:00:00 2001 From: Ionatan Wiznia Date: Thu, 29 Jul 2021 21:03:17 +0200 Subject: [PATCH 07/14] Move app state listener to actions --- src/App.js | 48 +++++++++-------------------------------- src/libs/actions/App.js | 10 +++++++++ 2 files changed, 20 insertions(+), 38 deletions(-) diff --git a/src/App.js b/src/App.js index 2d027264087..0ac8e0ac8e6 100644 --- a/src/App.js +++ b/src/App.js @@ -1,10 +1,9 @@ -import React, {Component} from 'react'; -import {AppState, LogBox} from 'react-native'; +import React from 'react'; +import {LogBox} from 'react-native'; import {SafeAreaProvider} from 'react-native-safe-area-context'; import CustomStatusBar from './components/CustomStatusBar'; import ErrorBoundary from './components/ErrorBoundary'; import Expensify from './Expensify'; -import Log from './libs/Log'; LogBox.ignoreLogs([ // Basically it means that if the app goes in the background and back to foreground on Android, @@ -16,41 +15,14 @@ LogBox.ignoreLogs([ 'Require cycle: node_modules/rn-fetch-blob', ]); -class App extends Component { - constructor(props) { - super(props); - this.state = { - appState: AppState.currentState, - }; - this.handleAppStateChange = this.handleAppStateChange.bind(this); - } - - componentDidMount() { - AppState.addEventListener('change', this.handleAppStateChange); - } - - componentWillUnmount() { - AppState.removeEventListener('change', this.handleAppStateChange); - } - - handleAppStateChange(nextAppState) { - if (nextAppState.match(/inactive|background/) && this.state.appState === 'active') { - Log.info('Flushing logs as app is going inactive', true, {}, true); - } - this.setState({appState: nextAppState}); - } - - render() { - return ( - - - - - - - ); - } -} +const App = () => ( + + + + + + +); App.displayName = 'App'; diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index e3b339fdc7a..c9cc34e2077 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -1,8 +1,10 @@ +import {AppState} from 'react-native'; import Onyx from 'react-native-onyx'; import ONYXKEYS from '../../ONYXKEYS'; import * as API from '../API'; import Firebase from '../Firebase'; import CONST from '../../CONST'; +import Log from '../Log'; let isSidebarLoaded; @@ -36,6 +38,14 @@ function setSidebarLoaded() { Firebase.stopTrace(CONST.TIMING.SIDEBAR_LOADED); } +let appState; +AppState.addEventListener('change', (nextAppState) => { + if (nextAppState.match(/inactive|background/) && appState === 'active') { + Log.info('Flushing logs as app is going inactive', true, {}, true); + } + appState = nextAppState; +}); + export { setCurrentURL, setLocale, From b8fe763ba0e6f5c902d44fcc866adfab985f1de0 Mon Sep 17 00:00:00 2001 From: Ionatan Wiznia Date: Thu, 29 Jul 2021 21:50:18 +0200 Subject: [PATCH 08/14] Readd log param and remove bad suppress --- src/libs/API.js | 6 ++---- src/libs/Network.js | 1 - 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/libs/API.js b/src/libs/API.js index 0ed7d9b8888..5799a67a57c 100644 --- a/src/libs/API.js +++ b/src/libs/API.js @@ -463,15 +463,13 @@ function GetRequestCountryCode() { /** * @param {Object} parameters - * @param {String} parameters.message - * @param {Object} parameters.parameters * @param {String} parameters.expensifyCashAppVersion - * @param {String} [parameters.email] + * @param {Object[]} parameters.logPacket * @returns {Promise} */ function Log(parameters) { const commandName = 'Log'; - requireParameters(['logPacket'], + requireParameters(['logPacket', 'expensifyCashAppVersion'], parameters, commandName); // Note: We are forcing Log to run since it requires no authToken and should only be queued when we are offline. diff --git a/src/libs/Network.js b/src/libs/Network.js index fce1a21182e..5116cc2d002 100644 --- a/src/libs/Network.js +++ b/src/libs/Network.js @@ -1,7 +1,6 @@ import _ from 'underscore'; import lodashGet from 'lodash/get'; import Onyx from 'react-native-onyx'; -// eslint-disable-next-line import/no-cycle import HttpUtils from './HttpUtils'; import ONYXKEYS from '../ONYXKEYS'; import CONST from '../CONST'; From 20fbc21eb7a09fd61660c1c0e6618eca1dfdb0ee Mon Sep 17 00:00:00 2001 From: Ionatan Wiznia Date: Fri, 6 Aug 2021 13:02:55 +0200 Subject: [PATCH 09/14] Update common to not need the log hack --- package-lock.json | 4 ++-- package.json | 2 +- src/components/ErrorBoundary/index.js | 1 - src/libs/Log.js | 9 ++++----- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index 96783e9ab5b..e3819a65675 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23070,8 +23070,8 @@ } }, "expensify-common": { - "version": "git://github.com/Expensify/expensify-common.git#144b8175981774f7ffbec625189fc58b5779161c", - "from": "git://github.com/Expensify/expensify-common.git#144b8175981774f7ffbec625189fc58b5779161c", + "version": "git://github.com/Expensify/expensify-common.git#f31dd1ff3f3591d58ce3ccb1e86479fd54a54a88", + "from": "git://github.com/Expensify/expensify-common.git#f31dd1ff3f3591d58ce3ccb1e86479fd54a54a88", "requires": { "classnames": "2.3.1", "clipboard": "2.0.4", diff --git a/package.json b/package.json index 3f065ac3fb1..01fe1a74b5b 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "electron-log": "^4.3.5", "electron-serve": "^1.0.0", "electron-updater": "^4.3.4", - "expensify-common": "git://github.com/Expensify/expensify-common.git#144b8175981774f7ffbec625189fc58b5779161c", + "expensify-common": "git://github.com/Expensify/expensify-common.git#f31dd1ff3f3591d58ce3ccb1e86479fd54a54a88", "expo-haptics": "^10.0.0", "file-loader": "^6.0.0", "html-entities": "^1.3.1", diff --git a/src/components/ErrorBoundary/index.js b/src/components/ErrorBoundary/index.js index 548a278fa52..37daf447ad1 100644 --- a/src/components/ErrorBoundary/index.js +++ b/src/components/ErrorBoundary/index.js @@ -5,5 +5,4 @@ BaseErrorBoundary.defaultProps.logError = (errorMessage, error, errorInfo) => { // Log the error to the server Log.alert(errorMessage, {error: error.message, errorInfo}, false); }; -window.Log = Log; export default BaseErrorBoundary; diff --git a/src/libs/Log.js b/src/libs/Log.js index 782a3cd2792..1bff8aa84fc 100644 --- a/src/libs/Log.js +++ b/src/libs/Log.js @@ -7,24 +7,24 @@ import NetworkConnection from './NetworkConnection'; import HttpUtils from './HttpUtils'; let timeout = null; -let info; /** * Network interface for logger. * + * @param {Logger} logger * @param {Object} params * @param {Object} params.parameters * @param {String} params.message * @return {Promise} */ -function serverLoggingCallback(params) { +function serverLoggingCallback(logger, params) { const requestParams = params; requestParams.expensifyCashAppVersion = `expensifyCash[${getPlatform()}]${version}`; if (requestParams.parameters) { requestParams.parameters = JSON.stringify(params.parameters); } clearTimeout(timeout); - timeout = setTimeout(() => info('Flushing logs older than 10 minutes', true, {}, true), 10 * 60 * 1000); + timeout = setTimeout(() => logger.info('Flushing logs older than 10 minutes', true, {}, true), 10 * 60 * 1000); return API.Log(requestParams); } @@ -39,8 +39,7 @@ const Log = new Logger({ }, isDebug: !CONFIG.IS_IN_PRODUCTION, }); -info = Log.info; -timeout = setTimeout(() => info('Flushing logs older than 10 minutes', true, {}, true), 10 * 60 * 1000); +timeout = setTimeout(() => Log.info('Flushing logs older than 10 minutes', true, {}, true), 10 * 60 * 1000); NetworkConnection.registerLogInfoCallback(Log.info); HttpUtils.setLogger(Log); From 053b75d2da36054facf0e9f6e11d6ddc799212df Mon Sep 17 00:00:00 2001 From: Ionatan Wiznia Date: Fri, 13 Aug 2021 16:11:25 +0200 Subject: [PATCH 10/14] Use latest version of common --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index fcd4f7cef9f..aea1a5693e6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23082,8 +23082,8 @@ } }, "expensify-common": { - "version": "git://github.com/Expensify/expensify-common.git#8f286b5826a041ecb739cff1ad6940ffb9324bee", - "from": "git://github.com/Expensify/expensify-common.git#8f286b5826a041ecb739cff1ad6940ffb9324bee", + "version": "git://github.com/Expensify/expensify-common.git#8aba7d37767ecfc7abee366c44aee7043f2c2bd4", + "from": "git://github.com/Expensify/expensify-common.git#8aba7d37767ecfc7abee366c44aee7043f2c2bd4", "requires": { "classnames": "2.3.1", "clipboard": "2.0.4", diff --git a/package.json b/package.json index 7194145cc15..2b2c21e5ab9 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "electron-log": "^4.3.5", "electron-serve": "^1.0.0", "electron-updater": "^4.3.4", - "expensify-common": "git://github.com/Expensify/expensify-common.git#8f286b5826a041ecb739cff1ad6940ffb9324bee", + "expensify-common": "git://github.com/Expensify/expensify-common.git#8aba7d37767ecfc7abee366c44aee7043f2c2bd4", "expo-haptics": "^10.0.0", "file-loader": "^6.0.0", "html-entities": "^1.3.1", From 04287bb333c7b0bafefce4031d4d72f5317d5fb8 Mon Sep 17 00:00:00 2001 From: Ionatan Wiznia Date: Fri, 13 Aug 2021 16:19:17 +0200 Subject: [PATCH 11/14] Add missing imports --- src/Expensify.js | 5 ++++- src/libs/actions/App.js | 3 +-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Expensify.js b/src/Expensify.js index 4f716a9601c..71916c0e12a 100644 --- a/src/Expensify.js +++ b/src/Expensify.js @@ -2,7 +2,7 @@ import lodashGet from 'lodash/get'; import PropTypes from 'prop-types'; import React, {PureComponent} from 'react'; import {View, AppState} from 'react-native'; -import {withOnyx} from 'react-native-onyx'; +import Onyx, {withOnyx} from 'react-native-onyx'; import _ from 'underscore'; import BootSplash from './libs/BootSplash'; @@ -19,6 +19,9 @@ import {growlRef} from './libs/Growl'; import StartupTimer from './libs/StartupTimer'; import {setRedirectToWorkspaceNewAfterSignIn} from './libs/actions/Session'; import {create} from './libs/actions/Policy'; +import CONST from './CONST'; +import Log from './libs/Log'; +import listenToStorageEvents from './libs/listenToStorageEvents'; // Initialize the store when the app loads for the first time Onyx.init({ diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index b374b33d96d..a81f4c21359 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -1,6 +1,5 @@ -import {AppState} from 'react-native'; +import {AppState, Linking} from 'react-native'; import Onyx from 'react-native-onyx'; -import {Linking} from 'react-native'; import lodashGet from 'lodash/get'; import ONYXKEYS from '../../ONYXKEYS'; import * as API from '../API'; From 85f7ad6e44eb662aa28a927eb88939293a5b7dab Mon Sep 17 00:00:00 2001 From: Ionatan Wiznia Date: Fri, 13 Aug 2021 17:17:12 +0200 Subject: [PATCH 12/14] Update to latest of common --- package-lock.json | 4 ++-- package.json | 2 +- src/libs/NetworkConnection.js | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index aea1a5693e6..87febd333b0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23082,8 +23082,8 @@ } }, "expensify-common": { - "version": "git://github.com/Expensify/expensify-common.git#8aba7d37767ecfc7abee366c44aee7043f2c2bd4", - "from": "git://github.com/Expensify/expensify-common.git#8aba7d37767ecfc7abee366c44aee7043f2c2bd4", + "version": "git://github.com/Expensify/expensify-common.git#5fb22bd4a3619eb9fe9e2a9c0dc25e291863a2a2", + "from": "git://github.com/Expensify/expensify-common.git#5fb22bd4a3619eb9fe9e2a9c0dc25e291863a2a2", "requires": { "classnames": "2.3.1", "clipboard": "2.0.4", diff --git a/package.json b/package.json index 2b2c21e5ab9..25fc3bd66ed 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "electron-log": "^4.3.5", "electron-serve": "^1.0.0", "electron-updater": "^4.3.4", - "expensify-common": "git://github.com/Expensify/expensify-common.git#8aba7d37767ecfc7abee366c44aee7043f2c2bd4", + "expensify-common": "git://github.com/Expensify/expensify-common.git#5fb22bd4a3619eb9fe9e2a9c0dc25e291863a2a2", "expo-haptics": "^10.0.0", "file-loader": "^6.0.0", "html-entities": "^1.3.1", diff --git a/src/libs/NetworkConnection.js b/src/libs/NetworkConnection.js index 5bc66855e92..4e83f5a6d96 100644 --- a/src/libs/NetworkConnection.js +++ b/src/libs/NetworkConnection.js @@ -19,7 +19,7 @@ const reconnectionCallbacks = []; * Loop over all reconnection callbacks and fire each one */ const triggerReconnectionCallbacks = _.throttle((reason) => { - logInfo(`[NetworkConnection] Firing reconnection callbacks because ${reason}`, true); + logInfo(`[NetworkConnection] Firing reconnection callbacks because ${reason}`); Onyx.set(ONYXKEYS.IS_LOADING_AFTER_RECONNECT, true); promiseAllSettled(_.map(reconnectionCallbacks, callback => callback())) .then(() => Onyx.set(ONYXKEYS.IS_LOADING_AFTER_RECONNECT, false)); @@ -67,7 +67,7 @@ function listenForReconnect() { * Tear down the event listeners when we are finished with them. */ function stopListeningForReconnect() { - logInfo('[NetworkConnection] stopListeningForReconnect called', true); + logInfo('[NetworkConnection] stopListeningForReconnect called'); if (unsubscribeFromNetInfo) { unsubscribeFromNetInfo(); unsubscribeFromNetInfo = undefined; From 124aade409c58685eaf5d894bbcf140f514612b2 Mon Sep 17 00:00:00 2001 From: Ionatan Wiznia Date: Mon, 16 Aug 2021 12:44:37 +0200 Subject: [PATCH 13/14] Remove deleted code, move navigation log to navigation event --- src/Expensify.js | 32 +-------------------------- src/libs/Navigation/Navigation.js | 2 -- src/libs/Navigation/NavigationRoot.js | 2 ++ 3 files changed, 3 insertions(+), 33 deletions(-) diff --git a/src/Expensify.js b/src/Expensify.js index 71916c0e12a..15a41f9b248 100644 --- a/src/Expensify.js +++ b/src/Expensify.js @@ -2,7 +2,7 @@ import lodashGet from 'lodash/get'; import PropTypes from 'prop-types'; import React, {PureComponent} from 'react'; import {View, AppState} from 'react-native'; -import Onyx, {withOnyx} from 'react-native-onyx'; +import {withOnyx} from 'react-native-onyx'; import _ from 'underscore'; import BootSplash from './libs/BootSplash'; @@ -19,36 +19,6 @@ import {growlRef} from './libs/Growl'; import StartupTimer from './libs/StartupTimer'; import {setRedirectToWorkspaceNewAfterSignIn} from './libs/actions/Session'; import {create} from './libs/actions/Policy'; -import CONST from './CONST'; -import Log from './libs/Log'; -import listenToStorageEvents from './libs/listenToStorageEvents'; - -// Initialize the store when the app loads for the first time -Onyx.init({ - keys: ONYXKEYS, - safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS], - initialKeyStates: { - - // Clear any loading and error messages so they do not appear on app startup - [ONYXKEYS.SESSION]: {loading: false, shouldShowComposeInput: true}, - [ONYXKEYS.ACCOUNT]: CONST.DEFAULT_ACCOUNT_DATA, - [ONYXKEYS.NETWORK]: {isOffline: false}, - [ONYXKEYS.IOU]: { - loading: false, error: false, creatingIOUTransaction: false, isRetrievingCurrency: false, - }, - [ONYXKEYS.IS_SIDEBAR_LOADED]: false, - }, - registerStorageEventListener: (onStorageEvent) => { - listenToStorageEvents(onStorageEvent); - }, -}); -Onyx.registerLogger(({level, message}) => { - if (level === 'alert') { - Log.alert(message, {}, false); - } else { - Log.client(message); - } -}); const propTypes = { /* Onyx Props */ diff --git a/src/libs/Navigation/Navigation.js b/src/libs/Navigation/Navigation.js index 06e6b526a8b..069bc6823c3 100644 --- a/src/libs/Navigation/Navigation.js +++ b/src/libs/Navigation/Navigation.js @@ -4,7 +4,6 @@ import {StackActions, DrawerActions, useLinkBuilder} from '@react-navigation/nat import PropTypes from 'prop-types'; import Onyx from 'react-native-onyx'; import linkTo from './linkTo'; -import Log from '../Log'; import ROUTES from '../../ROUTES'; import SCREENS from '../../SCREENS'; import CustomActions from './CustomActions'; @@ -55,7 +54,6 @@ function goBack(shouldOpenDrawer = true) { * @param {String} route */ function navigate(route = ROUTES.HOME) { - Log.info('Navigating to route', false, {route}); if (route === ROUTES.HOME) { if (isLoggedIn) { openDrawer(); diff --git a/src/libs/Navigation/NavigationRoot.js b/src/libs/Navigation/NavigationRoot.js index ec8745ec6cf..903b71f161c 100644 --- a/src/libs/Navigation/NavigationRoot.js +++ b/src/libs/Navigation/NavigationRoot.js @@ -6,6 +6,7 @@ import linkingConfig from './linkingConfig'; import AppNavigator from './AppNavigator'; import {setCurrentURL} from '../actions/App'; import FullScreenLoadingIndicator from '../../components/FullscreenLoadingIndicator'; +import Log from '../Log'; const propTypes = { /** Whether the current user is logged in with an authToken */ @@ -29,6 +30,7 @@ class NavigationRoot extends Component { } const path = getPathFromState(state, linkingConfig.config); + Log.info('Navigating to route', false, {path}); setCurrentURL(path); } From f42e8db0773dfa01dfbcd825a81ec6690ea9a88f Mon Sep 17 00:00:00 2001 From: Ionatan Wiznia Date: Mon, 16 Aug 2021 13:33:44 +0200 Subject: [PATCH 14/14] Clarify emtpy logging method --- src/libs/HttpUtils.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/HttpUtils.js b/src/libs/HttpUtils.js index c986fde3165..dc4b2e817f3 100644 --- a/src/libs/HttpUtils.js +++ b/src/libs/HttpUtils.js @@ -2,6 +2,7 @@ import _ from 'underscore'; import CONFIG from '../CONFIG'; import CONST from '../CONST'; +// To avoid a circular dependency, we can't include Log here, so instead, we define an empty logging method and expose the setLogger method to set the logger from outside this file let info = () => {}; /**