Done as getLogger(Object).
Here is another one:
public SocketServer(int port) throws IOException {
server = new ServerSocket(port);
if (logger == null) {
logger = LogManager.getLogger(getClass().getName(), port);
}
}
Where:
/**
* Returns a Logger with the name built from the given values. For
example:
*
* <pre>
* getLogger("a", "b", "c") = a Logger named "a.b.c"
* getLogger(getClass().getName(), portNumber) = a Logger named
"com.foo.http.80"</pre>
*
* @param values
* The logger name values.
* @return The Logger.
*/
public static Logger getLogger(final Object... values) {
...
}
The trick is that to test this, I had to do:
@Test
public void getLoggerByObjectArray() {
Logger classLogger = LogManager.getLogger(getClass().getName() +
".80");
assertEquals(classLogger, LogManager.getLogger(LoggerTest.class,
80));
}
Because Logger has no getName() API? How can that be?
Gary
On Wed, Oct 10, 2012 at 9:31 AM, Gary Gregory <[email protected]>wrote:
> I think I like getClassNameLogger in case we add more APIs with an
> Object arg. Or is that not YAGNI.
>
> Gary
>
> On Oct 10, 2012, at 9:07, Ralph Goers <[email protected]> wrote:
>
> > getClassNameLogger
>
--
E-Mail: [email protected] | [email protected]
JUnit in Action, 2nd Ed: <http://goog_1249600977>http://bit.ly/ECvg0
Spring Batch in Action: <http://s.apache.org/HOq>http://bit.ly/bqpbCK
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory