DEV Community

voluntas
voluntas

Posted on

2 1

Erlang/OTP でのロギングについて

あんまりたいしたこと書いてないです。追記型。

lager

Riak の Basho が公開しているフレームワーク。ほぼデファクトであろう。

良く出来てる。

crash.log のローテーション時間や世代を管理したい

https://github.com/basho/lager/blob/master/src/lager.app.src

ここにデフォルトが設定してあるので、これを上書きしてあげれば良い。

%% Whether to write a crash log, and where. Undefined means no crash logger.
{crash_log, "log/crash.log"},
%% Maximum size in bytes of events in the crash log - defaults to 65536
{crash_log_msg_size, 65536},
%% Maximum size of the crash log in bytes, before its rotated, set
%% to 0 to disable rotation - default is 0
{crash_log_size, 10485760},
%% What time to rotate the crash log - default is no time
%% rotation. See the README for a description of this format.
{crash_log_date, "$D0"},
%% Number of rotated crash logs to keep, 0 means keep only the
%% current one - default is 0
{crash_log_count, 5},
Enter fullscreen mode Exit fullscreen mode
  • crash_log
    • ファイル出力先
  • crash_log_msg_size
    • crash ログは error_logger をリダイレクトに渡してるので、そのサイズ指定
  • crash_log_size
    • ログローテーションサイズ
    • 0 にすればローテーションされない
  • crash_log_date
    • ログローテの日時
    • "" にすれば時間していはなくなる
  • crash_log_count
    • 世代、デフォルトは 5 まで、 0 にすれば世代管理されない

erlang.log

勝手に出来るけど、こいつ何者だ感があるやつ

デフォルトだと 100キロバイト単位で 5 世代でログローテーションしていく

だが、環境変数で設定は変更可能だったりする。

http://www.erlang.org/doc/man/run_erl.html

RUN_ERL_LOG_GENERATIONS
Controls the number of log files written before older files are being reused. Default is 5, minimum is 2, maximum is 1000.
RUN_ERL_LOG_MAXSIZE
The size (in bytes) of a log file before switching to a new log file. Default is 100000, minimum is 1000 and maximum is approximately 2^30.
Enter fullscreen mode Exit fullscreen mode
  • RUN_ERL_LOG_GENERATIONS
    • 世代管理、デフォルトは 5
    • 最小は 2 で、最大は 1000
  • RUN_ERL_LOG_MAXSIZE
    • ログローテーションのサイズですデフォルトは 100キロバイト
    • 最小 1000 バイト

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay