Java Code Examples for java.util.logging.Logger#getAnonymousLogger()

The following examples show how to use java.util.logging.Logger#getAnonymousLogger() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OBUtils.java    From GLEXP-Team-onebillion with Apache License 2.0 6 votes vote down vote up
public static String getExternalFilePathForFolder (String fileName, String folderName, OBSectionController controller)
{
    try
    {
        File outputDir = new File(Environment.getExternalStorageDirectory(), folderName);
        boolean folderCreated = outputDir.mkdir();
        File outputFile = new File(outputDir, fileName);
        return outputFile.getAbsolutePath();
    }
    catch (Exception exception)
    {
        Logger logger = Logger.getAnonymousLogger();
        logger.log(Level.SEVERE, "Error in getExternalFilePathForFolder", exception);
    }
    return null;
}
 
Example 2
Source File: LoggingDeadlock.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws InterruptedException{
    Thread t1 = new Thread(new Runnable() {
        public void run() {
            randomDelay();
            // Trigger Logger.<clinit>
            Logger.getAnonymousLogger();
        }
    });

    Thread t2 = new Thread(new Runnable() {
        public void run() {
            randomDelay();
            // Trigger LogManager.<clinit>
            LogManager.getLogManager();
        }
    });

    t1.start();
    t2.start();

    t1.join();
    t2.join();
    System.out.println("\nTest passed");
}
 
Example 3
Source File: LoggingDeadlock.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws InterruptedException{
    Thread t1 = new Thread(new Runnable() {
        public void run() {
            randomDelay();
            // Trigger Logger.<clinit>
            Logger.getAnonymousLogger();
        }
    });

    Thread t2 = new Thread(new Runnable() {
        public void run() {
            randomDelay();
            // Trigger LogManager.<clinit>
            LogManager.getLogManager();
        }
    });

    t1.start();
    t2.start();

    t1.join();
    t2.join();
    System.out.println("\nTest passed");
}
 
Example 4
Source File: LoggingDeadlock.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws InterruptedException{
    Thread t1 = new Thread(new Runnable() {
        public void run() {
            randomDelay();
            // Trigger Logger.<clinit>
            Logger.getAnonymousLogger();
        }
    });

    Thread t2 = new Thread(new Runnable() {
        public void run() {
            randomDelay();
            // Trigger LogManager.<clinit>
            LogManager.getLogManager();
        }
    });

    t1.start();
    t2.start();

    t1.join();
    t2.join();
    System.out.println("\nTest passed");
}
 
Example 5
Source File: LoggingDeadlock.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws InterruptedException{
    Thread t1 = new Thread(new Runnable() {
        public void run() {
            randomDelay();
            // Trigger Logger.<clinit>
            Logger.getAnonymousLogger();
        }
    });

    Thread t2 = new Thread(new Runnable() {
        public void run() {
            randomDelay();
            // Trigger LogManager.<clinit>
            LogManager.getLogManager();
        }
    });

    t1.start();
    t2.start();

    t1.join();
    t2.join();
    System.out.println("\nTest passed");
}
 
Example 6
Source File: LoggingDeadlock.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws InterruptedException{
    Thread t1 = new Thread(new Runnable() {
        public void run() {
            randomDelay();
            // Trigger Logger.<clinit>
            Logger.getAnonymousLogger();
        }
    });

    Thread t2 = new Thread(new Runnable() {
        public void run() {
            randomDelay();
            // Trigger LogManager.<clinit>
            LogManager.getLogManager();
        }
    });

    t1.start();
    t2.start();

    t1.join();
    t2.join();
    System.out.println("\nTest passed");
}
 
Example 7
Source File: LoggingDeadlock.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws InterruptedException{
    Thread t1 = new Thread(new Runnable() {
        public void run() {
            randomDelay();
            // Trigger Logger.<clinit>
            Logger.getAnonymousLogger();
        }
    });

    Thread t2 = new Thread(new Runnable() {
        public void run() {
            randomDelay();
            // Trigger LogManager.<clinit>
            LogManager.getLogManager();
        }
    });

    t1.start();
    t2.start();

    t1.join();
    t2.join();
    System.out.println("\nTest passed");
}
 
Example 8
Source File: TestAppletLoggerContext.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void testOne() {
    for (int i=0; i<3 ; i++) {
        Logger logger1 = Logger.getAnonymousLogger();
        Logger logger1b = Logger.getAnonymousLogger();
        Bridge.changeContext();
        Logger logger2 = Logger.getAnonymousLogger();
        Logger logger2b = Logger.getAnonymousLogger();
        Bridge.changeContext();
        Logger logger3 = new Bridge.CustomAnonymousLogger();
        Logger logger3b = new Bridge.CustomAnonymousLogger();
        Bridge.changeContext();
        Logger logger4 = new Bridge.CustomAnonymousLogger();
        Logger logger4b = new Bridge.CustomAnonymousLogger();
    }
}
 
Example 9
Source File: SimpleLogHandlerTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Test
public void getLoggerFilePath_onMissingLogHandler_fails() throws Exception {
  HandlerQuerier handlerQuerier = new HandlerQuerier();
  Logger logger = Logger.getAnonymousLogger();

  assertThrows(IOException.class, () -> handlerQuerier.getLoggerFilePath(logger));
}
 
Example 10
Source File: EngineLoggerTest.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void run( )
{
	try
	{
		FileHandler handler = new FileHandler( logFile );
		try
		{
			Logger logger = Logger.getAnonymousLogger( );
			logger.addHandler( handler );
			logger.setLevel( logLevel );
			logger.setUseParentHandlers( false );
			EngineLogger.setThreadLogger( logger );
			try
			{
				log( );
			}
			finally
			{
				EngineLogger.setThreadLogger( null );
			}
		}
		finally
		{
			handler.close( );
			count.decrementAndGet( );
			synchronized ( count )
			{
				count.notify( );
			}
		}
	}
	catch ( IOException ex )
	{
		ex.printStackTrace( );
	}
}
 
Example 11
Source File: SarlScriptExecutor.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
public CompiledFile compile(int lineno, String code, List<String> issues, ICompilatedResourceReceiver receiver) throws Exception {
	File rootFolder = createRootFolder();
	File sourceFolder = createSourceFolder(rootFolder);
	File genFolder = createGenFolder(rootFolder);
	File binFolder = createBinFolder(rootFolder);
	final SarlBatchCompiler compiler = this.compilerProvider.get();
	compiler.setBasePath(rootFolder.getAbsolutePath());
	compiler.addSourcePath(sourceFolder);
	compiler.setClassOutputPath(binFolder);
	compiler.setOutputPath(genFolder);
	compiler.setGenerateGeneratedAnnotation(false);
	compiler.setGenerateInlineAnnotation(false);
	compiler.setGenerateSyntheticSuppressWarnings(true);
	compiler.setCleaningPolicy(CleaningPolicy.NO_CLEANING);
	compiler.setClassPath(this.classpath);
	compiler.setBootClassPath(this.bootClasspath);
	compiler.setJavaSourceVersion(this.sourceVersion);
	compiler.setAllWarningSeverities(Severity.IGNORE);
	compiler.setWarningSeverity(IssueCodes.DEPRECATED_MEMBER_REFERENCE, Severity.ERROR);
	compiler.setJavaCompilerVerbose(false);
	final Logger nopLogger = Logger.getAnonymousLogger();
	nopLogger.setLevel(Level.OFF);
	compiler.setLogger(nopLogger);
	if (issues != null) {
		compiler.addIssueMessageListener((issue, uri, message) -> {
			if (issue.isSyntaxError() || issue.getSeverity() == Severity.ERROR) {
				final Integer line = issue.getLineNumber();
				final int issueLine = (line == null ? 0 : line.intValue()) + lineno;
				issues.add(MessageFormat.format(Messages.SarlScriptExecutor_1, message, issueLine));
			}
		});
	}
	if (receiver != null) {
		compiler.addCompiledResourceReceiver(receiver);
	}
	File file = createFile(sourceFolder, code);
	compiler.compile();
	return new CompiledFile(rootFolder, file);
}
 
Example 12
Source File: TestAppletLoggerContext.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void testOne() {
    for (int i=0; i<3 ; i++) {
        Logger logger1 = Logger.getAnonymousLogger();
        Logger logger1b = Logger.getAnonymousLogger();
        Bridge.changeContext();
        Logger logger2 = Logger.getAnonymousLogger();
        Logger logger2b = Logger.getAnonymousLogger();
        Bridge.changeContext();
        Logger logger3 = new Bridge.CustomAnonymousLogger();
        Logger logger3b = new Bridge.CustomAnonymousLogger();
        Bridge.changeContext();
        Logger logger4 = new Bridge.CustomAnonymousLogger();
        Logger logger4b = new Bridge.CustomAnonymousLogger();
    }
}
 
Example 13
Source File: ThunderbirdMailStorageTest.java    From mail-importer with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  MockitoAnnotations.initMocks(this);

  mailStorage = new ThunderbirdMailStorage(
      Logger.getAnonymousLogger(),
      rootFolder,
      new XMozillaStatusParser());
}
 
Example 14
Source File: TestAppletLoggerContext.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void testOne() {
    for (int i=0; i<3 ; i++) {
        Logger logger1 = Logger.getAnonymousLogger();
        Logger logger1b = Logger.getAnonymousLogger();
        Bridge.changeContext();
        Logger logger2 = Logger.getAnonymousLogger();
        Logger logger2b = Logger.getAnonymousLogger();
        Bridge.changeContext();
        Logger logger3 = new Bridge.CustomAnonymousLogger();
        Logger logger3b = new Bridge.CustomAnonymousLogger();
        Bridge.changeContext();
        Logger logger4 = new Bridge.CustomAnonymousLogger();
        Logger logger4b = new Bridge.CustomAnonymousLogger();
    }
}
 
Example 15
Source File: FileHandlerQuerierTest.java    From bazel with Apache License 2.0 4 votes vote down vote up
private Logger getLoggerWithFileHandler(FileHandler handler) {
  Logger logger = Logger.getAnonymousLogger();
  logger.addHandler(handler);
  return logger;
}
 
Example 16
Source File: TestAnonymousLogger.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    System.setSecurityManager(new SecurityManager());
    Logger anonymous = Logger.getAnonymousLogger();

    final TestHandler handler = new TestHandler();
    final TestFilter filter = new TestFilter();
    final ResourceBundle bundle = ResourceBundle.getBundle(TestBundle.class.getName());
    anonymous.setLevel(Level.FINEST);
    anonymous.addHandler(handler);
    anonymous.setFilter(filter);
    anonymous.setUseParentHandlers(true);
    anonymous.setResourceBundle(bundle);

    if (anonymous.getLevel() != Level.FINEST) {
        throw new RuntimeException("Unexpected level: " + anonymous.getLevel());
    } else {
        System.out.println("Got expected level: " + anonymous.getLevel());
    }
    if (!Arrays.asList(anonymous.getHandlers()).contains(handler)) {
        throw new RuntimeException("Expected handler not found in: "
                + Arrays.asList(anonymous.getHandlers()));
    } else {
        System.out.println("Got expected handler in: " + Arrays.asList(anonymous.getHandlers()));
    }
    if (anonymous.getFilter() != filter) {
        throw new RuntimeException("Unexpected filter: " + anonymous.getFilter());
    } else {
        System.out.println("Got expected filter: " + anonymous.getFilter());
    }
    if (!anonymous.getUseParentHandlers()) {
        throw new RuntimeException("Unexpected flag: " + anonymous.getUseParentHandlers());
    } else {
        System.out.println("Got expected flag: " + anonymous.getUseParentHandlers());
    }
    if (anonymous.getResourceBundle() != bundle) {
        throw new RuntimeException("Unexpected bundle: " + anonymous.getResourceBundle());
    } else {
        System.out.println("Got expected bundle: " + anonymous.getResourceBundle());
    }
    try {
        anonymous.setParent(Logger.getLogger("foo.bar"));
        throw new RuntimeException("Expected SecurityException not raised!");
    } catch (SecurityException x) {
        System.out.println("Got expected exception: " + x);
    }
    if (anonymous.getParent() != Logger.getLogger("")) {
        throw new RuntimeException("Unexpected parent: " + anonymous.getParent());
    } else {
        System.out.println("Got expected parent: " + anonymous.getParent());
    }
}
 
Example 17
Source File: TestAnonymousLogger.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    System.setSecurityManager(new SecurityManager());
    Logger anonymous = Logger.getAnonymousLogger();

    final TestHandler handler = new TestHandler();
    final TestFilter filter = new TestFilter();
    final ResourceBundle bundle = ResourceBundle.getBundle(TestBundle.class.getName());
    anonymous.setLevel(Level.FINEST);
    anonymous.addHandler(handler);
    anonymous.setFilter(filter);
    anonymous.setUseParentHandlers(true);
    anonymous.setResourceBundle(bundle);

    if (anonymous.getLevel() != Level.FINEST) {
        throw new RuntimeException("Unexpected level: " + anonymous.getLevel());
    } else {
        System.out.println("Got expected level: " + anonymous.getLevel());
    }
    if (!Arrays.asList(anonymous.getHandlers()).contains(handler)) {
        throw new RuntimeException("Expected handler not found in: "
                + Arrays.asList(anonymous.getHandlers()));
    } else {
        System.out.println("Got expected handler in: " + Arrays.asList(anonymous.getHandlers()));
    }
    if (anonymous.getFilter() != filter) {
        throw new RuntimeException("Unexpected filter: " + anonymous.getFilter());
    } else {
        System.out.println("Got expected filter: " + anonymous.getFilter());
    }
    if (!anonymous.getUseParentHandlers()) {
        throw new RuntimeException("Unexpected flag: " + anonymous.getUseParentHandlers());
    } else {
        System.out.println("Got expected flag: " + anonymous.getUseParentHandlers());
    }
    if (anonymous.getResourceBundle() != bundle) {
        throw new RuntimeException("Unexpected bundle: " + anonymous.getResourceBundle());
    } else {
        System.out.println("Got expected bundle: " + anonymous.getResourceBundle());
    }
    try {
        anonymous.setParent(Logger.getLogger("foo.bar"));
        throw new RuntimeException("Expected SecurityException not raised!");
    } catch (SecurityException x) {
        System.out.println("Got expected exception: " + x);
    }
    if (anonymous.getParent() != Logger.getLogger("")) {
        throw new RuntimeException("Unexpected parent: " + anonymous.getParent());
    } else {
        System.out.println("Got expected parent: " + anonymous.getParent());
    }
}
 
Example 18
Source File: LoadItUp1.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public Logger getAnonymousLogger(String rbName) throws Exception {
    // we should not be able to find the resource in this directory via
    // getLogger calls.  The only way that would be possible given this setup
    // is that if Logger.getLogger searched up the call stack
    return Logger.getAnonymousLogger(rbName);
}
 
Example 19
Source File: TestAnonymousLogger.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    System.setSecurityManager(new SecurityManager());
    Logger anonymous = Logger.getAnonymousLogger();

    final TestHandler handler = new TestHandler();
    final TestFilter filter = new TestFilter();
    final ResourceBundle bundle = ResourceBundle.getBundle(TestBundle.class.getName());
    anonymous.setLevel(Level.FINEST);
    anonymous.addHandler(handler);
    anonymous.setFilter(filter);
    anonymous.setUseParentHandlers(true);
    anonymous.setResourceBundle(bundle);

    if (anonymous.getLevel() != Level.FINEST) {
        throw new RuntimeException("Unexpected level: " + anonymous.getLevel());
    } else {
        System.out.println("Got expected level: " + anonymous.getLevel());
    }
    if (!Arrays.asList(anonymous.getHandlers()).contains(handler)) {
        throw new RuntimeException("Expected handler not found in: "
                + Arrays.asList(anonymous.getHandlers()));
    } else {
        System.out.println("Got expected handler in: " + Arrays.asList(anonymous.getHandlers()));
    }
    if (anonymous.getFilter() != filter) {
        throw new RuntimeException("Unexpected filter: " + anonymous.getFilter());
    } else {
        System.out.println("Got expected filter: " + anonymous.getFilter());
    }
    if (!anonymous.getUseParentHandlers()) {
        throw new RuntimeException("Unexpected flag: " + anonymous.getUseParentHandlers());
    } else {
        System.out.println("Got expected flag: " + anonymous.getUseParentHandlers());
    }
    if (anonymous.getResourceBundle() != bundle) {
        throw new RuntimeException("Unexpected bundle: " + anonymous.getResourceBundle());
    } else {
        System.out.println("Got expected bundle: " + anonymous.getResourceBundle());
    }
    try {
        anonymous.setParent(Logger.getLogger("foo.bar"));
        throw new RuntimeException("Expected SecurityException not raised!");
    } catch (SecurityException x) {
        System.out.println("Got expected exception: " + x);
    }
    if (anonymous.getParent() != Logger.getLogger("")) {
        throw new RuntimeException("Unexpected parent: " + anonymous.getParent());
    } else {
        System.out.println("Got expected parent: " + anonymous.getParent());
    }
}
 
Example 20
Source File: LoadItUp1.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public Logger getAnonymousLogger(String rbName) throws Exception {
    // we should not be able to find the resource in this directory via
    // getLogger calls.  The only way that would be possible given this setup
    // is that if Logger.getLogger searched up the call stack
    return Logger.getAnonymousLogger(rbName);
}