スキップしてメイン コンテンツに移動

投稿

2月, 2012の投稿を表示しています

【PHP】CodeIgniterのログをクラス名やメソッド名や行番号とかも表示してみる

環境 CodeIgniter:Version 2.1.0 前置き 表題にCodeIgniterと書きましたが、概念的にはこのフレームワークだからという話ではないです。 前回 の続きと言うことで。 デフォルトでログは以下のように吐かれます。 DEBUG - 2012-02-18 23:30:43 --> Controller Class Initialized INFO - 2012-02-18 23:30:43 --> start INFO - 2012-02-18 23:30:43 --> valid id:hogehoge INFO - 2012-02-18 23:30:43 --> end まあ、ざっくりこのログが何を表しているかというと、 土曜の夜だというのにデバッグしてる MVCモデルのControllerの部分に要求がきて、その中のメソッドを開始し、idの値判定して結果をログへ出力。正常にメソッドを抜けてendといった感じを表しています。 自分で作り込んでいれば、上記では割愛した前後のログでおよその見当は付くでしょうが、ぱっと見どこの処理かわからないですね。 これにクラス名やメソッド名、行番号が表示されていれば、前後を確認しなくとも1発でどこの処理か判断する事ができるのではないでしょうか。 クラス名やメソッド名、行番号などの情報を取得する方法 PHPには便利な関数があるようで、 ・PHP: debug_backtrace - Manual http://www.php.net/manual/ja/function.debug-backtrace.php この関数を叩けば、呼び出し元のクラス名やら行番号が参照できます。という事で、 前回 社畜仕様に カスタマイズしたファイルに埋め込めばOK。はい解決!と行きたいところですが、少し挙動を見てみましょう。 debug_backtrace関数の戻り値を表示させるには、 var_dump(debug_backtrace()); という記述をしてやります。これを前回で言うところのMY_Log.phpのwrite_logメソッド内に記述し、 呼び出し元となる、テスト用のControllerを作成してやります。 <?php if ( ! defined(

【PHP】CodeIgniterのログ出力をサイズ単位にカスタマイズ

環境 CodeIgniter:Version 2.1.0 前置き CodeIgniterは「application\config\config.php」の /* |-------------------------------------------------------------------------- | Error Logging Threshold |-------------------------------------------------------------------------- | | If you have enabled error logging, you can set an error threshold to | determine what gets logged. Threshold options are: | You can enable error logging by setting a threshold over zero. The | threshold determines what gets logged. Threshold options are: | | 0 = Disables logging, Error logging TURNED OFF | 1 = Error Messages (including PHP errors) | 2 = Debug Messages | 3 = Informational Messages | 4 = All Messages | | For a live site you'll usually only enable Errors (1) to be logged otherwise | your log files will fill up very fast. | */ $config['log_threshold'] = 3; log_thresholdの値を3(または4)とかにして log_message('debug', "hello CodeIgniter"); のように書けば「application/logs」ディレクトリへログが出力されますが、ファイル名が

[JavaScript]プロトタイプ定義したメソッド内でsetTimeoutを使って自身を呼び 出す方法

コメント欄で思いがけず見つけたので、メモ。 prototype定義したメソッド内でsetTimeoutで自身を呼び出す方法 ・JavaScript’s setTimeout and how to use it with your methods » Klevo blog http://klevo.sk/javascript/javascripts-settimeout-and-how-to-use-it-with-your-methods/ If you are using the prototype javascript, you can take advantage of its general purpose early-binding function, bind (see http://alternateidea.com/blog/articles/2007/7/18/javascript-scope-and-binding) . The solution using prototype’s bind function is: setTimeout(this.methodToCall.bind(this), time); 上記赤文字の通りに使えば良いのですが、メソッド自身を繰り返し呼んでブラウザに時計のように表示するサンプルを以下に。 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>BrowserTimer</title> <meta name="author&q