aaaaah yes, I didn't see this. Maybe its worth thinking to autmatically activateoptions once this appender is called
Thanks for giving feedback On Thu, Apr 15, 2010 at 1:32 PM, Miquel Canes <miquel.ca...@cast-info.es> wrote: > Hi, > Finally, after using the php debuger, i found what's my problem. > > $logger = Logger::getRootLogger(); > > $appender = new LoggerAppenderFile("programmatically"); > $layout = new LoggerLayoutPattern("[%p] %t %c - %m%n"); > > $appender->setLayout($layout); > $appender->setFileName("programmatically.log"); > $appender->setAppend(true); > $appender->activateOptions(); > $logger->addAppender($appender); > > $allappenders = $logger->getAllAppenders(); > foreach ($allappenders as $nappender){ > echo $nappender->getName()."\n"; > } > > $logger->info("info text"); > > This function: $appender->activateOptions() creates the file descriptor. > Must be called before sending any log message. > > Thanks, > Miquel > > On Wednesday 14 April 2010 17:52:58 Miquel Canes wrote: >> Hi, >> If i call the configure() function after add the appender, none of them >> works. Well, all the loggers and appenders inside the property file are >> ignored. >> >> If i try put the logger line of the property file on the bottom, happens >> the same that if that line are on the top of the property file. >> >> And finally if I don't call the configure function, only stdout log works >> (default appender) but the file appender added inside the program is still >> not working. >> >> Maybe we need to put some more sets to the $appender or something like that >> to add an appender inside the program. >> >> Thanks, >> Miquel >> >> On Wednesday 14 April 2010 17:08:03 Christian Grobmeier wrote: >> > Hm >> > >> > I think I know the problem. Its because you first need to configure >> > the appenders and then the loggers. Otherwise the references are not >> > set. This is also true for property files in general in log4php. First >> > appenders, then loggers. >> > >> > In your case - I am not sure if there is a workaround for this because >> > you configuration is mixed. You probably can try it out with putting >> > the rootLogger defintion on the bottom of your property file or >> > assigning the appender before calling configure(). i am not sure if it >> > helps. >> > >> > There is already an issue in Jira which addresses this >> > >> > Christian >> > >> > 2010/4/14 Miquel Canes <miquel.ca...@cast-info.es>: >> > > Hello, >> > > It doesn't work. >> > > >> > > Logger::configure(dirname(__FILE__) . '/../log4php.properties'); >> > > >> > > $logger = Logger::getRootLogger(); >> > > >> > > $appender = new LoggerAppenderFile("programmatically"); >> > > $layout = new LoggerLayoutPattern("[%p] %t %c - %m%n"); >> > > >> > > $appender->setLayout($layout); >> > > $appender->setFileName("programmatically.log"); >> > > $appender->setAppend(true); >> > > $appender->setThreshold("ALL"); >> > > $logger->addAppender($appender); >> > > >> > > echo $logger->isInfoEnabled() . "\n"; >> > > >> > > $allappenders = $logger->getAllAppenders(); >> > > foreach ($allappenders as $nappender){ >> > > >> > > echo $nappender->getName()."\n"; >> > > >> > > } >> > > >> > > $logger->info("info text"); >> > > >> > > With this code it write: >> > > 1 >> > > stdout >> > > R >> > > programmatically >> > > >> > > >> > > I'm using a config file too and the file appender defined on it works. >> > > >> > > log4php.properties content: >> > > >> > > #R - Default Log file appender. >> > > log4php.rootLogger=all, stdout, R >> > > >> > > log4php.appender.stdout=LoggerAppenderConsole >> > > log4php.appender.stdout.layout=LoggerLayoutPattern >> > > >> > > # Pattern to output the caller's file name and line number. >> > > #log4php.appender.stdout.layout.ConversionPattern=[%p] %t %c - %m%n >> > > >> > > log4php.appender.R=LoggerAppenderRollingFile >> > > log4php.appender.R.File=testrollingappender.log >> > > >> > > log4php.appender.R.MaxFileSize=100KB >> > > # Keep one backup file >> > > log4php.appender.R.MaxBackupIndex=1 >> > > >> > > log4php.appender.R.layout=LoggerLayoutPattern >> > > log4php.appender.R.layout.ConversionPattern=[%p] %t %c - %m%n >> > > >> > > >> > > Maybe, a programmatically appender cannot be added if a configure file >> > > is used? But it does not make any sense. >> > > >> > > Thanks, >> > > Miquel >> > > >> > > On Wednesday 14 April 2010 16:23:59 Christian Grobmeier wrote: >> > >> Hello, >> > >> >> > >> whats returned if you do: >> > >> >> > >> echo $logger->isInfoEnabled(); >> > >> >> > >> My guess is that info level is not enabled for the root logger >> > >> >> > >> Also you might need to set a threshhold for your appender: >> > >> $appender->setThreshold($threshhold); >> > >> >> > >> which is in fact a LoggerLevel. If you use ALL, you outputing all >> > >> >> > >> Pls let me know if that worked for you >> > >> >> > >> Christian >> > >> >> > >> 2010/4/13 Miquel Canes <miquel.ca...@cast-info.es>: >> > >> > Hello, >> > >> > >> > >> > I'm trying to add a file appender programmatically. >> > >> > >> > >> > I'm using this piece of code >> > >> > >> > >> > $logger = Logger::getRootLogger(); >> > >> > >> > >> > $appender = new LoggerAppenderFile("programmatically"); >> > >> > $layout = new LoggerLayoutPattern("[%p] %t %c - %m%n"); >> > >> > >> > >> > $appender->setLayout($layout); >> > >> > $appender->setFileName("programmatically.log"); >> > >> > $appender->setAppend(true); >> > >> > $logger->addAppender($appender); >> > >> > >> > >> > $allappenders = $logger->getAllAppenders(); >> > >> > foreach ($allappenders as $nappender){ >> > >> > >> > >> > echo $nappender->getName()."\n"; >> > >> > >> > >> > } >> > >> > >> > >> > $logger->info("info text"); >> > >> > >> > >> > >> > >> > >> > >> > It show the new appender when he print all the appenders but it >> > >> > doesn't create the new log file. >> > >> > >> > >> > How can I add a new file appender to the logger? >> > >> > >> > >> > Thanks, >> > >> > Miquel >> > >> > >> > >> > *Advertencia legal: en virtud de lo establecido en la Ley Orgánica >> > >> > 15/1999 de Protección de Datos de Carácter Personal, le informamos >> > >> > de que los datos personales que pueda facilitarnos se incorporaran >> > >> > a un fichero automatizado titularidad de CAST INFO, S.A. con la >> > >> > finalidad de gestionar la relación negocial que nos vincula. Podrá >> > >> > revocar su consentimiento al tratamiento de los datos, así como >> > >> > ejercer sus derechos de acceso, rectificación, cancelación u >> > >> > oposición >> > >> > dirigiéndose por escrito a CAST INFO domiciliada en C/ Tuset 23, 1º >> > >> > -- 08006 Barcelona, o a la dirección de correo electrónico >> > >> > l...@cast-info.es. >> > >> > >> > >> > Este mensaje y los ficheros anexos que pueda contener son >> > >> > confidenciales, pueden contener información sometida a secreto >> > >> > profesional y se dirige exclusivamente a su destinatario. Si ha >> > >> > recibido este mensaje por error o tiene conocimiento del mismo por >> > >> > cualquier motivo, le rogamos que nos lo comunique inmediatamente por >> > >> > este mismo medio y se abstenga de utilizarlo, reproducirlo, >> > >> > alterarlo, archivarlo o comunicarlo a terceros. El emisor no se >> > >> > responsabiliza de posibles perjuicios derivados de la captura, >> > >> > incorporaciones de virus o cualesquiera otras manipulaciones >> > >> > efectuadas por terceros. >> > >> > >> > >> > Antes de imprimir este e-mail piense bien si es necesario hacerlo. >> > >> >> > >> *Advertencia legal: en virtud de lo establecido en la Ley Org�nica >> > >> 15/1999 de Protecci�n de Datos de Car�cter Personal, le informamos de >> > >> que los datos personales que pueda facilitarnos se incorporaran a un >> > >> fichero automatizado titularidad de CAST INFO, S.A. con la finalidad >> > >> de gestionar la relaci�n negocial que nos vincula. Podr� revocar su >> > >> consentimiento al tratamiento de los datos, as� como ejercer sus >> > >> derechos de acceso, rectificaci�n, cancelaci�n u oposici�n >> > >> dirigi�ndose por escrito a CAST INFO domiciliada en C/ Tuset 23, 1� >> > >> -- 08006 Barcelona, o a la direcci�n de correo electr�nico >> > >> l...@cast-info.es. >> > >> >> > >> Este mensaje y los ficheros anexos que pueda contener son >> > >> confidenciales, pueden contener informaci�n sometida a secreto >> > >> profesional y se dirige exclusivamente a su destinatario. Si ha >> > >> recibido este mensaje por error o tiene conocimiento del mismo por >> > >> cualquier motivo, le rogamos que nos lo comunique inmediatamente por >> > >> este mismo medio y se abstenga de utilizarlo, reproducirlo, alterarlo, >> > >> archivarlo o comunicarlo a terceros. El emisor no se responsabiliza de >> > >> posibles perjuicios derivados de la captura, incorporaciones de virus >> > >> o cualesquiera otras manipulaciones efectuadas por terceros. >> > >> >> > >> Antes de imprimir este e-mail piense bien si es necesario hacerlo. >