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

The following examples show how to use java.util.logging.Logger#getAnonymousLogger() . These examples are extracted from open source projects. 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 Project: GLEXP-Team-onebillion   File: OBUtils.java    License: 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
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
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
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
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
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
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 Project: sarl   File: SarlScriptExecutor.java    License: 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 9
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 10
@Before
public void setUp() throws Exception {
  MockitoAnnotations.initMocks(this);

  mailStorage = new ThunderbirdMailStorage(
      Logger.getAnonymousLogger(),
      rootFolder,
      new XMozillaStatusParser());
}
 
Example 11
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 12
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 Project: birt   File: EngineLoggerTest.java    License: 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 14
Source Project: bazel   File: SimpleLogHandlerTest.java    License: 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 15
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 16
Source Project: hottub   File: LoadItUp1.java    License: 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 17
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 Project: bazel   File: FileHandlerQuerierTest.java    License: 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 19
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
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());
    }
}