public Log4J2LogImpl(String category) { logger=LogManager.getFormatterLogger(category); }
public Log4J2LogImpl(Class<?> category) { logger = LogManager.getFormatterLogger(category); }
/** * Returns a formatter Logger using the fully qualified name of the calling Class as the Logger name. * <p> * This logger lets you use a {@link java.util.Formatter} string in the message to format parameters. * </p> * * @return The Logger for the calling class. * @throws UnsupportedOperationException if the calling class cannot be determined. * @since 2.4 */ public static Logger getFormatterLogger() { return getFormatterLogger(StackLocatorUtil.getCallerClass(2)); }
/** * Returns a formatter Logger with the specified name. * <p> * This logger let you use a {@link java.util.Formatter} string in the message to format parameters. * </p> * <p> * Short-hand for {@code getLogger(name, StringFormatterMessageFactory.INSTANCE)} * </p> * * @param name The logger name. If null it will default to the name of the calling class. * @return The Logger, created with a {@link StringFormatterMessageFactory} * @throws UnsupportedOperationException if {@code name} is {@code null} and the calling class cannot be determined. * @see Logger#fatal(Marker, String, Object...) * @see Logger#fatal(String, Object...) * @see Logger#error(Marker, String, Object...) * @see Logger#error(String, Object...) * @see Logger#warn(Marker, String, Object...) * @see Logger#warn(String, Object...) * @see Logger#info(Marker, String, Object...) * @see Logger#info(String, Object...) * @see Logger#debug(Marker, String, Object...) * @see Logger#debug(String, Object...) * @see Logger#trace(Marker, String, Object...) * @see Logger#trace(String, Object...) * @see StringFormatterMessageFactory */ public static Logger getFormatterLogger(final String name) { return name == null ? getFormatterLogger(StackLocatorUtil.getCallerClass(2)) : getLogger(name, StringFormatterMessageFactory.INSTANCE); }
@Test public void getFormatterLogger() { // The TestLogger logger was already created in an instance variable for this class. // The message factory is only used when the logger is created. final TestLogger testLogger = (TestLogger) LogManager.getFormatterLogger(); final TestLogger altLogger = (TestLogger) LogManager.getFormatterLogger(getClass()); assertEquals(testLogger.getName(), altLogger.getName()); assertNotNull(testLogger); assertMessageFactoryInstanceOf(testLogger.getMessageFactory(), StringFormatterMessageFactory.class); assertEqualMessageFactory(StringFormatterMessageFactory.INSTANCE, testLogger); testLogger.debug("%,d", Integer.MAX_VALUE); assertEquals(1, testLogger.getEntries().size()); assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0)); }
@Test public void getFormatterLogger_Class() { // The TestLogger logger was already created in an instance variable for this class. // The message factory is only used when the logger is created. final TestLogger testLogger = (TestLogger) LogManager.getFormatterLogger(TestStringFormatterMessageFactory.class); assertNotNull(testLogger); assertMessageFactoryInstanceOf(testLogger.getMessageFactory(), StringFormatterMessageFactory.class); assertEqualMessageFactory(StringFormatterMessageFactory.INSTANCE, testLogger); testLogger.debug("%,d", Integer.MAX_VALUE); assertEquals(1, testLogger.getEntries().size()); assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0)); }
@Test public void getFormatterLogger_String() { final StringFormatterMessageFactory messageFactory = StringFormatterMessageFactory.INSTANCE; final TestLogger testLogger = (TestLogger) LogManager.getFormatterLogger("getLogger_String_StringFormatterMessageFactory"); assertNotNull(testLogger); assertMessageFactoryInstanceOf(testLogger.getMessageFactory(), StringFormatterMessageFactory.class); assertEqualMessageFactory(messageFactory, testLogger); testLogger.debug("%,d", Integer.MAX_VALUE); assertEquals(1, testLogger.getEntries().size()); assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0)); }
@Test public void getFormatterLogger_Object() { // The TestLogger logger was already created in an instance variable for this class. // The message factory is only used when the logger is created. final TestLogger testLogger = (TestLogger) LogManager.getFormatterLogger(new TestStringFormatterMessageFactory()); assertNotNull(testLogger); assertMessageFactoryInstanceOf(testLogger.getMessageFactory(), StringFormatterMessageFactory.class); assertEqualMessageFactory(StringFormatterMessageFactory.INSTANCE, testLogger); testLogger.debug("%,d", Integer.MAX_VALUE); assertEquals(1, testLogger.getEntries().size()); assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0)); }
public Log4J2LogImpl(String category) { logger=LogManager.getFormatterLogger(category); }
public Log4J2LogImpl(Class<?> category) { logger = LogManager.getFormatterLogger(category); }
public Log4J2LogImpl(String category) { logger=LogManager.getFormatterLogger(category); }
public Log4J2LogImpl(String category) { logger=LogManager.getFormatterLogger(category); }
public Log4J2LogImpl(Class<?> category) { logger = LogManager.getFormatterLogger(category); }
public Log4J2LogImpl(Class<?> category) { logger = LogManager.getFormatterLogger(category); }
public Log4J2LogImpl(Class<?> category) { logger = LogManager.getFormatterLogger(category); }
public Log4J2LogImpl(String category) { logger=LogManager.getFormatterLogger(category); }
/** * Returns a formatter Logger using the fully qualified name of the calling Class as the Logger name. * <p> * This logger lets you use a {@link java.util.Formatter} string in the message to format parameters. * </p> * * @return The Logger for the calling class. * @throws UnsupportedOperationException if the calling class cannot be determined. * @since 2.4 */ public static Logger getFormatterLogger() { return getFormatterLogger(StackLocatorUtil.getCallerClass(2)); }
static public Logger getLoger() { if (null != logger) { return logger; } String name = "xresloader"; InputStream inCfg = getInstance().getClass().getClassLoader().getResourceAsStream("application.properties"); Properties props = new Properties(); try { props.load(inCfg); name = props.getProperty("name"); } catch (IOException e) { System.err.println(String.format("[ERROR] Get application name failed.\n%s", e.toString())); } try { logger = LogManager.getFormatterLogger(name); } catch (UnsupportedCharsetException e) { System.err.println(String.format("[WARN] Unknown console charset %s, we will try use UTF-8 for console output", e.getCharsetName())); } if (null == logger) { //logger = LogManager.get } return logger; } }
/** * Returns a formatter Logger with the specified name. * <p> * This logger let you use a {@link java.util.Formatter} string in the message to format parameters. * </p> * <p> * Short-hand for {@code getLogger(name, StringFormatterMessageFactory.INSTANCE)} * </p> * * @param name The logger name. If null it will default to the name of the calling class. * @return The Logger, created with a {@link StringFormatterMessageFactory} * @throws UnsupportedOperationException if {@code name} is {@code null} and the calling class cannot be determined. * @see Logger#fatal(Marker, String, Object...) * @see Logger#fatal(String, Object...) * @see Logger#error(Marker, String, Object...) * @see Logger#error(String, Object...) * @see Logger#warn(Marker, String, Object...) * @see Logger#warn(String, Object...) * @see Logger#info(Marker, String, Object...) * @see Logger#info(String, Object...) * @see Logger#debug(Marker, String, Object...) * @see Logger#debug(String, Object...) * @see Logger#trace(Marker, String, Object...) * @see Logger#trace(String, Object...) * @see StringFormatterMessageFactory */ public static Logger getFormatterLogger(final String name) { return name == null ? getFormatterLogger(StackLocatorUtil.getCallerClass(2)) : getLogger(name, StringFormatterMessageFactory.INSTANCE); }