Skip to content

Commit

Permalink
feat: modify Logger.ts type & naming
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanna922 committed Feb 5, 2024
1 parent 4c1d1d1 commit 49157f1
Showing 1 changed file with 15 additions and 32 deletions.
47 changes: 15 additions & 32 deletions src/Logger.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { LogPayloadParams, LogType, LoggerType } from './types/LogType';
import { LogPayloadParams } from './types/LogType';

const createUserId = () => {
// Todo: create random id
return 123;
const createHashedId = (userId: string) => {
// Todo: create hashedId
return '';
};

const createTimestamp = () => {
Expand All @@ -11,60 +11,43 @@ const createTimestamp = () => {
return now.toISOString();
};

const setLocalStorage = (logger: LogType) => {
if (window.localStorage.getItem('yls-web') == undefined) {
const list: any[] = [];
list.push(logger);
localStorage.setItem('yls-web', JSON.stringify(list));
} else {
const remainList: any[] = JSON.parse(localStorage.getItem('yls-web') as string) || [];
const updateList = [...remainList, logger];
localStorage.setItem('yls-web', JSON.stringify(updateList));
}
};

export const useYLSLogger = () => {
const screen = ({ serviceName, name }: LogPayloadParams) => {
//사용자에서 path,name,message를 넣어줌
const loggerType: LoggerType = {
const screen = ({ userId, name }: LogPayloadParams) => {
//사용자에서 userId, name, message(선택) 등을 넣어줌
const loggerType: LogPayloadParams = {
userId: userId,
path: '/',
serviceName: 'home',
name: '',
message: '/',
};
const logger = Logger(loggerType);
console.log(`Logging screen information for path: ${serviceName}`);
logger.event.name = name;

setLocalStorage(logger);
};

const click = ({ name }: LogPayloadParams) => {
console.log(`Logging click information for button: ${name}`);
//사용자에서 path,name,message를 넣어줌
const loggerType: LoggerType = {
const click = ({ userId, name }: LogPayloadParams) => {
//사용자에서 userId, name, message(선택) 등을 넣어줌
const loggerType: LogPayloadParams = {
userId: userId,
path: '/',
serviceName: 'home',
name: '',
message: '/',
};
const logger = Logger(loggerType);

console.log(`Logging click information for button: ${name}`);
logger.event.name = name;

setLocalStorage(logger);
};
// todo: 로컬스토리지 로그 개수가 10개 넘어가면 postLog.ts호출

return {
screen,
click,
};
};

export const Logger = ({ serviceName, name, message, path, tags }: LoggerType) => {
export const Logger = ({ userId, serviceName, name, message, path, tags }: LogPayloadParams) => {
return {
userId: createUserId(),
hashedId: createHashedId(userId),
timestamp: createTimestamp(),
event: {
platform: 'web',
Expand Down

0 comments on commit 49157f1

Please sign in to comment.