
이번 글을 통해 배워갈 내용
- nodejs 로깅에 시간추가하는 방법을 배우겠습니다
프로젝트에 npm 혹은 yarn으로 console-stamp를 추가합니다
yarn add console-stamp
프로젝트에 시작지점 index.js 혹은 app.js 파일에
consoleStamp를 추가해 줍니다
import consoleStamp from 'console-stamp';
consoleStamp(console, { format: ':date(yyyy/mm/dd HH:MM:ss.l) :label' });
프로젝트 시작 시 아래와 같이 로깅이 잘되는 것을 확인할 수 있습니다
[2023/03/07 06:16:13.156] [LOG] listening on port 3000
읽어주셔서 감사합니다 좋은 하루 보내세요~
필요시 pm2를 활용해서 nodejs 서버를 실행하고 로그를 확인
pm2 logs
vi ~/.pm2/logs/index-error.log
필요시 Ubuntu OS라면 resync를 활용해서 로그 파일 백업
필요시 scheduled job을 통해 디비에 로그를 남기는 것도 좋은 방법
출처 및 인용
https://www.npmjs.com/package/console-stamp
console-stamp
Patch NodeJS console methods in order to add timestamp information by pattern. Latest version: 3.1.1, last published: 23 days ago. Start using console-stamp in your project by running `npm i console-stamp`. There are 163 other projects in the npm registry
www.npmjs.com
728x90
'Javascript > 웹 기타' 카테고리의 다른 글
| 배포환경 Netlify에서 500 에러 날때 혹은 404 날때 해결한 한가지 방법 (0) | 2023.05.31 |
|---|---|
| VS Code 에서 Prettier 전역으로 적용하는 명령어 (1) | 2023.05.30 |
| CSS 기본 스타일 무시하는 한가지 방법 (0) | 2022.07.21 |
| json-server Invoke-WebRequest문제를 해결하는 한가지 방법 (0) | 2022.07.12 |
| html css로 카드 뒤집기 구현해보는 한가지 방법 (0) | 2022.06.18 |