----- Original Message -----
From: "Lst Recv" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Thursday, June 23, 2005 12:15 AM
Subject: Logging the user's IP with log4php
>Is there anyway to have it include the user's IP address,
>PHPSESSIONID, URL, and filename/linenumber? These things are very
>useful - more than a PID etc in PHP.
You can use the method LoggerLoggingEvent::getMDC() (see LoggerMDC class for
details).
If you use the LoggerPatternLayout a conversion character %X{clientNumber} is
what you need.
With %X{server.REMOTE_ADDR} you get the client IP address.
Put any key/value pair using the static method LoggerMDC::put(key, value) and
get the value via %X{key}.
Example:
----
LoggerMDC::put('sessionid', session_id());
....
in log4php.xml
...
<appender name="default" class="LoggerAppenderEcho">
<layout class="LoggerPatternLayout">
<param name="conversionPattern" value="%-5p [%t] [%X{sessionid}]:
%m in %F line %L%n" />
</layout>
</appender>
....
For filename/linenumber:
with LoggerPatternLayout use the %F, %L conversion chars and with
LoggerLayoutHtml, LoggerXmlLayout set the "locationInfo" property
"true". (with locationInfo enabled every log event calls a debug backtrace...
(see LoggerLoggingEvent::getLocationInformation()).
-Marco