List of usage examples for java.util.logging Logger isLoggable
public boolean isLoggable(Level level)
From source file:Main.java
public static void main(String[] argv) throws Exception { Logger logger = Logger.getLogger("com.mycompany.MyClass"); // Check if the message will be logged if (logger.isLoggable(Level.FINEST)) { logger.finest("my finest message"); }/*from ww w . ja va 2s . c o m*/ }
From source file:fr.opensagres.xdocreport.core.logging.LogUtils.java
/** * Checks log level and logs//from www .j a va 2s .c om * * @param logger the Logger the log to * @param level the severity level * @param message the log message * @param parameters the parameters to substitute into message */ public static void log(Logger logger, Level level, String message, Object[] parameters) { if (logger.isLoggable(level)) { doLog(logger, level, message, null); } }
From source file:fr.opensagres.xdocreport.core.logging.LogUtils.java
/** * Allows both parameter substitution and a typed Throwable to be logged. * /*from ww w . j a va2 s .c o m*/ * @param logger the Logger the log to * @param level the severity level * @param message the log message * @param throwable the Throwable to log * @param parameter the parameter to substitute into message */ public static void log(Logger logger, Level level, String message, Throwable throwable, Object parameter) { if (logger.isLoggable(level)) { final String formattedMessage = MessageFormat.format(message, parameter); doLog(logger, level, formattedMessage, throwable); } }
From source file:fr.opensagres.xdocreport.core.logging.LogUtils.java
/** * Allows both parameter substitution and a typed Throwable to be logged. * //ww w . j a v a 2s . c o m * @param logger the Logger the log to * @param level the severity level * @param message the log message * @param throwable the Throwable to log * @param parameters the parameters to substitute into message */ public static void log(Logger logger, Level level, String message, Throwable throwable, Object... parameters) { if (logger.isLoggable(level)) { final String formattedMessage = MessageFormat.format(message, parameters); doLog(logger, level, formattedMessage, throwable); } }
From source file:MyClass.java
public boolean myMethod(int p1, Object p2) { Logger logger = Logger.getLogger("com.mycompany.MyClass"); if (logger.isLoggable(Level.FINER)) { logger.entering(this.getClass().getName(), "myMethod", new Object[] { new Integer(p1), p2 }); }//from w w w .j a v a 2 s . c o m System.out.println("Method body"); boolean result = true; if (logger.isLoggable(Level.FINER)) { logger.exiting(this.getClass().getName(), "myMethod", new Boolean(result)); logger.exiting(this.getClass().getName(), "myMethod"); } return result; }
From source file:mockit.integration.logging.LoggingIntegrationsTest.java
@Test public void jdkLoggingShouldLogNothing() { Logger log1 = Logger.getAnonymousLogger(); Logger log2 = Logger.getAnonymousLogger("bundle"); Logger log3 = Logger.getLogger(LoggingIntegrationsTest.class.getName()); Logger log4 = Logger.getLogger(LoggingIntegrationsTest.class.getName(), "bundle"); assertFalse(log1.isLoggable(Level.ALL)); log1.severe("testing that logger does nothing"); log2.setLevel(Level.WARNING); log2.info("testing that logger does nothing"); log3.warning("testing that logger does nothing"); log4.fine("testing that logger does nothing"); log4.finest("testing that logger does nothing"); }
From source file:com.ibm.ws.lars.rest.RepositoryRESTResourceLoggingTest.java
@Test public void testGetFakeImConfig(@Mocked final Logger logger) { new Expectations() { {/*from w ww. j av a 2s . c om*/ logger.isLoggable(Level.FINE); result = true; logger.fine("getFakeImConfig called"); } }; getRestResource().getFakeImConfig(); }
From source file:com.ibm.ws.lars.rest.RepositoryRESTResourceLoggingTest.java
@Test public void testDeleteAttachment(@Mocked final Logger logger) throws InvalidIdException { new Expectations() { {/* w w w . jav a2s.c o m*/ logger.isLoggable(Level.FINE); result = true; logger.fine("deleteAttachment called for assetId: " + NON_EXISTENT_ID + " and attachmentId: " + NON_EXISTENT_ID); } }; getRestResource().deleteAttachment(NON_EXISTENT_ID, NON_EXISTENT_ID); }
From source file:com.ibm.ws.lars.rest.RepositoryRESTResourceLoggingTest.java
@Test public void testGetAttachments(@Mocked final Logger logger, @Mocked final SecurityContext sc) throws Exception { new Expectations() { {//from ww w . ja v a 2s . c o m logger.isLoggable(Level.FINE); result = true; logger.fine("getAttachments called for assetId: " + NON_EXISTENT_ID); sc.isUserInRole("Administrator"); result = true; } }; getRestResource().getAttachments(NON_EXISTENT_ID, dummyUriInfo, sc); }
From source file:com.ibm.ws.lars.rest.RepositoryRESTResourceLoggingTest.java
@Test public void testDeleteAssets(@Mocked final Logger logger) throws InvalidIdException, NonExistentArtefactException { new Expectations() { {/*from www . jav a 2 s . c o m*/ logger.isLoggable(Level.FINE); result = true; logger.fine("deleteAsset called with id of " + NON_EXISTENT_ID); } }; getRestResource().deleteAsset(NON_EXISTENT_ID); }