-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable setting logging level in the application
- create `DEFAULT_LOG_LEVEL` env variable for centralize logging level selection - ensure logging level persist across session using background storage - add logging level to global state and created `useLogger` to easily share the state
- Loading branch information
1 parent
87b1005
commit 002e672
Showing
22 changed files
with
266 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { useEffect } from 'react'; | ||
import { LogLevelString } from '@lace/common'; | ||
import { getBackgroundStorage, setBackgroundStorage } from '@lib/scripts/background/storage'; | ||
import { useWalletStore } from '@stores'; | ||
|
||
type UseLoggerReturnType = { | ||
currentLogLevel: LogLevelString; | ||
updateLogLevel: (logLevel: LogLevelString) => Promise<void>; | ||
}; | ||
|
||
export const useLogger = (): UseLoggerReturnType => { | ||
const { currentLogLevel, setCurrentLogLevel } = useWalletStore(); | ||
|
||
useEffect(() => { | ||
(async () => { | ||
await getBackgroundStorage().then((res) => { | ||
setCurrentLogLevel(res.logLevel); | ||
}); | ||
})(); | ||
}, [setCurrentLogLevel]); | ||
|
||
const updateLogLevel = async (logLevel: LogLevelString) => { | ||
setCurrentLogLevel(logLevel); | ||
await setBackgroundStorage({ logLevel }); | ||
}; | ||
|
||
return { currentLogLevel, updateLogLevel }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
apps/browser-extension-wallet/src/lib/scripts/background/session/is-lace-popup-open.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...let/src/views/browser-view/features/settings/components/SettingsLogging/LoggingDrawer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import React from 'react'; | ||
import { Radio, RadioChangeEvent, Typography } from 'antd'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { Drawer, DrawerHeader, DrawerNavigation, LogLevel, LogLevelString, toast } from '@lace/common'; | ||
import styles from '../SettingsLayout.module.scss'; | ||
import SwitchIcon from '@assets/icons/edit.component.svg'; | ||
import capitalize from 'lodash/capitalize'; | ||
import { useLogger } from '@hooks'; | ||
|
||
const { Text } = Typography; | ||
|
||
interface LoggingDrawerProps { | ||
visible: boolean; | ||
onClose: () => void; | ||
popupView?: boolean; | ||
} | ||
|
||
const logLevels: LogLevelString[] = Object.keys(LogLevel).filter((key) => | ||
Number.isNaN(Number(key)) | ||
) as LogLevelString[]; | ||
|
||
export const LoggingDrawer = ({ visible, onClose, popupView = false }: LoggingDrawerProps): React.ReactElement => { | ||
const { t } = useTranslation(); | ||
const { currentLogLevel, updateLogLevel } = useLogger(); | ||
|
||
const handleLoggingChange = async (event: RadioChangeEvent) => { | ||
const value = event.target.value as LogLevelString; | ||
await updateLogLevel(value); | ||
toast.notify({ | ||
text: 'Logging level has been updated', | ||
withProgressBar: true, | ||
icon: SwitchIcon | ||
}); | ||
}; | ||
|
||
return ( | ||
<Drawer | ||
visible={visible} | ||
onClose={onClose} | ||
title={ | ||
<DrawerHeader | ||
title="Logging Level" | ||
subtitle={!popupView ? 'This is the logging level for the extension' : undefined} | ||
popupView={popupView} | ||
/> | ||
} | ||
navigation={ | ||
<DrawerNavigation | ||
title={t('browserView.settings.heading')} | ||
onCloseIconClick={!popupView ? onClose : undefined} | ||
onArrowIconClick={popupView ? onClose : undefined} | ||
/> | ||
} | ||
popupView={popupView} | ||
> | ||
<div className={popupView ? styles.popupContainer : undefined}> | ||
{popupView && <Text className={styles.drawerDescription}>{'This is the logging level for the extension'}</Text>} | ||
<div className={styles.radios}> | ||
<Radio.Group | ||
className={styles.radioGroup} | ||
onChange={handleLoggingChange} | ||
value={currentLogLevel} | ||
data-testid="logging-radio-group" | ||
> | ||
{logLevels.map((level) => ( | ||
<a className={styles.radio} key={level}> | ||
<Radio | ||
value={level} | ||
className={styles.radioLabel} | ||
data-testid={`logging-${level.toLowerCase()}-radio-button`} | ||
> | ||
<span>{capitalize(level)}</span> | ||
</Radio> | ||
</a> | ||
))} | ||
</Radio.Group> | ||
</div> | ||
</div> | ||
</Drawer> | ||
); | ||
}; |
Oops, something went wrong.