1

I'm building a Server-Client app with Perl/Mojolicious and JQuery. The server generates a log file using the Log::Log4perl and send the log file name back to the client so the client can see the progress. In the client I use a regular HTML A link to the log file as:

<a href="logs/blabla.log">See log file</a>

The problem is I click on the 'See log file' in the client side, the browser shows that the file is loading and stuck until the server finishing writing to the file - just then i can see the content of the file.

I configed the Log::Log4perl to autoflush and tried to use 'log4perl.appender.Syncer' and even set the buffer to 0 or 1: log4perl.appender.Buffer but nothing helped - my Log::Log4perl config is:

log4perl.appender.myFILE          = Log::Log4perl::Appender::File
    log4perl.appender.myFILE.filename =  $logfile_name
    log4perl.appender.myFILE.create_at_logtime = 1
    log4perl.appender.myFILE.mode = write
    log4perl.appender.myFILE.autoflush = 1
    log4perl.appender.myFILE.umask    = 0000,
    log4perl.appender.myFILE.layout   = Log::Log4perl::Layout::PatternLayout
    log4perl.appender.myFILE.layout.ConversionPattern = [%p][%d{HH:mm}: %m%n

How can I see the content of the log file when the server is updating it? Thanks a lot and have a nice week,

Seif.

iseif
  • 297
  • 2
  • 14

1 Answers1

0

I am just guessing with this small amount of information. Please post more details to be able to help you. Without the client code I can't tell what is wrong.

Many file based Log::Log4perl appender has an option to turn on/off buffering. Turn off the buffering, it may help.

If I see correctly your example then it does not assign the appender to any loglevel or module.

You could try this out:

# log config
my $log4perl_conf = qq(     
    log4perl.rootLogger                   = INFO,MyFILE 
    log4perl.appender.myFILE          = Log::Log4perl::Appender::File
    log4perl.appender.myFILE.filename =  $logfile_name
    log4perl.appender.myFILE.create_at_logtime = 1
    log4perl.appender.myFILE.mode = append
    log4perl.appender.myFILE.autoflush = 1
    log4perl.appender.myFILE.umask    = 0222,
    log4perl.appender.myFILE.layout   = Log::Log4perl::Layout::PatternLayout
    log4perl.appender.myFILE.layout.ConversionPattern = [%p][%d{HH:mm}: %m%n
    log4perl.appender.myFILE.header_text = "#Log file created!"
);  
# Initialize logging
Log::Log4perl->init_once( \$log4perl_conf );    
$Log::Log4perl::JOIN_MSG_ARRAY_CHAR=' '; 
my $logger = get_logger(__PACKAGE__);
$logger->info("test! $$");
user1126070
  • 5,059
  • 1
  • 16
  • 15
  • In the client I just add a regular link to the file for example: See log file – iseif Dec 05 '13 at 11:37
  • In the server side I have: log4perl.appender.myFILE = Log::Log4perl::Appender::File log4perl.appender.myFILE.filename = $logfile_name log4perl.appender.myFILE.create_at_logtime = 1 log4perl.appender.myFILE.mode = write log4perl.appender.myFILE.autoflush = 1 log4perl.appender.myFILE.syswrite = 1 log4perl.appender.myFILE.layout = Log::Log4perl::Layout::PatternLayout log4perl.appender.myFILE.layout.ConversionPattern = [%p][%d{HH:mm}]: %m%n – iseif Dec 05 '13 at 11:39
  • log4perl.appender.Syncer = Log::Log4perl::Appender::Synchronized log4perl.appender.Syncer.appender = myFILE – iseif Dec 05 '13 at 11:40