Skip to content

Commit

Permalink
feat: Add app and device info in fileLogger's email body
Browse files Browse the repository at this point in the history
  • Loading branch information
Ldoppea committed Feb 16, 2024
1 parent 338ac7c commit ef264df
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/app/domain/logger/fileLogger.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ describe('fileLogger', () => {
await sendLogs(client)

expect(Alert.alert).not.toHaveBeenCalled()
expect(sendLogFilesByEmailSpy).toHaveBeenCalledWith({
subject: 'Log file for ',
to: '[email protected]'
})
expect(sendLogFilesByEmailSpy).toHaveBeenCalledWith(
expect.objectContaining({
subject: 'Log file for ',
to: '[email protected]'
})
)
})

it('should do nothing and display alert if logs are disabled', async () => {
Expand Down
20 changes: 19 additions & 1 deletion src/app/domain/logger/fileLogger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import AsyncStorage from '@react-native-async-storage/async-storage'
import { Alert } from 'react-native'
import DeviceInfo from 'react-native-device-info'
import { FileLogger, LogLevel } from 'react-native-file-logger'

import type CozyClient from 'cozy-client'
Expand Down Expand Up @@ -49,7 +50,8 @@ export const sendLogs = async (client?: CozyClient): Promise<void> => {
log.info('Start email intent')
const emailResult = await FileLogger.sendLogFilesByEmail({
to: supportEmail,
subject: subject
subject: subject,
body: buildMessageBody()
})
log.info('Did finish email intent:', emailResult)
await hideSplashScreen(splashScreens.SEND_LOG_EMAIL)
Expand Down Expand Up @@ -94,3 +96,19 @@ const areLogsEnabledInAsyncStorage = async (): Promise<boolean> => {

return logsEnabled === '1'
}

const buildMessageBody = (): string => {
const appVersion = DeviceInfo.getVersion()
const appBuild = DeviceInfo.getBuildNumber()
const bundle = DeviceInfo.getBundleId()
const deviceBrand = DeviceInfo.getBrand()
const deviceModel = DeviceInfo.getModel()
const os = DeviceInfo.getSystemName()
const version = DeviceInfo.getSystemVersion()

const appInfo = `App info: ${appVersion} (${appBuild})`
const bundleInfo = `App bundle: ${bundle}`
const deviceInfo = `Device info: ${deviceBrand} ${deviceModel} ${os} ${version}`

return `${appInfo}\n${bundleInfo}\n${deviceInfo}`
}

0 comments on commit ef264df

Please sign in to comment.