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

Handle and log error when a DB instance cannot be found #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

schleyfox
Copy link
Contributor

Not a huge issue, but this patch prevents some of our rapidly created or destroyed instances from gumming up the works.

/cc @jtai @ktrice

@ktrice
Copy link
Contributor

ktrice commented Oct 8, 2014

good call. looks good

@pcarrier
Copy link
Contributor

👍

} catch(DBInstanceNotFoundException e) {
// It is possible for an instance to disappear between when we got the list of instances and
// when we go to find the instance's tags.
log.warn("Unable to find RDS instance '" +
Copy link
Contributor

Choose a reason for hiding this comment

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

So the traditional way to log a message with an exception with Slf4j is:

log.warn("message", exception);

That way the logger will, depending on configuration, provide a stacktrace (usually compacted), and/or the exception message, and/or the exception class (usually all of those, and it will do that as it walks up the causality chain so nicely provided by Java exceptions).

Instead of building your string with + (which javac will internally convert to invocations of a StringBuilder constructor if few enough, a constructor then a few appends otherwise), it's best to use the logger's string formatting support. The idea there is that if a log message won't be printed anyway (eg because the log level is disabled), it'll avoid unnecessary work. Stupid example:

log.warn("foo {} baz", "bar", exception);

Essentially, {} in the message format will consume parameters, and the last parameter that's an exception shouldn't be consumed by the message format as the logger will deal with it as it sees fit.

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

Successfully merging this pull request may close these issues.

3 participants