Rails 3.2 feature: unreadable production logs
github.com
github.com
We added tagged logging to deal with the "not in order" problem. Find the process id of the request you're trying to follow, grep for that.
Both problems solved.
I have the same issue with daemons, even prior to 3.2. Tagged logging helps to solve the problem for those too, as it's easy to output an environment variable that's set by the starting script.
http://stackoverflow.com/questions/11561846/rails-3-2-2-log-...
file = File.open("log/production.log", "w")
file.sync = true
Rails.logger = ActiveSupport::BufferedLogger.new(file)1. This commit changed two things: default file mode of open logs is no more sync in production (i.e. it is not automatically flushed by ruby write routines) AND it doesn't buffer log entries anymore (which is actually funny, since, you know, it is called ActiveSupport::BufferedLogger) 2. When IO#sync is false, which was the case, ruby didn't flush upon every write. That manifested itself in logfile entries not appearing immediately after write. 2.1. In some 3.2 release they've reversed that, so sync = true is by default in all latest versions of rails. 3. Since logger doesn't buffer requests anymore, the problem of interleaving messages should still be there, sorry for confusion. 3.1. To solve this, you can either use tag features of recent rails or port older buffered logger itself.
But this is not my point, for me rails has been about sane defaults - this is what makes it fun to start and easy to work with. I just don't see why we fix something that is not broken at all.
They decided to get rid of supposedly unneeded cruft that was hard to maintain and delegate file handling functions to OS.
With a nice UI this would not only solve this problem here but it could potentially offer a lot more insight than just looking at isolated entries in text form.
config.after_initialize do
# Reverse the deprecation of flush in BufferedLogger
module ActiveSupport
class BufferedLogger
def flush
@log_dest.flush
end
def respond_to?(method, include_private = false)
super
end
end
end
# Let the OS buffer the log
Rails.logger.instance_variable_get(:@logger).instance_variable_get(:@log_dest).sync = false
endThe bigger issue is the complete absence structure.
We shouldn't have to resort to addons like lograge[1] to turn that stream of poo into something human- and machine-readable.
ActiveSupport::BufferedLogger#auto_flushing is deprecated. Either set the
sync level on the underlying file handle like this:
f = File.open('foo.log', 'w')
f.sync = true
ActiveSupport::BufferedLogger.new f
Or tune your filesystem. The FS cache is now what controls flushing.
The above from the commit message is incorrect. IO#sync in ruby has nothing to with the filesystem cache, and only controls Ruby's own internal buffers. And as far as I can tell the logger in rails has sync = true by default anyway.And disabling your filesystem cache at the OS level sounds like a terrible idea.
The commit message only makes sense if he actual talks about IO#fdatasync or he means that "f.sync = false" disables the new behavior.
So does anyone know the rationale behind this change? I'm guessing there's actually a good reason and it's just eluding us because our logs are now messy and that appears to be bad.
If you get scrambled lines (ie the contents of two lines can mix up) then I personally would see that as a bug.
No change to IO#sync, IO#fdatasync or the filesystem settings should make it revert to the old behavior. If you set IO#sync to false it might seem like you get something like the old behviour back, but I think you risk scrambled lines since it will the flush when Ruby's buffer is full.
and the useful info that comes after it can of course be included in the commit. but starting at line 3!
well, well.
And more explicitly: https://github.com/torvalds/linux/pull/17#issuecomment-56599...
We have been moving towards commit messages similar to those used in the kernel development (i.e. longer, descriptive) and it has proven very useful indeed
Github itself even uses these rules [2] so I think it's slightly annoying people don't follow them as it looks worse if you use long first lines on the website.
[1] http://tbaggery.com/2008/04/19/a-note-about-git-commit-messa... [2] https://github.com/blog/926-shiny-new-commit-styles
Open up any git GUI; gitk or SourceTree are my two favorite. If you keep your summary lines under 50 characters you can quickly scan a maximal number of commits. Detailed descriptions are great and should be included as well for any substantial commits, but that is not what you want in the summary. That should be added in separate paragraphs after the summary line.
This is not arbitrary, and it has nothing to do with the ability to line wrap, it's about efficient communication faced with a history of tens or hundreds of thousands of commits over time.
Long commit messages are good. But a good first line is essential, since, as Linus points out, that is what gets shown by default by a lot of tools.
vim's syntax highlighting will warn you when you write too much, so i usually do not really notice the length (afair emacs does as well).
The short message first, longer message after is a pretty good middle ground. But if that first sentence is useless, I'd rather just have a single commit message that accurately describes the commit.
I think this is the part people don't understand. The first line should be < 72 chars. After that (and a blank line), write as much as you want.