Simple Logging in PHP (File based & one-liner)シンプルなログ出力はPHP (ファイルベース& 1つ-ライナー)
Often we (php developers) need to log certain messages in order to debug our script.しばしば私たち( PHPの開発者が)必要であれば、特定のメッセージをログに記録するためのスクリプトをデバッグする。 Here I will describe the default syslog method and a much simpler (and better) way to log your messages quickly and painlessly.ここで私は、デフォルトのsyslogの方法を説明すると、よりシンプルな(そしてより良い)の方法をログに記録してメッセージをすばやく手軽にします。
PHP manual suggests usingを使用してPHPマニュアルを示唆 syslog syslogに for logging.ログを記録します。
Problems with 問題が発生 syslog syslogに
The problem with syslog is that its implementation is system dependent. syslogに問題があるのは、その実装はシステム依存です。 For example openlog() is not supported on windows.例えば、 openlog ( )ではないのWindowsでサポートされています。
The location of the logged data is system dependent, which you may not have access to (if you are on a shared web hosting environment) or know about.場所はログに記録するデータはシステムに依存、これにアクセスすることはできません(場合にはウェブホスティング環境で使用する共有) 、または知っている。
The procedure is more cumbersome than you may like to undertake for simple quick and dirty log messages.この手順は、他の煩雑なことがありますように着手をより迅速かつ簡単な汚いログメッセージを表示します。
Using syslog を使用してのsyslog
Here is a sample code using syslog:次に示すのは、サンプルコードを使用してのsyslog :
< ?php <ですか? PHPの
define_syslog_variables(); するdefine_syslog_variables ( ) ;
// open syslog, include the process ID and also send / / syslogに開いて、送信するには、プロセスID 、また
// the log to standard error, and use a user defined / /ログを標準エラー出力、およびユーザ定義を使用する
// logging mechanism / /ログ機構
openlog(”myScriptLog”, LOG_PID | LOG_PERROR, LOG_LOCAL0); openlog ( " myscriptlog " 、 log_pid | log_perror 、 log_local0 ) ;
// some code / /いくつかのコード
if (authorized_client()) {もし( authorized_client ( ) ) (
// do something / /何か
} else { )他(
// unauthorized client! / /許可されていないクライアントから!
// log the attempt / /ログの試み
$access = date(”Y/m/d H:i:s”); $アクセス=日付( " y /月/ d h :私:秒" ) ;
syslog(LOG_WARNING, “Unauthorized client: $access $_SERVER[REMOTE_ADDR] ($_SERVER[HTTP_USER_AGENT])”);のsyslog ( log_warning 、 "許可されていないクライアント: $アクセス$ _server [のREMOTE_ADDR ] ( $ _server [ http_user_agent ])");
} )
closelog();するcloselog ( ) ;
?>ですか? >
Simpler alternative シンプルな代替
Now lets look into a quicker and simpler alternative for your simple logging needs.今すぐ見てみましょうをすばやく簡単に代替お客様のニーズにシンプルなログ出力します。
file_put_contents file_put_contents (’log_file_name’, $data, FILE_APPEND); ( ' log_file_name ' 、 $データ、 file_append ) ;
$data is the data you want logged. $データはログに記録されたデータを選択します。 You can also pass in an array.パスの配列をすることもできます。 This creates a file in the directory the script is invoked from and appends your log messages.このファイルを、ディレクトリを作成するスクリプトが呼び出されるからと付加してログメッセージを表示します。
Filed under提出されて Headline Newsニュースの見出し , 、 How Toどのように , 、 PHP PHPの , 、 Tech Note技術のノート , 、 Webウェブ , 、 Web Services Webサービス , 、 Windows Windowsの | |
| |
RSS 2.0 RSS 2.0を | |
Trackbackトラックバック this Article |この記事|
Email this Article電子メールこの記事
You may also like to readを読むようにすることも可能 |





August 23rd, 2006 at 1:24 pm 2006年8月23日は1:24 pmの
[...] articles on Open Source Software, PHP, Web, WebLog, How To, Headline News, Tech Note | | RSS 2.0 | Trackback this Article | Email thisArticle [...] [...]の記事を、オープンソースソフトウェア、 PHP 、網、ウェブログ、どのように、ニュースの見出し、技術の注意なさい| | RSS 2.0 |トラックバックこの記事|電子メールのthisArticle [...]
September 11th, 2007 at 11:44 pm 2007年9月11日11:44 pmの
Thanks a zillion for this hint!このヒントを無数に感謝する!
It\’s EXACTLY what I needed.それ\ '秒丁度私必要です。 I hope there isn\’t some kind of exploit as it almost seems too good to be true.あるといいisn \ 'トンいくつかの種類として悪用されることのほとんどはあまりにも良いtrueです。
[it also makes for a nice alternative to logging services that add cookies and such. [こともログでは、ニースの代わりにクッキーなどのサービスを追加します。 I mean, I use \'em - I like to know what keywords are used, how many pages, entry and exit pages and all of that --- but sometimes...つまり、僕の使用\ '日-私を知ってどのようなキーワードが使われるように、どのよう多くのページ、出口ページとのすべてのエントリとは- --しかし、時には. .. sometimes you just want a stinkin\' IP address!!あるとき、あなただけを望むstinkin \ ' IPアドレス! !
I\’ma microsoft excel NUT, so I like to be able to have massive amounts of data to sort through and make my own graphs, charts, filters, ideas, implementations.私\ 'マサチューセッツMicrosoft Excelのナット、だからできるようにするには膨大な量のデータを並べ替えて、自分自身のグラフに、グラフ、フィルタ、アイデア、実装します。
Your one little line of code is just what the doctor ordered.あなたのコードの行を1つのほとんどはおあつらえ向きのものです。
Ken of Naples FL USA - grateful.ケンのナポリフロリダアメリカ合衆国-感謝します。
September 12th, 2007 at 8:41 pm 2007年9月12日は午後8時41分
This isn’t an exploitこの問題ではない