Note that there are some explanatory texts on larger screens.

plurals
  1. POCan I disable the log header for ruby logger?
    text
    copied!<p>I'm currently running into kind of a problem.</p> <p>As you might know, the ruby logger adds a logging header at the top of every newly created logfile.</p> <pre><code>"# Logfile created on %s by %s\n" % [Time.now.to_s, Logger::ProgName] </code></pre> <p>I am logging CSV files to import them in a warehouse later, usually I just skip the first line with the header. It's seems like there is a bug in the logger, because sometimes the logging header appears more than once, right in the middle of a log file.</p> <p>So I decided to simply leave that header out. To my surprise I didn't find any argument one could pass at the creation of a logger. I thought of something like this:</p> <pre><code>Logger.new "info.log", :skip_header =&gt; true </code></pre> <p>But it's just not there. I searched in the ruby core sources and surprisingly there really is nothing that could prevent the logger from adding the log header:</p> <pre><code>def create_logfile(filename) logdev = open(filename, (File::WRONLY | File::APPEND | File::CREAT)) logdev.sync = true add_log_header(logdev) logdev end def add_log_header(file) file.write( "# Logfile created on %s by %s\n" % [Time.now.to_s, Logger::ProgName] ) end </code></pre> <p>Does anyone have an idea what I could do, to prevent the log header? I'm using Ruby 1.8.7 302 with Rails 2.3.5 here. Simply ignoring the comments on the warehouse side is not possible because I have no control over the code there, and it seems to be to risky to simply ignore it, if something goes wrong with a a logging line.</p> <p>Does someone know a logger that allows this? Do you think it would be a good idea to use and write plain to a file?</p> <p>Thanks in advance, Tommy</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload