TIL
express) morgan 으로 로그 관리하기
기주그지마
2024. 1. 10. 21:38
morgan : request, response 로깅 미들웨어
morgan미들웨어만들기)
morgan(format, options)
첫번째인자 format : Log를 어떻게 생성하여 출력할 것인지 설정
ㄴ'dev', 'combined'와 같은 방식으로 미리 정해진 형식으로 Log를 생성할 수 있다
ㄴ그외에도 'common', 'short', 'tiny'등의 형식이있음
ㄴ사용자 지정형식: 사용자가 원하는 대로 custom하여 Log를 생성할 수도 있다
ㄴㄴ'dev' : 나의 개발환경에서 사용, 간단한 log
ㄴㄴ'dev' 형식)
:method :url :status :response-time ms - :res[content-length]
ㄴㄴ'combined' : 배포 환경에서 사용, 자세한 log
ㄴㄴ'combined' 형식)
:remote-addr - :remote-user [:date[clf]] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent"
두번째인자 options : 생성된 Log를 어디에, 어떻게 저장할것인지 설정 (db저장, 파일저장...)