in reply to Re: log file formatting
in thread log file formatting

Yes, I use ms Windows, IE6.0 browser to view logs. I view logs via browser, just type path to log file http://www. domain.com/logs.txt This is most convenient for me, no other methods required. What should be corrected in code and how?
Thanks.

Replies are listed 'Best First'.
Re^3: log file formatting
by radiantmatrix (Parson) on May 16, 2005 at 13:44 UTC
    Well, hold on there, friend -- no need to get punchy. You might have mentioned that you had this problem in your browser, and not in an editor: this is why it's important to be complete when asking a question, here.

    To fix this code-side rather than client-side, you need to instruct your code to use Windows-style line endings. In your code, wherever you see "\n", use "\r\n" instead. If there are a great number of places that you've already used "\n" and you don't want to hunt them down, you could also use a short Perl script to convert them right before viewing. This might look like:

    #!/usr/bin/perl use strict; use CGI::Simple; my $q = new CGI::Simple; $| = 1; print $q->header( -type => 'text/plain', -expires => '+1m' ); ## the header is for plain text, and the data expires in 1m ## If there's no file parameter, exit with an error message unless ($q->param('file')) { print 'No File was requested'; exit; } open LOG, '<', $q->param('file') or do { # exit with error if we can't open the file print 'Unable to open file ',$q->param('file'),':',$!; exit; }; while (<LOG>) { s{(\r\n)|(\n)}{\r\n}g; ## replace unix with Win line-endings print $_; }
    This is untested

    This should be invoked as http://www.domain.com/myname.pl?file=logs.txt (if you named your script 'myname.pl').


    The Eightfold Path: 'use warnings;', 'use strict;', 'use diagnostics;', perltidy, CGI or CGI::Simple, try the CPAN first, big modules and small scripts, test first.