pm2 로그 기록 과 로그 분할

6956 단어
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 설정
  • ``max_size ` (기본 10M): 최대 얼마 일 때 분할 합 니 다. 예 를 들 어 10G, 10M, 10K
  • ``retain` (Defaults to all): This number is the number of rotated logs that are keep at any one time, it means that if you have retain = 7 you will have at most 7 rotated logs and your current one.
  • 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.logpm2-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

    좋은 웹페이지 즐겨찾기