Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/main/java/com/metamx/common/logger/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ public void info(Throwable t, String message, Object... formatArgs)
}
}

/**
* Protect against assuming slf4j convention. use `warn(Throwable t, String message, Object... formatArgs)` instead
* @param message The string message
* @param t The Throwable to log
*/
@Deprecated
public void warn(String message, Throwable t) {
log.warn(message, t);
}

public void warn(String message, Object... formatArgs)
{
log.warn(StringUtils.safeFormat(message, formatArgs));
Expand All @@ -92,6 +102,16 @@ public void error(String message, Object... formatArgs)
log.error(StringUtils.safeFormat(message, formatArgs));
}

/**
* Protect against assuming slf4j convention. use `error(Throwable t, String message, Object... formatArgs)` instead
* @param message The string message
* @param t The Throwable to log
*/
@Deprecated
public void error(String message, Throwable t) {
log.error(message, t);
}

public void error(Throwable t, String message, Object... formatArgs)
{
log.error(StringUtils.safeFormat(message, formatArgs), t);
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/com/metamx/common/logger/LoggerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,14 @@ public void testLogWithCrazyMessages()
final Logger log = new Logger(LoggerTest.class);
log.warn(message);
}

@Test
public void testLegacyLogging()
{
final Logger log = new Logger(LoggerTest.class);
final Throwable throwable = new Throwable();
// These should show up in an IDE as deprecated, but shouldn't actually fail.
log.error("foo", throwable);
log.warn("foo", throwable);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i think you are expecting IDE to flag these as deprecated. but since there are no asserts, its difficult for someone to understand what is being "tested" here. can you add comment telling why this test needs to exist or may be remove it since it can't really "fail" whether or not the thing you expected works or not.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok sure

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

}