Skip to content

Commit

Permalink
More log improvements: log navigations, improve logs, flush on logout…
Browse files Browse the repository at this point in the history
… and app inactive
  • Loading branch information
iwiznia committed Jul 23, 2021
1 parent 002bfef commit 2aa3b90
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 14 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
48 changes: 38 additions & 10 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -15,14 +16,41 @@ LogBox.ignoreLogs([
'Require cycle: node_modules/rn-fetch-blob',
]);

const App = () => (
<SafeAreaProvider>
<CustomStatusBar />
<ErrorBoundary errorMessage="E.cash crash caught by error boundary">
<Expensify />
</ErrorBoundary>
</SafeAreaProvider>
);
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 (
<SafeAreaProvider>
<CustomStatusBar />
<ErrorBoundary errorMessage="E.cash crash caught by error boundary">
<Expensify />
</ErrorBoundary>
</SafeAreaProvider>
);
}
}

App.displayName = 'App';

Expand Down
7 changes: 7 additions & 0 deletions src/libs/Log.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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);
}

Expand All @@ -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;
2 changes: 2 additions & 0 deletions src/libs/Navigation/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 5 additions & 1 deletion src/libs/PusherConnectionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 2 additions & 0 deletions src/libs/actions/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 2aa3b90

Please sign in to comment.