How can I make log4perl create a log directory if it does not exist?

If my logging directory ( /home/hss/Data/log/DataImport.log ) does not exist when log4perl is initialized, I get this error:

 Cannot write to '/home/hss/Data/log/DataImport.log': No such file or directory 

Is there a way to create a directory myself, without having to specify a directory somewhere other than my log.conf file?

+4
source share
2 answers

I am sure that Log::Log4perl::Appender::File does not create directories. Probably the easiest method would be to subclass it and override the file_open method with the directory discovery / creation code, followed by the original invocation method.

+1
source

Starting with version 1.43, a new mkpath parameter is created in Log :: Log4perl :: Appender :: File, which creates a directory if it is set to true in the configuration.

Docu 1.43: http://search.cpan.org/dist/Log-Log4perl-1.43/lib/Log/Log4perl/Appender/File.pm

+1
source

Source: https://habr.com/ru/post/1339475/


All Articles