Consul Template 로그

Consul Template 로그

Consul Template의 로깅 과정을 설명해 드릴게요. 로그 레벨 설정부터 파일 로깅까지, 운영할 때 필요한 로그 관련 기능을 하나씩 살펴보아요.

출처: 문서

본문

이 페이지는 Consul Template의 로깅 과정을 설명해요.

로그 레벨 설정

Consul Template의 로그 레벨을 설정하려면 -log-level 플래그를 사용해요:

$ consul-template -log-level info ...

로그 레벨을 설정하려면 CONSUL_TEMPLATE_LOG_LEVEL 환경 변수를 사용할 수도 있어요.

$ export CONSUL_TEMPLATE_LOG_LEVEL=info && consul-template ...

이 명령은 로그를 표준 출력(stdout)으로 출력해요.

# ...
[INFO] (cli) received redis from Watcher
[INFO] (cli) invoking Runner
# ...

디버깅할 때는 레벨을 debug로 지정할 수도 있어요:

$ consul-template -log-level debug ...

이 명령은 로그를 표준 출력으로 출력해요.

# ...
[DEBUG] (cli) creating Runner
[DEBUG] (cli) creating Consul API client
[DEBUG] (cli) creating Watcher
[DEBUG] (cli) looping for data
[DEBUG] (watcher) starting watch
[DEBUG] (watcher) all pollers have started, waiting for finish
[DEBUG] (redis) starting poll
[DEBUG] (service redis) querying Consul with &{...}
[DEBUG] (service redis) Consul returned 2 services
[DEBUG] (redis) writing data to channel
[DEBUG] (redis) starting poll
[INFO] (cli) received redis from Watcher
[INFO] (cli) invoking Runner
[DEBUG] (service redis) querying Consul with &{...}
# ...

파일로 로그 기록

Consul Template은 파일로도 로그를 기록할 수 있어요. stdout 및/또는 stderr을 캡처하기 어려운 사용 사례에서 파일 로깅이 특히 유용해요. 예를 들어 Consul Template을 장기 실행(long running) 서비스로 배포할 때는 파일 로깅을 권장해요.

다음은 관련 CLI 플래그들이에요:

  • -log-file — 모든 Consul Template 로그 메시지를 파일에 기록해요. 이 값은 로그 파일 이름의 접두사로 사용돼요. 파일 이름에는 현재 타임스탬프가 추가돼요. 값이 경로 구분자로 끝나면 값에 consul-template-이 추가돼요. 파일 이름에 확장자가 없으면 .log가 추가돼요. 예를 들어 log-file을 /var/log/로 설정하면 로그 파일 경로는 /var/log/consul-template-{timestamp}.log가 돼요. log-file은 -log-rotate-bytes 및 -log-rotate-duration과 조합하여 세밀한 로그 로테이션을 구성할 수 있어요.

  • -log-rotate-bytes — 로테이션되기 전까지 로그에 기록해야 하는 바이트 수를 지정해요. 지정하지 않으면 로그 파일에 기록할 수 있는 바이트 수에 제한이 없어요.

  • -log-rotate-duration — 로테이션되기 전까지 로그를 기록할 최대 기간을 지정해요. 30s 같은 지속 시간 값이어야 해요. 기본값은 24h예요.

  • -log-rotate-max-files — 유지할 이전 로그 파일 아카이브의 최대 개수를 지정해요. 기본값은 0(파일이 삭제되지 않음)이에요. 새 파일이 생성될 때 이전 로그 파일을 버리려면 -1로 설정해요.

더 알아보기 (Learn more)