diff --git a/src/Logger.ts b/src/Logger.ts index 07a1bd3..c09c27f 100644 --- a/src/Logger.ts +++ b/src/Logger.ts @@ -1,4 +1,4 @@ -import { SetLocalStorage } from './SetLocalStorage'; +import { SetLocalStorage, SetLocalStorageClear } from './SetLocalStorage'; import { LogPayloadParams, ServiceNameType } from './types/LogType'; import CryptoJS from 'crypto-js'; @@ -89,3 +89,12 @@ export const Logger = ({ userId, serviceName, name, message, path, tags }: LogPa }, }; }; + +window.addEventListener('unload', async (event) => { + event.preventDefault(); + + const logList: any[] = JSON.parse(localStorage.getItem('yls-web') as string) || []; + + // const res = await postLog(logList); + SetLocalStorageClear(); +}); diff --git a/src/SetLocalStorage.ts b/src/SetLocalStorage.ts index a96331d..c020071 100644 --- a/src/SetLocalStorage.ts +++ b/src/SetLocalStorage.ts @@ -1,7 +1,7 @@ import { postLog } from './apis/postLog'; import { LogType } from './types/LogType'; -const SetLocalStorageClear = () => { +export const SetLocalStorageClear = () => { const list: any[] = []; localStorage.setItem('yls-web', JSON.stringify(list)); };