From 685cf7834d6b8670148314168c3e272157edbca4 Mon Sep 17 00:00:00 2001 From: JungminLee <85864699+JjungminLee@users.noreply.github.com> Date: Wed, 14 Feb 2024 20:36:11 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=9C=A0=EC=A0=80=20=EC=9D=B4=ED=83=88?= =?UTF-8?q?=EC=8B=9C=20=EB=B0=B1=EC=97=94=EB=93=9C=EC=97=90=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=20=EC=A0=84=EB=8B=AC=20(#27)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Logger.ts | 11 ++++++++++- src/SetLocalStorage.ts | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) 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)); };