You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@logging.apache.org by Daniel Carvalho <dc...@finibanco.pt> on 2006/06/29 18:03:53 UTC

multiple files

Hi.

i would like to have log4j configured so that each logger is appended to a different file.

The filename would be based on logger's name, with dots replaced by file-separator. For instance, the logger named "aplic.dada.x1" would go to
"/MYLOGDIR/aplic/dada/x1.log"

It would be nice to have an appender "FileTreeAppender" with this funcionality. Then i would configure the root logger to use this appender.
Acorddingly to log4j rules, all other loggers would inherit this appender.

But this wouldn't work, because all loggers would use the same instance of FileTreeAppender, but i want their outputs to go to different files. One
solution would be the "FileTreeAppender.doAppend" method choose the file based in LoggingEvent.getLoggerName(), but this would be very slow.

So i think i will have to dinamically create an FileAppender for each Logger. I would like to ask if there is a way to automatically do this, each
time someone calls Logger.getLogger.

I saw that one solution was to define LoggerFactory. But the API says: "The usage of custom logger factories is discouraged and no longer documented."

can someone point to better solutions?

thanks
daniel


__________________________________________________

Esta mensagem e quaisquer ficheiros anexos são confidenciais, destinando-se
ao uso exclusivo da pessoa e/ou entidade a que se dirigem. Caso não se lhe
destine, ou não seja responsável pelo seu encaminhamento ao destinatário,
informamos que a recebeu por engano. Qualquer utilização, distribuição,
reencaminhamento ou outra forma de revelação a terceiros, impressão ou
cópia são expressamente proibidos; sendo que agradecemos que destrua a
mensagem de imediato, informando o seu emissor ou o Finibanco do sucedido.
Não obstante o Finibanco utilizar software anti-vírus como precaução, não é
possível garantir que a presente mensagem e eventuais ficheiros anexos não
contêm vírus, pelo que não consideramos da responsabilidade desta
instituição eventuais consequências inerentes. Alerta-se, ainda, que as
mensagens transmitidas por este meio podem ser interceptadas, corrompidas,
perdidas, destruídas ou entregues com atraso ao destinatário.




Re: multiple files

Posted by Boris Unckel <bo...@gmx.net>.
Hello Daniel,

Curt Arnold wrote:
>
> On Jun 29, 2006, at 11:03 AM, Daniel Carvalho wrote:
>
>> Hi.
>>
>> i would like to have log4j configured so that each logger is appended 
>> to a different file.
>>
>> The filename would be based on logger's name, with dots replaced by 
>> file-separator. For instance, the logger named "aplic.dada.x1" would 
>> go to
>> "/MYLOGDIR/aplic/dada/x1.log"
>>
>> It would be nice to have an appender "FileTreeAppender" with this 
>> funcionality. Then i would configure the root logger to use this 
>> appender.
>> Acorddingly to log4j rules, all other loggers would inherit this 
>> appender.
>>
>> But this wouldn't work, because all loggers would use the same 
>> instance of FileTreeAppender, but i want their outputs to go to 
>> different files. One
>> solution would be the "FileTreeAppender.doAppend" method choose the 
>> file based in LoggingEvent.getLoggerName(), but this would be very slow.
>>
>
> All you would be adding is a get() on a hash map to map logger name 
> with to get an OutputStream for each call to doAppend.  The cost of 
> mapping logger name to stream will be trivial compared to actual file 
> io.  You would end up having an open OutputStream around for every 
> encountered log name until the end of the appenders lifetime, but I 
> don't know if you had a chance to work around that in any other approach.
There could be a workaround: The information about the logger name is
part of each log entry. You could easily write a script which splits
up one big log file into several others at your choice.
Why do you need that? You cannot see the flow of the application after
splitting the log.

This is the wrong list for this discussion. It belongs to log4-users.

Regards
Boris



Re: multiple files

Posted by Curt Arnold <ca...@apache.org>.
On Jun 29, 2006, at 11:03 AM, Daniel Carvalho wrote:

> Hi.
>
> i would like to have log4j configured so that each logger is  
> appended to a different file.
>
> The filename would be based on logger's name, with dots replaced by  
> file-separator. For instance, the logger named "aplic.dada.x1"  
> would go to
> "/MYLOGDIR/aplic/dada/x1.log"
>
> It would be nice to have an appender "FileTreeAppender" with this  
> funcionality. Then i would configure the root logger to use this  
> appender.
> Acorddingly to log4j rules, all other loggers would inherit this  
> appender.
>
> But this wouldn't work, because all loggers would use the same  
> instance of FileTreeAppender, but i want their outputs to go to  
> different files. One
> solution would be the "FileTreeAppender.doAppend" method choose the  
> file based in LoggingEvent.getLoggerName(), but this would be very  
> slow.
>

All you would be adding is a get() on a hash map to map logger name  
with to get an OutputStream for each call to doAppend.  The cost of  
mapping logger name to stream will be trivial compared to actual file  
io.  You would end up having an open OutputStream around for every  
encountered log name until the end of the appenders lifetime, but I  
don't know if you had a chance to work around that in any other  
approach.