LoginSignup
4
3

More than 5 years have passed since last update.

luigiのコンソールログのログレベルを設定する

Last updated at Posted at 2017-04-13

ようやく方法が分かったのでメモ。

デフォルトの出力

コマンドラインから起動した場合、こんな感じのコンソールログが出力される。

$ PYTHONPATH=examples bin/luigi --module foo examples.Foo --local-scheduler
DEBUG: Checking if examples.Foo() is complete
DEBUG: Checking if examples.Bar(num=0) is complete
DEBUG: Checking if examples.Bar(num=1) is complete
DEBUG: Checking if examples.Bar(num=2) is complete
DEBUG: Checking if examples.Bar(num=3) is complete
DEBUG: Checking if examples.Bar(num=4) is complete
DEBUG: Checking if examples.Bar(num=5) is complete
DEBUG: Checking if examples.Bar(num=6) is complete
DEBUG: Checking if examples.Bar(num=7) is complete
DEBUG: Checking if examples.Bar(num=8) is complete
DEBUG: Checking if examples.Bar(num=9) is complete
INFO: Informed scheduler that task   examples.Foo__99914b932b   has status   PENDING
INFO: Informed scheduler that task   examples.Bar_9_afea9c1ed4   has status   DONE
INFO: Informed scheduler that task   examples.Bar_8_446a6fadda   has status   PENDING
INFO: Informed scheduler that task   examples.Bar_7_7a5655a70d   has status   DONE
INFO: Informed scheduler that task   examples.Bar_6_d94e6707b0   has status   DONE
INFO: Informed scheduler that task   examples.Bar_5_381f71ed51   has status   DONE
INFO: Informed scheduler that task   examples.Bar_4_3798ec54a0   has status   DONE
INFO: Informed scheduler that task   examples.Bar_3_40c49393a7   has status   DONE
INFO: Informed scheduler that task   examples.Bar_2_51dd7c7388   has status   DONE
INFO: Informed scheduler that task   examples.Bar_1_aebd9cb151   has status   DONE
INFO: Informed scheduler that task   examples.Bar_0_e0cbafafd8   has status   DONE
INFO: Done scheduling tasks
INFO: Running Worker with 1 processes
DEBUG: Asking scheduler for work...
DEBUG: Pending tasks: 2
INFO: [pid 2571] Worker Worker(salt=398089765, workers=1, host=oonishitk-MBP.local, username=bwtakacy, pid=2571) running   examples.Bar(num=8)
<<以下略>>

DEBUGレベルまで出てしまうため非常に量が多い。

ログレベルを設定する

バージョン2.6.0以前

luigiはログ出力にpythonのloggingモジュールを使っている。
なので、loggingモジュール向けの設定ファイルを作って読み込ませればよい。

  1. loggingモジュール向け設定ファイルを作成する
[loggers]
keys=root

[handlers]
keys=consoleHandler

[formatters]
keys=simpleFormatter

[logger_root]
level=INFO
handlers=consoleHandler

[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=simpleFormatter
args=(sys.stdout,)

[formatter_simpleFormatter]
format=%(levelname)s: %(message)s

これはluigiのテスト用に用意されているtest/testconfig/logging.confにて
ルートロガーのログレベルをINFOにしただけ。

  1. luigiの設定ファイルluigi.cfgにてlogging_conf_fileを設定する。
[core]
logging_conf_file=/Users/bwtakacy/Develop/luigi/test/testconfig/logging.cfg

あとはluigi.cfgを

  • /etc/luigi/client.cfg
  • カレントディレクトリ
  • LUIGI_CONFIG_PATH 環境変数で定義したPATH

のいずれかに置いてluigiを起動すればOK。

$ PYTHONPATH=examples bin/luigi --module foo examples.Foo --local-scheduler
INFO: Informed scheduler that task   examples.Foo__99914b932b   has status   PENDING
INFO: Informed scheduler that task   examples.Bar_9_afea9c1ed4   has status   PENDING
INFO: Informed scheduler that task   examples.Bar_8_446a6fadda   has status   PENDING
INFO: Informed scheduler that task   examples.Bar_7_7a5655a70d   has status   PENDING
INFO: Informed scheduler that task   examples.Bar_6_d94e6707b0   has status   PENDING
INFO: Informed scheduler that task   examples.Bar_5_381f71ed51   has status   PENDING
INFO: Informed scheduler that task   examples.Bar_4_3798ec54a0   has status   PENDING
INFO: Informed scheduler that task   examples.Bar_3_40c49393a7   has status   PENDING
INFO: Informed scheduler that task   examples.Bar_2_51dd7c7388   has status   PENDING
INFO: Informed scheduler that task   examples.Bar_1_aebd9cb151   has status   PENDING
INFO: Informed scheduler that task   examples.Bar_0_e0cbafafd8   has status   PENDING
INFO: Done scheduling tasks
INFO: Running Worker with 1 processes
INFO: Starting pruning of task graph
INFO: Done pruning task graph
INFO: [pid 3664] Worker Worker(salt=529277451, workers=1, host=oonishitk-MBP.local, username=bwtakacy, pid=3664) running   examples.Bar(num=8)
<<以下略>>

すっきりsilent ♪

luigi.cfgを使わなくても、luigiのコマンドラインオプション`--logging-conf-fileを使って直接logging設定ファイルを与えてもいける。

$ PYTHONPATH=examples luigi --module foo examples.Foo --local-scheduler --logging-conf-file /Users/bwtakacy/Develop/luigi/test/testconfig/logging.cfg 

バージョン2.6.0以降

luigi.cfgにてlog_levelというパラメータが用意されたので、もっと手軽になった。 

ref: https://github.com/spotify/luigi/commit/e7ad1998c4dc90cfff053d26e06c6586ab85c332

[core]
log_level=INFO

これだけでOK。

素晴らしい!

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3