You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4php-user@logging.apache.org by fabien JOBIN <fa...@altair-multimedia.com> on 2006/10/30 18:08:09 UTC

Logging to one file per user

Hi,

For a website I need to have a log file per user.

I first looking into NDC by this make only one file with some informations (I test with session id).

After I've try to create a file logger and change the name but that doesn't work. here's the code :
----------8<-----------
$oUserLogger 	= LoggerManager::getLogger('userLog');
$oAppender 	= $oUserLogger->getAppender( 'userFile' );
$sLogFile  	= sprintf('system/logs/users/%s.log',session_id() );
$oAppender->setFile($sLogFile);

----------8<-----------

So anybody has an idea to make a log file per user ?

Example :
The user bob login and I want him to have the log file logs/users/bob.log
The user dave login and I want him to have the log file logs/users/dave.log

Of course I don't want to create in the config files each log entry but I want to create them 
dynamiquely (I have hundreds of users).


Hope you can help me.

Best regards,
Fabien

-- 
ALTAIR Multimédia
RN 147 - Les Petites Buffeteries
49124 Saint Barthélemy d'Anjou
Tél : 02.41.36.86.10
Fax : 02.41.36.86.11
http://www.altair-multimedia.com

Re: Logging to one file per user

Posted by "Marco V." <ma...@apache.org>.
> Hi,
> 
> For a website I need to have a log file per user.
> 
> I first looking into NDC by this make only one file with some informations (I test with session id).
> 
> After I've try to create a file logger and change the name but that doesn't work. here's the code :
> ----------8<-----------
> $oUserLogger = LoggerManager::getLogger('userLog');
> $oAppender = $oUserLogger->getAppender( 'userFile' );
> $sLogFile  = sprintf('system/logs/users/%s.log',session_id() );
> $oAppender->setFile($sLogFile);
> 
> ----------8<-----------
> 
> So anybody has an idea to make a log file per user ?

Try to change your code like this (use & to reference objects in PHP4; with php5 you can omit them):

$oUserLogger =& LoggerManager::getLogger('userLog');
$oAppender =& $oUserLogger->getAppender( 'userFile' );
$oAppender->close();
$sLogFile  = sprintf('system/logs/users/%s.log',session_id() );
$oAppender->setFile($sLogFile);
$oAppender->activateOptions();

the close() method closes the file opened by logger configurator; then activateOptions() open the file $sLogFile.

Regards,
-Marco