Skip to content
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

Merged
merged 3 commits into from
Jan 4, 2018

Conversation

juliancheal
Copy link
Member

No description provided.

@@ -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)
Copy link
Member

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) ?

Copy link
Member Author

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?

Copy link
Member

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

@juliancheal juliancheal force-pushed the fix_logger_size_limit branch 2 times, most recently from bb7c84b to b65291e Compare November 21, 2017 18:56
@juliancheal juliancheal force-pushed the fix_logger_size_limit branch 3 times, most recently from 9be4917 to 7cfac18 Compare November 21, 2017 21:06
@juliancheal juliancheal changed the title [WIP] Truncating log messages when they are too large Truncating log messages when they are too large Nov 21, 2017
@juliancheal juliancheal force-pushed the fix_logger_size_limit branch from 7cfac18 to 4bd5c1d Compare November 21, 2017 21:08
@miq-bot miq-bot removed the wip label Nov 21, 2017
@juliancheal juliancheal force-pushed the fix_logger_size_limit branch 2 times, most recently from 3971069 to 673ed3d Compare November 21, 2017 21:15
@@ -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
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok thanks @Fryguy.

Copy link
Member

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.

@juliancheal juliancheal force-pushed the fix_logger_size_limit branch from 673ed3d to 921f694 Compare November 21, 2017 21:19
@@ -95,6 +95,18 @@
expect(VMDBLogger.contents("mylog.log")).to eq("")
end

context "long messages" do
before(:each) do
Copy link
Member

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) }

Copy link
Member

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

Copy link
Member Author

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 :)

@Fryguy
Copy link
Member

Fryguy commented Nov 21, 2017

I think my other comment got lost;

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.

@juliancheal
Copy link
Member Author

🍏 ❓

@@ -1,5 +1,6 @@
require 'util/vmdb-logger'
require 'util/miq-password'
require 'active_support/core_ext/string'
Copy link
Member

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

Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member

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)

@juliancheal juliancheal force-pushed the fix_logger_size_limit branch from 24b2d56 to 3eb11a5 Compare November 22, 2017 14:58
@@ -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
Copy link
Member

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.

Copy link
Member

@Fryguy Fryguy Nov 27, 2017

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point it is.

@juliancheal juliancheal force-pushed the fix_logger_size_limit branch from 3eb11a5 to 23a2664 Compare November 28, 2017 14:39
@juliancheal
Copy link
Member Author

@Fryguy changes all done.

@juliancheal juliancheal force-pushed the fix_logger_size_limit branch from 23a2664 to 33af821 Compare November 28, 2017 14:49
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
@juliancheal juliancheal force-pushed the fix_logger_size_limit branch from 33af821 to 3f16029 Compare December 6, 2017 15:42
@juliancheal
Copy link
Member Author

@Fryguy I thought I'd pushed my changes, guess not. Sorry my bad! Just made the change you asked for. Should hopefully be green.

@miq-bot
Copy link
Member

miq-bot commented Dec 6, 2017

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
2 files checked, 0 offenses detected
Everything looks fine. 👍

@juliancheal
Copy link
Member Author

@Fryguy 🍏 We good to go?

@Fryguy Fryguy merged commit d09f86a into ManageIQ:master Jan 4, 2018
@Fryguy Fryguy added this to the Sprint 77 Ending Jan 15, 2018 milestone Jan 4, 2018
simaishi pushed a commit that referenced this pull request Jan 4, 2018
Truncating log messages when they are too large
(cherry picked from commit d09f86a)
@simaishi
Copy link
Contributor

simaishi commented Jan 4, 2018

Gaprindashvili backport details:

$ git log -1
commit 36602cedbf23f88d9e7d8e78d7517e70e36ed227
Author: Jason Frey <[email protected]>
Date:   Thu Jan 4 10:33:47 2018 -0500

    Merge pull request #315 from juliancheal/fix_logger_size_limit
    
    Truncating log messages when they are too large
    (cherry picked from commit d09f86aa78fdaf68b832f28c69cd8024df416bca)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants