태그 보관물: log-files

log-files

열려 있고 항상 기록중인 파일 회전 로그 파일은 몇 주 안에

로깅 정보를 지속적으로 로그 파일에 쓰는 리눅스 응용 프로그램이 있습니다. /var/log/application.log. 응용 프로그램이 파일을 자동으로 회전시키지 않기 때문에이 로그 파일은 몇 주 안에 기가 바이트 크기에 도달 할 수 있으므로이 파일을 올바르게 회전 할 수 있기를 원합니다

내 주요 관심사는 응용 프로그램에서 항상 열린 파일을 회전하려면 아마도 다음을 수행해야한다는 것입니다.

  1. 파일을 회전 된 형태로 이동 /var/log/application.log -> /var/log/application.log.2013-01-28

  2. 빈을 만듭니다 /var/log/application.log. Obs : 이 시점에서 신청 절차는 여전히/var/log/application.log.2013-01-28

  3. 응용 프로그램 프로세스의 파일 디스크립터를 다시 가리 키도록 변경하십시오. /var/log/application.log

내가 맞습니까? 그렇다면 어떻게해야합니까? (주로 파일 디스크립터 부분 변경)

내가 아닌 경우 올바른 방법은 무엇이며 어떻게해야합니까?



답변

logrotate사용할 설정 작성copytruncate

copytruncate
    Truncate the original log file in place after creating a copy, instead of moving the
    old log file and optionally creating a new one. It can be used when some program
    cannot be told to close its logfile and thus might continue writing (appending) to
    the previous log file forever. Note that there is a very small time slice between
    copying the file and truncating it, so some logging data might be lost. When this
    option is used, the create option will have no effect, as the old log file stays
    in place.


답변

이러한 응용 프로그램의 대부분은와 같은 신호에 응답하며 신호 SIGHUP를 받으면 로그 파일을 닫았다가 다시 엽니 다. 전송할 올바른 신호에 대해서는 응용 프로그램 설명서를 확인하십시오.


답변