marionweb.com에서 퍼옴
Intentionally throw PHP errors | ![]() |
![]() |
![]() |
Written by Marion Consulting | |
Error messages are not something that most developers enjoy seeing, but they can be very useful especially when debugging or testing an applications code. Sometimes we would like throw an error to see how the application behaves and below is an example of how to do just this. trigger_error Generates a user-level error/warning/notice message (PHP 4 >= 4.0.1, PHP 5) bool trigger_error ( string error_msg [, int error_type] )
error_msg The designated error message for this error. It's limited to 1024 characters in length. Any additional characters beyond 1024 will be truncated. error_typeThe designated error type for this error. It only works with the E_USER family of constants, and will default to E_USER_NOTICE. Example usage: trigger_error ('I just threw an error", E_USER_ERROR); |
How to use log4php | ![]() |
![]() |
![]() |
Written by Marion Consulting | |
This is a very basic tutorial on how to implement log4php into your php projects. Log4php is a port of log4j, which is a very popular logging utility in java. It works very nice in PHP and makes it very simple to log information in many different formats. The following should allow you to begin using this new functionality in your applications. Download the example code at a zip file that is provided in plain text below Get log4php source from http://www.vxr.it/log4php/download.html Untar/zip the files into a directory on your webserver machine. There are many directories inside the archive that you do not need unless you want to look over the examples. //define the following in your application define('LOG4PHP_DIR', 'log4php-0.9'); // the name of the log4php directory define('LOG4PHP_CONFIGURATION','log_configuration.xml'); |
Explanation and Examples of log_configuration.xml
The xml file can be named whatever you wish, you just need to reference the appropriate name in the definition of LOG4PHP_CONFIGURATION above. The xml below writes a log file to the filesystem for all logged messages (debug to fatal), and it sends an email to the specified email address on any fatal logged error. The xml can be configured for a number of different formats, but the log file and email are my preferred logging methods.
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
/**
* Script: log_configuration.xml
* Author: Author <tony [at] marionweb [dot] com>
*
* Purpose: Setup logging configuration
* Creation Date: 1/29/2006
* Details: Currently setup to write to log file for all messages debug -> fatal. All fatal messages are emailed to site admin.
*/
-->
<log4php:configuration xmlns:log4php="http://www.vxr.it/log4php/" threshold="all" debug="false">
<appender name="write_to_log" class="LoggerAppenderDailyFile">
<param name="datePattern" value="Ymd" />
<param name="file" value="/path_to_logfile/logs/web_application_%s.log" />
<layout class="LoggerLayoutTTCC">
<param name="threadPrinting" value="true" />
<param name="categoryPrefixing" value="true" />
<param name="contextPrinting" value="true" />
<param name="microSecondsPrinting" value="true" />
</layout>
</appender>
<appender name="email_log" class="LoggerAppenderMailEvent">
<param name="from" value="
admin@email.com" />
<param name="to" value="
admin@email.com" />
<param name="subject" value="Log4php test" />
<layout class="LoggerLayoutTTCC" />
</appender>
<root>
<level value="debug" />
<appender_ref ref="write_to_log" />
</root>
<root>
<level value="fatal" />
<appender_ref ref="email_log" />
</root>
</log4php:configuration>
'svn' 카테고리의 다른 글
PC에 svn 서버 설치 도움되는 Site (0) | 2010.09.06 |
---|---|
Setting property in svn repository (0) | 2009.04.17 |
cvs에서 cvs checkout: failed to create lock directory 에러 문제 (0) | 2007.12.06 |
[펌] svn 사용법 (0) | 2006.01.17 |
svn 명령시 깨지는 글자나 나타날 때. (0) | 2005.11.01 |