-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Truncating log messages when they are too large #315
Conversation
lib/gems/pending/util/vmdb-logger.rb
Outdated
@@ -157,7 +157,7 @@ class Formatter < Logger::Formatter | |||
|
|||
def call(severity, time, progname, msg) | |||
msg = prefix_task_id(msg2str(msg)) | |||
|
|||
msg = truncate_large_lines(msg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about just msg = prefix_task_id(msg2str(msg)).truncate(max_log_line_length)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guess so, was worried about making an incomplete char at the end of the line, then again that could happen with byteslice
too.
And I guess we're truncating the line anyway so a bust char wouldn't be the end of the world?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah and it automatically appends ...
so you can tell that it was truncated
bb7c84b
to
b65291e
Compare
9be4917
to
7cfac18
Compare
7cfac18
to
4bd5c1d
Compare
3971069
to
673ed3d
Compare
lib/gems/pending/util/vmdb-logger.rb
Outdated
@@ -156,8 +156,9 @@ class Formatter < Logger::Formatter | |||
FORMAT = "[----] %s, [%s#%d:%x] %5s -- %s: %s\n" | |||
|
|||
def call(severity, time, progname, msg) | |||
msg = prefix_task_id(msg2str(msg)) | |||
max_log_line_length = 1.megabyte # TODO: (julian) Move to config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't worry about config, because I can't see a user configuring this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok thanks @Fryguy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might need to add some activesupport extensions at the top of this file...it can run standalone without the rails env. See how we use core_ext above.
673ed3d
to
921f694
Compare
spec/util/vmdb-logger_spec.rb
Outdated
@@ -95,6 +95,18 @@ | |||
expect(VMDBLogger.contents("mylog.log")).to eq("") | |||
end | |||
|
|||
context "long messages" do | |||
before(:each) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The :each
is redundant, so you can remove it... however, you can also just make this a let
let(:logger) { VMDBLogger.new(@log) }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See way up above for an example of using let
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was future proofing for when we add more tests :)
I think my other comment got lost;
|
🍏 ❓ |
spec/util/vmdb-logger_spec.rb
Outdated
@@ -1,5 +1,6 @@ | |||
require 'util/vmdb-logger' | |||
require 'util/miq-password' | |||
require 'active_support/core_ext/string' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think you need this in lib/gems/pending/util/vmdb-logger.rb
too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preferably in the vmdb-logger and not in the spec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see, so active_support/core_ext/string
should be included via util/vmdb-logger
? @Fryguy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, since that's where you actually use it (for the truncate call)
24b2d56
to
3eb11a5
Compare
lib/gems/pending/util/vmdb-logger.rb
Outdated
@@ -156,8 +157,9 @@ class Formatter < Logger::Formatter | |||
FORMAT = "[----] %s, [%s#%d:%x] %5s -- %s: %s\n" | |||
|
|||
def call(severity, time, progname, msg) | |||
msg = prefix_task_id(msg2str(msg)) | |||
max_log_line_length = 1.megabyte |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this call will happen very frequently, I'm thinking this might be better moved to a constant. That way it doesn't have to re-evaluate 1.megabyte over and over.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, is there an active_support/core_ext for this megabyte method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point it is.
3eb11a5
to
23a2664
Compare
@Fryguy changes all done. |
23a2664
to
33af821
Compare
Allows the tests and gems-pending code to be run standalone. Changed before(:each) to simple let(:foo) in specs MAX_LOG_LINE_LENGTH is a constant
33af821
to
3f16029
Compare
@Fryguy I thought I'd pushed my changes, guess not. Sorry my bad! Just made the change you asked for. Should hopefully be green. |
Checked commits juliancheal/manageiq-gems-pending@ad4fb78~...3f16029 with ruby 2.3.3, rubocop 0.47.1, haml-lint 0.20.0, and yamllint 1.10.0 |
@Fryguy 🍏 We good to go? |
Truncating log messages when they are too large (cherry picked from commit d09f86a)
Gaprindashvili backport details:
|
No description provided.