pm2 로그 기록 과 로그 분할
소개
pm2 는 nodejs 프로 세 스 관리 도구 입 니 다. 현 재 는 기본적으로 node 생산 서버 의 표준 선택 입 니 다. node 다 중 프로 세 스 서 비 스 를 실현 하고 여러 개의 인 스 턴 스 를 열 면 부하 균형 을 자동 으로 실현 할 수 있 습 니 다.가장 중요 한 것 은 node 단일 프로 세 스 가 오류 로 인해 종료 되 지 않도록 하 는 것 입 니 다. 데 몬 으로서 nodejs 서비스 가 지연 되 지 않도록 하 는 것 입 니 다.전체적으로 성능 모니터링, 자동 재 부팅, 부하 균형 작용 이 있다.
pm2 - logrotate 소개
pm2 자체 가 로그 파일 을 출력 할 수 있 습 니 다. 기본 파일 경로:
error log path │ /home/username/.pm2/logs/app-error-0.log
out log path │ /home/username/.pm2/logs/app-out-0.log
그러나 pm2 의 로그 파일 은 자동 으로 분할 되 지 않 아 파일 이 계속 커지 고 성능 에 영향 을 줄 뿐만 아니 라 이 로 그 를 보 는 것 도 번 거 로 울 수 있 습 니 다.그래서 자동 분할 로 그 를 실현 하기 위해 서 는
pm2-logrotate
가 필요 하 다.pm2 - logrotate 설치
pm2 install pm2-logrotate
, pm2 명령 으로 npm 명령 이 아 닙 니 다.pm2 - logrotate 설정
compress
(기본 false): 로 그 를 압축 할 지 여부 dateFormat
(기본 YYYY - MM - DD HH - mm - ss): 로그 형식 rotateModule
(Defaults to true) : Rotate the log of pm2's module like other apps workerInterval
(Defaults to 30 in secs) : You can control at which interval the worker is checking the log's size (minimum is 1) rotateInterval
(Defaults to 0 0 * * * everyday at midnight): This cron is used to a force rotate when executed. We are using node-schedule to schedule cron, so all valid cron for node-schedule is valid cron for this option. Cron style : TZ
(Defaults to system time): This is the standard tz database timezone used to offset the log file saved. For instance, a value of Etc/GMT-1, with an hourly log, will save a file at hour 14 GMT with hour 13 GMT-1 in the log name. * * * * * * ┬ ┬ ┬ ┬ ┬ ┬ │ │ │ │ │ | │ │ │ │ │ └ day of week (0 - 7) (0 or 7 is Sun) │ │ │ │ └───── month (1 - 12) │ │ │ └────────── day of month (1 - 31) │ │ └─────────────── hour (0 - 23) │ └──────────────────── minute (0 - 59) └───────────────────────── second (0 - 59, OPTIONAL)
로그 파일 의 최대 1KB 코드
pm2 set pm2-logrotate:max_size 1K (1KB)
를 사용 해 볼 수 있 습 니 다. console.log
, 크기 가 1KB 에 도달 하면 자동 으로 생 성 /home/username/.pm2/logs/app-out-0.log
이 형식의 로그 파일 입 니 다.app-out-0__2018-01-25_16-58-16.log
(기본 경로, 설정 가능) 경로 아래 에 또 있 습 니 다./home/username/.pm2/logs/
app-error-0.log
pm2-logrotate-out-1.log
몇 개의 파일, pm2-logrotate-error-1.log
파일 이 기록 한 것 은 app-out-0.log
출력 입 니 다. console.log
기록 한 것 은 오류 출력 입 니 다. app-error-0.log
과 pm2-logrotate-out-1.log
각각 분 단 된 로그 파일 을 기록 한 것 은 이러한 내용 입 니 다. "/home/username/.pm2/pm2__2018-01-25_16-57-16.log" has been created
"/home/username/.pm2/logs/app-out-0__2018-01-25_16-58-16.log" has been created
"/home/username/.pm2/logs/app-out-0__2018-01-25_16-58-46.log" has been created
다음으로 전송:https://www.cnblogs.com/czq-0214/p/8494602.html
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.