Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use server logs instead of console.debug most places #5827

Merged
merged 8 commits into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/components/AddPlaidBankAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import PropTypes from 'prop-types';
import lodashGet from 'lodash/get';
import {withOnyx} from 'react-native-onyx';
import Log from '../libs/Log';
import PlaidLink from './PlaidLink';
import {
clearPlaidBankAccountsAndToken,
Expand Down Expand Up @@ -163,12 +164,12 @@ class AddPlaidBankAccount extends React.Component {
<PlaidLink
token={this.props.plaidLinkToken}
onSuccess={({publicToken, metadata}) => {
console.debug('[PlaidLink] Success: ', {publicToken, metadata});
Log.info('[PlaidLink] Success!');
getPlaidBankAccounts(publicToken, metadata.institution.name);
this.setState({institution: metadata.institution});
}}
onError={(error) => {
console.debug(`Plaid Error: ${error.message}`);
Log.hmmm('[PlaidLink] Error: ', error.message);
}}

// User prematurely exited the Plaid flow
Expand Down
3 changes: 2 additions & 1 deletion src/components/ImageWithSizeCalculation.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, {PureComponent} from 'react';
import {Image} from 'react-native';
import PropTypes from 'prop-types';
import Log from '../libs/Log';
import styles from '../styles/styles';

const propTypes = {
Expand Down Expand Up @@ -63,7 +64,7 @@ class ImageWithSizeCalculation extends PureComponent {

this.props.onMeasure({width, height});
}, (error) => {
console.debug('Unable to fetch image to calculate size', {error});
Log.hmmm('Unable to fetch image to calculate size', {error, url: this.props.url});
});
}

Expand Down
3 changes: 2 additions & 1 deletion src/components/OptionsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import _ from 'underscore';
import React, {forwardRef, Component} from 'react';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import Log from '../libs/Log';
import styles from '../styles/styles';
import OptionRow from '../pages/home/sidebar/OptionRow';
import optionPropTypes from './optionPropTypes';
Expand Down Expand Up @@ -154,7 +155,7 @@ class OptionsList extends Component {
* @param {Object} info
*/
onScrollToIndexFailed(info) {
console.debug(info);
Log.hmmm('[OptionsList] scrollToIndex failed', info);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/components/PlaidLink/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {useCallback, useEffect} from 'react';
import {usePlaidLink} from 'react-plaid-link';
import {plaidLinkPropTypes, plaidLinkDefaultProps} from './plaidLinkPropTypes';
import Log from '../../libs/Log';

const PlaidLink = (props) => {
const onSuccess = useCallback((publicToken, metadata) => {
Expand All @@ -11,11 +12,11 @@ const PlaidLink = (props) => {
token: props.token,
onSuccess,
onExit: (exitError, metadata) => {
console.debug('[PlaidLink] Exit: ', {exitError, metadata});
Log.info('[PlaidLink] Exit: ', false, {exitError, metadata});
props.onExit();
},
onEvent: (event, metadata) => {
console.debug('[PlaidLink] Event: ', {event, metadata});
Log.info('[PlaidLink] Event: ', false, {event, metadata});
},
});

Expand Down
3 changes: 2 additions & 1 deletion src/components/PlaidLink/index.native.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import {NativeEventEmitter} from 'react-native';
import {openLink} from 'react-native-plaid-link-sdk';
import Log from '../../libs/Log';
import CONST from '../../CONST';
import nativeModule from './nativeModule';
import {plaidLinkPropTypes, plaidLinkDefaultProps} from './plaidLinkPropTypes';
Expand Down Expand Up @@ -35,7 +36,7 @@ class PlaidLink extends React.Component {
* @param {*} event
*/
onEvent(event) {
console.debug('[PlaidLink] Handled Plaid Event: ', event);
Log.info('[PlaidLink] Handled Plaid Event: ', false, event);
if (event.eventName === CONST.PLAID.EVENT.ERROR) {
this.props.onError(event.metadata);
} else if (event.eventName === CONST.PLAID.EVENT.EXIT) {
Expand Down
13 changes: 10 additions & 3 deletions src/libs/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import redirectToSignIn from './actions/SignInRedirect';
import * as Network from './Network';
import isViaExpensifyCashNative from './isViaExpensifyCashNative';

// eslint-disable-next-line import/no-cycle
import LogUtil from './Log';

let isAuthenticating;
let credentials;
Onyx.connect({
Expand Down Expand Up @@ -57,7 +60,7 @@ function addDefaultValuesToParameters(command, parameters) {
if (!authToken) {
redirectToSignIn();

console.debug('A request was made without an authToken', {command, parameters});
LogUtil.info('A request was made without an authToken', false, {command, parameters});
Network.pauseRequestQueue();
Network.clearRequestQueue();
Network.unpauseRequestQueue();
Expand Down Expand Up @@ -172,7 +175,11 @@ Network.registerResponseHandler((queuedRequest, response) => {
});

Network.registerErrorHandler((queuedRequest, error) => {
console.debug('[API] Handled error when making request', error);
if (queuedRequest.command !== 'Log') {
LogUtil.hmmm('[API] Handled error when making request', error);
} else {
console.debug('[API] There was an error in the Log API command, unable to log to server!', error);
}

// Set an error state and signify we are done loading
Onyx.merge(ONYXKEYS.SESSION, {loading: false, error: 'Cannot connect to server'});
Expand Down Expand Up @@ -304,7 +311,7 @@ function reauthenticate(command = '') {
// If we experience something other than a network error then redirect the user to sign in
redirectToSignIn(error.message);

console.debug('Redirecting to Sign In because we failed to reauthenticate', {
LogUtil.hmmm('Redirecting to Sign In because we failed to reauthenticate', {
command,
error: error.message,
});
Expand Down
4 changes: 3 additions & 1 deletion src/libs/Log.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import Logger from 'expensify-common/lib/Logger';
import * as API from './API';
import CONFIG from '../CONFIG';
import getPlatform from './getPlatform';
import {version} from '../../package.json';
import NetworkConnection from './NetworkConnection';
import HttpUtils from './HttpUtils';

// eslint-disable-next-line import/no-cycle
import * as API from './API';

let timeout = null;

/**
Expand Down
13 changes: 7 additions & 6 deletions src/libs/Navigation/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '@react-navigation/native';
import PropTypes from 'prop-types';
import Onyx from 'react-native-onyx';
import Log from '../Log';
import linkTo from './linkTo';
import ROUTES from '../../ROUTES';
import SCREENS from '../../SCREENS';
Expand Down Expand Up @@ -39,7 +40,7 @@ function setDidTapNotification() {
*/
function openDrawer() {
if (!navigationRef.isReady()) {
console.debug('[Navigation] openDrawer failed because navigation ref was not yet ready');
Log.hmmm('[Navigation] openDrawer failed because navigation ref was not yet ready');
return;
}
navigationRef.current.dispatch(DrawerActions.openDrawer());
Expand All @@ -51,7 +52,7 @@ function openDrawer() {
*/
function closeDrawer() {
if (!navigationRef.isReady()) {
console.debug('[Navigation] closeDrawer failed because navigation ref was not yet ready');
Log.hmmm('[Navigation] closeDrawer failed because navigation ref was not yet ready');
return;
}
navigationRef.current.dispatch(DrawerActions.closeDrawer());
Expand All @@ -74,12 +75,12 @@ function getDefaultDrawerState(isSmallScreenWidth) {
*/
function goBack(shouldOpenDrawer = true) {
if (!navigationRef.isReady()) {
console.debug('[Navigation] goBack failed because navigation ref was not yet ready');
Log.hmmm('[Navigation] goBack failed because navigation ref was not yet ready');
return;
}

if (!navigationRef.current.canGoBack()) {
console.debug('Unable to go back');
Log.hmmm('[Navigation] Unable to go back');
if (shouldOpenDrawer) {
openDrawer();
}
Expand All @@ -95,7 +96,7 @@ function goBack(shouldOpenDrawer = true) {
*/
function navigate(route = ROUTES.HOME) {
if (!navigationRef.isReady()) {
console.debug('[Navigation] navigate failed because navigation ref was not yet ready');
Log.hmmm('[Navigation] navigate failed because navigation ref was not yet ready', {route});
return;
}

Expand Down Expand Up @@ -129,7 +130,7 @@ function navigate(route = ROUTES.HOME) {
*/
function dismissModal(shouldOpenDrawer = false) {
if (!navigationRef.isReady()) {
console.debug('[Navigation] dismissModal failed because navigation ref was not yet ready');
Log.hmmm('[Navigation] dismissModal failed because navigation ref was not yet ready');
return;
}

Expand Down
21 changes: 9 additions & 12 deletions src/libs/Notification/PushNotification/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import _ from 'underscore';
import {AppState} from 'react-native';
import {UrbanAirship, EventType} from 'urbanairship-react-native';
import lodashGet from 'lodash/get';
import Log from '../../Log';
import NotificationType from './NotificationType';

const notificationEventActionMap = {};
Expand All @@ -21,25 +22,21 @@ function pushNotificationEventCallback(eventType, notification) {
payload = JSON.parse(payload);
}

console.debug(`[PUSH_NOTIFICATION] ${eventType}`, {
title: notification.title,
message: notification.alert,
payload,
});
Log.info(`[PUSH_NOTIFICATION] Callback triggered for ${eventType}`);

if (!payload) {
console.debug('[PUSH_NOTIFICATION] Notification has null or undefined payload, not executing any callback.');
Log.warn('[PUSH_NOTIFICATION] Notification has null or undefined payload, not executing any callback.');
return;
}

if (!payload.type) {
console.debug('[PUSH_NOTIFICATION] No type value provided in payload, not executing any callback.');
Log.warn('[PUSH_NOTIFICATION] No type value provided in payload, not executing any callback.');
return;
}

const action = actionMap[payload.type];
if (!action) {
console.debug('[PUSH_NOTIFICATION] No callback set up: ', {
Log.warn('[PUSH_NOTIFICATION] No callback set up: ', {
event: eventType,
notificationType: payload.type,
});
Expand All @@ -61,7 +58,7 @@ function init() {
// If a push notification is received while the app is in foreground,
// we'll assume pusher is connected so we'll ignore it and not fetch the same data twice.
if (AppState.currentState === 'active') {
console.debug('[PUSH_NOTIFICATION] Push received while app is in foreground, not executing any callback.');
Log.info('[PUSH_NOTIFICATION] Push received while app is in foreground, not executing any callback.');
return;
}

Expand Down Expand Up @@ -90,21 +87,21 @@ function register(accountID) {
UrbanAirship.enableUserPushNotifications()
.then((isEnabled) => {
if (!isEnabled) {
console.debug('[PUSH_NOTIFICATIONS] User has disabled visible push notifications for this app.');
Log.info('[PUSH_NOTIFICATIONS] User has disabled visible push notifications for this app.');
}
});

// Register this device as a named user in AirshipAPI.
// Regardless of the user's opt-in status, we still want to receive silent push notifications.
console.debug(`[PUSH_NOTIFICATIONS] Subscribing to notifications for account ID ${accountID}`);
Log.info(`[PUSH_NOTIFICATIONS] Subscribing to notifications for account ID ${accountID}`);
UrbanAirship.setNamedUser(accountID.toString());
}

/**
* Deregister this device from push notifications.
*/
function deregister() {
console.debug('[PUSH_NOTIFICATIONS] Unsubscribing from push notifications.');
Log.info('[PUSH_NOTIFICATIONS] Unsubscribing from push notifications.');
UrbanAirship.setNamedUser(null);
UrbanAirship.removeAllListeners(EventType.PushReceived);
UrbanAirship.removeAllListeners(EventType.NotificationResponse);
Expand Down
25 changes: 12 additions & 13 deletions src/libs/Pusher/pusher.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import _ from 'underscore';
import Pusher from './library';
import TYPE from './EventType';
import Log from '../Log';

let socket;
const socketEventCallbacks = [];
Expand Down Expand Up @@ -118,7 +119,7 @@ function bindEventToChannel(channel, eventName, eventCallback = () => {}, isChun
try {
data = _.isObject(eventData) ? eventData : JSON.parse(eventData);
} catch (err) {
console.debug('Unable to parse JSON response from Pusher', 0, {error: err, eventData});
Log.alert('[Pusher] Unable to parse JSON response from Pusher', {error: err, eventData});
return;
}

Expand Down Expand Up @@ -151,7 +152,7 @@ function bindEventToChannel(channel, eventName, eventCallback = () => {}, isChun
try {
eventCallback(JSON.parse(chunkedEvent.chunks.join('')));
} catch (err) {
console.debug('[Pusher] Unable to parse chunked JSON response from Pusher', 0, {
Log.alert('[Pusher] Unable to parse chunked JSON response from Pusher', {
error: err,
eventData: chunkedEvent.chunks.join(''),
});
Expand Down Expand Up @@ -193,7 +194,7 @@ function subscribe(
most likely has been called before Pusher.init()`);
}

console.debug('[Pusher] Attempting to subscribe to channel', true, {channelName, eventName});
Log.info('[Pusher] Attempting to subscribe to channel', false, {channelName, eventName});
let channel = getChannel(channelName);

if (!channel || !channel.subscribed) {
Expand All @@ -217,7 +218,7 @@ function subscribe(

channel.bind('pusher:subscription_error', (status) => {
if (status === 403) {
console.debug('[Pusher] Issue authenticating with Pusher during subscribe attempt.', 0, {
Log.hmmm('[Pusher] Issue authenticating with Pusher during subscribe attempt.', {
channelName,
status,
});
Expand All @@ -243,21 +244,19 @@ function unsubscribe(channelName, eventName = '') {
const channel = getChannel(channelName);

if (!channel) {
console.debug(`[Pusher] Attempted to unsubscribe or unbind from a channel,
but Pusher-JS has no knowledge of it`, 0, {channelName, eventName});
Log.hmmm('[Pusher] Attempted to unsubscribe or unbind from a channel, but Pusher-JS has no knowledge of it', {channelName, eventName});
return;
}

if (eventName) {
console.debug('[Pusher] Unbinding event', true, {eventName, channelName});
Log.info('[Pusher] Unbinding event', false, {eventName, channelName});
channel.unbind(eventName);
} else {
if (!channel.subscribed) {
console.debug(`[Pusher] Attempted to unsubscribe from channel,
but we are not subscribed to begin with`, 0, {channelName});
Log.info('Pusher] Attempted to unsubscribe from channel, but we are not subscribed to begin with', false, {channelName});
return;
}
console.debug('[Pusher] Unsubscribing from channel', true, {channelName});
Log.info('[Pusher] Unsubscribing from channel', false, {channelName});

channel.unbind();
socket.unsubscribe(channelName);
Expand Down Expand Up @@ -339,7 +338,7 @@ function registerCustomAuthorizer(authorizer) {
*/
function disconnect() {
if (!socket) {
console.debug('[Pusher] Attempting to disconnect from Pusher before initialisation has occurred, ignoring.');
Log.info('[Pusher] Attempting to disconnect from Pusher before initialisation has occurred, ignoring.');
return;
}

Expand All @@ -352,11 +351,11 @@ function disconnect() {
*/
function reconnect() {
if (!socket) {
console.debug('[Pusher] Unable to reconnect since Pusher instance does not yet exist.');
Log.info('[Pusher] Unable to reconnect since Pusher instance does not yet exist.');
return;
}

console.debug('[Pusher] Reconnecting to Pusher');
Log.info('[Pusher] Reconnecting to Pusher');
socket.disconnect();
socket.connect();
}
Expand Down
4 changes: 1 addition & 3 deletions src/libs/actions/PersonalDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ function fetchPersonalDetails() {

// Set my personal details so they can be easily accessed and subscribed to on their own key
Onyx.merge(ONYXKEYS.MY_PERSONAL_DETAILS, myPersonalDetails);
})
.catch(error => console.debug('Error fetching personal details', error));
});
}

/**
Expand Down Expand Up @@ -261,7 +260,6 @@ function fetchLocalCurrency() {
.then(() => {
Onyx.merge(ONYXKEYS.MY_PERSONAL_DETAILS, {localCurrencyCode: currency});
})
.catch(error => console.debug(`Error fetching currency preference: , ${error}`))
.finally(() => {
Onyx.merge(ONYXKEYS.IOU, {
isRetrievingCurrency: false,
Expand Down
Loading