Last active
December 15, 2015 14:39
Revisions
-
isdyy revised this gist
Mar 30, 2013 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ ## Logging Flow 忘れてしまいがち - http://docs.python.org/2/howto/logging.html#logging-flow @@ -17,12 +16,14 @@ - 予め Adapterでラップした特定の logger インスタンスの使用を義務付けられる範囲で - もしくは logging.setLoggerClass でLogger じたいを独自のものに置き換えることもできる - python2 で 3系の logging.setLogRecordFactory() 相当のことをするには Logger を継承して makeRecord() を override するしかないか ## ローカルファイルへの出力でローテーションに対応するには - 出力先ファイルパスは一定で、logrotate でローテーションするケース - logging.handlers.WatchedFileHandler というのがあるのでこれを使う - 引数は FileHandler と同じ - logging じたいにも日時やサイズに応じてローテーションさせるハンドラが用意されてはいる (RotatingFileHandler) ## GAE/Python のログ - google.appengine.api.app_logging.AppLogsHandler というのがセットされてる - デプロイ環境だと google3.apphosting.api.app_logging.AppLogsHandler となっている -
isdyy created this gist
Mar 30, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ ## Logging Flow 忘れてしまいがち - http://docs.python.org/2/howto/logging.html#logging-flow - http://docs.python.org/3/howto/logging.html#logging-flow - python2, 3 でフローは同じ - 3 だと logging.setLogRecordFactory() で LogRecord の生成もフックできるようになってる ## Adding contextual information - http://docs.python.org/2/howto/logging-cookbook.html#adding-contextual-information-to-your-logging-output - http://docs.python.org/3/howto/logging-cookbook.html#adding-contextual-information-to-your-logging-output - webアプリケーションのログにリクエストユーザーの情報を含める等 - LoggerAdapter を使って logger をラップする方法(>= 2.6) と、Filter を作って Logger または Handler に仕掛けておく方法がある - Filter を使うと、既存のアプリケーションコードに一切変更をせず、また新たなコーディング上のルール等も作らずに、ログに情報を付加できる - Filter のサブクラスを作って、サイトグローバルな logging設定や WSGIミドルウェアを通じて設定する - Adapter は特定モジュール/パッケージ内で固有の処理をするときには良さげな感じ - 予め Adapterでラップした特定の logger インスタンスの使用を義務付けられる範囲で - もしくは logging.setLoggerClass でLogger じたいを独自のものに置き換えることもできる - python2 で 3系の logging.setLogRecordFactory() 相当のことをするには Logger を継承して makeRecord() を override するしかないか ## ローカルファイルへの出力でローテーションに対応するには - 出力先ファイルパスは一定で、logrotate でローテーションするケース - logging.handlers.WatchedFileHandler というのがあるのでこれを使う - 引数は FileHandler と同じ - logging じたいにも日時やサイズに応じてローテーションさせるハンドラが用意されてはいる (RotatingFileHandler) ## GAE/Python のログ - google.appengine.api.app_logging.AppLogsHandler というのがセットされてる - デプロイ環境だと google3.apphosting.api.app_logging.AppLogsHandler となっている - 1メッセージあたり 8192 bytes で truncate される - emit先は GAE のログストレージ