Java 类java.util.logging.ConsoleHandler 实例源码

项目:Dist_HW_2    文件:Server.java   
public Server(String fileName, boolean restart) {
    super();
    parseServerFile(fileName);
    seatAssignments = new ArrayList<>(nSeats);
    for (int i = 0; i < nSeats; i++)
        seatAssignments.add("");

    log.getParent().removeHandler(log.getParent().getHandlers()[0]);

    try {
        // check if logs dir exists
        File logDir = new File("./logs/"); 
        if( !(logDir.exists()) )
            logDir.mkdir();

        FileHandler fh = new FileHandler("logs/server_log_" + serverID + ".log");
        fh.setFormatter(new SimpleFormatter());
        fh.setLevel(logLevel);
        log.addHandler(fh);

        ConsoleHandler ch = new ConsoleHandler();
        ch.setLevel(logLevel);
        log.addHandler(ch);
        log.setLevel(logLevel);

        log.info("Server initializing...");
        log.info("ServerID = " + serverID);
        log.info("nServers = " + nServers);
        log.info("nSeats = " + nSeats);
        log.info("my tcp port = " + tcpPort);
        for (int i = 0; i < nServers; i++)
            log.info("Server " + i + ": " + servers.get(i) + ":" + ports.get(i));
        log.info("Server init complete");
        log.info("--------------------------------");
        mutex = new LamportMutex(servers, ports, this, restart);
        mutex.init();
    } catch (SecurityException | IOException e) {
        e.printStackTrace();
    }
}
项目:majordodo    文件:RestartBrokerAndStartWorkerTest.java   
@Before
public void setupLogger() throws Exception {
    Level level = Level.INFO;
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread t, Throwable e) {
            System.err.println("uncaughtException from thread " + t.getName() + ": " + e);
            e.printStackTrace();
        }
    });
    java.util.logging.LogManager.getLogManager().reset();
    ConsoleHandler ch = new ConsoleHandler();
    ch.setLevel(level);
    SimpleFormatter f = new SimpleFormatter();
    ch.setFormatter(f);
    java.util.logging.Logger.getLogger("").setLevel(level);
    java.util.logging.Logger.getLogger("").addHandler(ch);
}
项目:incubator-netbeans    文件:TopLoggingNbLoggerConsoleTest.java   
private void doDeadlockConsoleAndStdErr(final ConsoleHandler ch) {
    class H extends Handler implements Runnable {
        public void publish(LogRecord record) {
            try {
                RequestProcessor.getDefault().post(this).waitFinished(100);
            } catch (InterruptedException ex) {
                // ex.printStackTrace();
            }
        }

        public void flush() {
        }

        public void close() throws SecurityException {
        }

        public void run() {
            ch.publish(new LogRecord(Level.WARNING, "run"));
        }
    }
    H handler = new H();
    Logger.getLogger("stderr").addHandler(handler);

    System.err.println("Ahoj");
}
项目:scorekeeperfrontend    文件:AppSetup.java   
public static void unitLogging()
{
    // Start with a fresh root set at warning
    Logger root = LogManager.getLogManager().getLogger("");
    root.setLevel(Level.WARNING);
    for(Handler handler : root.getHandlers()) { root.removeHandler(handler); }

    //Logger.getLogger("java.util.prefs").setLevel(Level.SEVERE);
    Logger.getLogger("org.postgresql.jdbc").setLevel(Level.OFF);
    Logger.getLogger("org.postgresql.Driver").setLevel(Level.OFF);
    Logger.getLogger("org.wwscc").setLevel(Level.ALL);

    ConsoleHandler ch = new ConsoleHandler();
    ch.setLevel(Level.ALL);
    ch.setFormatter(new SingleLineFormatter());
    root.addHandler(ch);
}
项目:OpenCyclos    文件:LoggingHandlerImpl.java   
/**
 * Creates a new logger
 */
private Logger init(final Level level, final String file) {
    final LogSettings logSettings = settingsService.getLogSettings();
    final Logger logger = Logger.getAnonymousLogger();
    logger.setLevel(level);
    logger.setUseParentHandlers(false);
    try {
        final FileUnits units = logSettings.getMaxLengthPerFileUnits();
        final FileHandler fileHandler = new FileHandler(file, units.calculate(logSettings.getMaxLengthPerFile()), logSettings.getMaxFilesPerLog(), true);
        fileHandler.setFormatter(logFormatter);
        fileHandler.setEncoding(settingsService.getLocalSettings().getCharset());
        logger.addHandler(fileHandler);
    } catch (final Exception e) {
        final ConsoleHandler consoleHandler = new ConsoleHandler();
        consoleHandler.setFormatter(logFormatter);
        try {
            consoleHandler.setEncoding(settingsService.getLocalSettings().getCharset());
        } catch (final Exception e1) {
            // Just ignore
        }
        logger.addHandler(consoleHandler);
        logger.log(Level.WARNING, "Unable to create logger for file " + file);
    }
    return logger;
}
项目:noa-libre    文件:OfficeBeanTest.java   
/**
 * Main entry point for the OpenOffice.org Bean Test.
 *
 * @param args arguments of the test
 *
 * @author Andreas Bröker
 * @date 21.05.2006
 */
public static void main(String[] args) throws OfficeApplicationException {

   LogManager.getLogManager().reset();
   ConsoleHandler consoleHandler = new ConsoleHandler();
   consoleHandler.setLevel(Level.FINEST);
   LOGGER.addHandler(consoleHandler);
   LOGGER.setLevel(Level.FINEST);

   try {
      FileHandler fileHandler = new FileHandler("log.xml");
      fileHandler.setLevel(Level.FINEST);
      LOGGER.addHandler(fileHandler);
   } catch (Throwable throwable) {
   }
   OfficeBeanTest testOfficeBean = new OfficeBeanTest();

   if (args.length == 0) {
      testOfficeBean.test(null);
   }else if (args.length == 1) {
      testOfficeBean.test(args[0]);
   }else if(args.length==4){
      testOfficeBean.remoteTestPDF(new File(args[2]), new File(args[3]), args[0], Integer.valueOf(args[1]));
   }else{
      System.out.println("usage:\nOfficeBeanTest host port source-odt target-pdf\nOfficeBeanTest officeHome");
   }
}
项目:blazingcache    文件:JSRExamplesTest.java   
@Before
public void setupLogger() throws Exception {
    Level level = Level.SEVERE;
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread t, Throwable e) {
            System.err.println("uncaughtException from thread " + t.getName() + ": " + e);
            e.printStackTrace();
        }
    });
    java.util.logging.LogManager.getLogManager().reset();
    ConsoleHandler ch = new ConsoleHandler();
    ch.setLevel(level);
    SimpleFormatter f = new SimpleFormatter();
    ch.setFormatter(f);
    java.util.logging.Logger.getLogger("").setLevel(level);
    java.util.logging.Logger.getLogger("").addHandler(ch);
}
项目:majordodo    文件:KerberosSimpleBrokerStatusReplicationTest.java   
@Before
public void setupLogger() throws Exception {
    Level level = Level.SEVERE;
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread t, Throwable e) {
            System.err.println("uncaughtException from thread " + t.getName() + ": " + e);
            e.printStackTrace();
        }
    });
    java.util.logging.LogManager.getLogManager().reset();
    ConsoleHandler ch = new ConsoleHandler();
    ch.setLevel(level);
    SimpleFormatter f = new SimpleFormatter();
    ch.setFormatter(f);
    java.util.logging.Logger.getLogger("").setLevel(level);
    java.util.logging.Logger.getLogger("").addHandler(ch);
}
项目:majordodo    文件:BrokerStatusReplicationWithLedgerDeletionTest.java   
@Before
public void setupLogger() throws Exception {
    Level level = Level.SEVERE;
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread t, Throwable e) {
            System.err.println("uncaughtException from thread " + t.getName() + ": " + e);
            e.printStackTrace();
        }
    });
    java.util.logging.LogManager.getLogManager().reset();
    ConsoleHandler ch = new ConsoleHandler();
    ch.setLevel(level);
    SimpleFormatter f = new SimpleFormatter();
    ch.setFormatter(f);
    java.util.logging.Logger.getLogger("").setLevel(level);
    java.util.logging.Logger.getLogger("").addHandler(ch);
}
项目:majordodo    文件:SimpleBrokerStatusReplicationKerberosTest.java   
@Before
public void setupLogger() throws Exception {
    Level level = Level.SEVERE;
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread t, Throwable e) {
            System.err.println("uncaughtException from thread " + t.getName() + ": " + e);
            e.printStackTrace();
        }
    });
    java.util.logging.LogManager.getLogManager().reset();
    ConsoleHandler ch = new ConsoleHandler();
    ch.setLevel(level);
    SimpleFormatter f = new SimpleFormatter();
    ch.setFormatter(f);
    java.util.logging.Logger.getLogger("").setLevel(level);
    java.util.logging.Logger.getLogger("").addHandler(ch);
}
项目:majordodo    文件:AcquireLeadershipTest.java   
@Before
public void setupLogger() throws Exception {
    Level level = Level.SEVERE;
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread t, Throwable e) {
            System.err.println("uncaughtException from thread " + t.getName() + ": " + e);
            e.printStackTrace();
        }
    });
    java.util.logging.LogManager.getLogManager().reset();
    ConsoleHandler ch = new ConsoleHandler();
    ch.setLevel(level);
    SimpleFormatter f = new SimpleFormatter();
    ch.setFormatter(f);
    java.util.logging.Logger.getLogger("").setLevel(level);
    java.util.logging.Logger.getLogger("").addHandler(ch);
}
项目:majordodo    文件:SimpleCodePoolTest.java   
@Before
public void setupLogger() throws Exception {
    Level level = Level.INFO;
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread t, Throwable e) {
            System.err.println("uncaughtException from thread " + t.getName() + ": " + e);
            e.printStackTrace();
        }
    });
    java.util.logging.LogManager.getLogManager().reset();
    ConsoleHandler ch = new ConsoleHandler();
    ch.setLevel(level);
    SimpleFormatter f = new SimpleFormatter();
    ch.setFormatter(f);
    java.util.logging.Logger.getLogger("").setLevel(level);
    java.util.logging.Logger.getLogger("").addHandler(ch);
}
项目:majordodo    文件:HttpClientLeaderRecoveryTest.java   
@Before
public void setupLogger() throws Exception {
    Level level = Level.SEVERE;
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread t, Throwable e) {
            System.err.println("uncaughtException from thread " + t.getName() + ": " + e);
            e.printStackTrace();
        }
    });
    java.util.logging.LogManager.getLogManager().reset();
    ConsoleHandler ch = new ConsoleHandler();
    ch.setLevel(level);
    SimpleFormatter f = new SimpleFormatter();
    ch.setFormatter(f);
    java.util.logging.Logger.getLogger("").setLevel(level);
    java.util.logging.Logger.getLogger("").addHandler(ch);
}
项目:majordodo    文件:SlotsReleaseTest.java   
@Before
public void setupLogger() throws Exception {
    Level level = Level.INFO;
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread t, Throwable e) {
            System.err.println("uncaughtException from thread " + t.getName() + ": " + e);
            e.printStackTrace();
        }
    });
    java.util.logging.LogManager.getLogManager().reset();
    ConsoleHandler ch = new ConsoleHandler();
    ch.setLevel(level);
    SimpleFormatter f = new SimpleFormatter();
    ch.setFormatter(f);
    java.util.logging.Logger.getLogger("").setLevel(level);
    java.util.logging.Logger.getLogger("").addHandler(ch);
}
项目:majordodo    文件:ExpireMultipleTasksTest.java   
@Before
public void setupLogger() throws Exception {
    Level level = Level.INFO;
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread t, Throwable e) {
            System.err.println("uncaughtException from thread " + t.getName() + ": " + e);
            e.printStackTrace();
        }
    });
    java.util.logging.LogManager.getLogManager().reset();
    ConsoleHandler ch = new ConsoleHandler();
    ch.setLevel(level);
    SimpleFormatter f = new SimpleFormatter();
    ch.setFormatter(f);
    java.util.logging.Logger.getLogger("").setLevel(level);
    java.util.logging.Logger.getLogger("").addHandler(ch);
}
项目:majordodo    文件:TaskDeadlineWithoutRequestTest.java   
@Before
public void setupLogger() throws Exception {
    Level level = Level.INFO;
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread t, Throwable e) {
            System.err.println("uncaughtException from thread " + t.getName() + ": " + e);
            e.printStackTrace();
        }
    });
    java.util.logging.LogManager.getLogManager().reset();
    ConsoleHandler ch = new ConsoleHandler();
    ch.setLevel(level);
    SimpleFormatter f = new SimpleFormatter();
    ch.setFormatter(f);
    java.util.logging.Logger.getLogger("").setLevel(level);
    java.util.logging.Logger.getLogger("").addHandler(ch);
}
项目:majordodo    文件:TaskExecutionRecoveryOnErrorTest.java   
@Before
public void setupLogger() throws Exception {
    Level level = Level.INFO;
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread t, Throwable e) {
            System.err.println("uncaughtException from thread " + t.getName() + ": " + e);
            e.printStackTrace();
        }
    });
    java.util.logging.LogManager.getLogManager().reset();
    ConsoleHandler ch = new ConsoleHandler();
    ch.setLevel(level);
    SimpleFormatter f = new SimpleFormatter();
    ch.setFormatter(f);
    java.util.logging.Logger.getLogger("").setLevel(level);
    java.util.logging.Logger.getLogger("").addHandler(ch);
}
项目:majordodo    文件:MaxTasksPerUserTest.java   
@Before
public void setupLogger() throws Exception {
    Level level = Level.INFO;
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread t, Throwable e) {
            System.err.println("uncaughtException from thread " + t.getName() + ": " + e);
            e.printStackTrace();
        }
    });
    java.util.logging.LogManager.getLogManager().reset();
    ConsoleHandler ch = new ConsoleHandler();
    ch.setLevel(level);
    SimpleFormatter f = new SimpleFormatter();
    ch.setFormatter(f);
    java.util.logging.Logger.getLogger("").setLevel(level);
    java.util.logging.Logger.getLogger("").addHandler(ch);
}
项目:majordodo    文件:TaskExecutionSendAgainFinishedNotificationTest.java   
@Before
public void setupLogger() throws Exception {
    Level level = Level.INFO;
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread t, Throwable e) {
            System.err.println("uncaughtException from thread " + t.getName() + ": " + e);
            e.printStackTrace();
        }
    });
    java.util.logging.LogManager.getLogManager().reset();
    ConsoleHandler ch = new ConsoleHandler();
    ch.setLevel(level);
    SimpleFormatter f = new SimpleFormatter();
    ch.setFormatter(f);
    java.util.logging.Logger.getLogger("").setLevel(level);
    java.util.logging.Logger.getLogger("").addHandler(ch);
}
项目:j2objc    文件:ConsoleHandlerTest.java   
public void testConstructor_InvalidProperties() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.ConsoleHandler.level", INVALID_LEVEL);
    p.put("java.util.logging.ConsoleHandler.filter", className);
    p.put("java.util.logging.ConsoleHandler.formatter", className);
    p.put("java.util.logging.ConsoleHandler.encoding", "XXXX");
    LogManager.getLogManager().readConfiguration(
            EnvironmentHelper.PropertiesToInputStream(p));

    assertEquals(LogManager.getLogManager().getProperty(
            "java.util.logging.ConsoleHandler.level"), INVALID_LEVEL);
    assertEquals(LogManager.getLogManager().getProperty(
            "java.util.logging.ConsoleHandler.encoding"), "XXXX");
    ConsoleHandler h = new ConsoleHandler();
    assertSame(h.getLevel(), Level.INFO);
    assertTrue(h.getFormatter() instanceof SimpleFormatter);
    assertNull(h.getFilter());
    assertNull(h.getEncoding());
    h.publish(new LogRecord(Level.SEVERE, "test"));
    assertNull(h.getEncoding());
}
项目:j2objc    文件:ConsoleHandlerTest.java   
public void testPublish_AfterResetSystemErr() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.ConsoleHandler.formatter", className
            + "$MockFormatter");
    LogManager.getLogManager().readConfiguration(
            EnvironmentHelper.PropertiesToInputStream(p));
    ConsoleHandler h = new ConsoleHandler();
    h.setFilter(new MockFilter());

    System.setErr(new PrintStream(new ByteArrayOutputStream()));

    LogRecord r = new LogRecord(Level.INFO, "testPublish_WithFilter");
    h.setLevel(Level.INFO);
    h.publish(r);
    assertNull(CallVerificationStack.getInstance().pop());
    assertSame(r, CallVerificationStack.getInstance().pop());
    assertEquals("", this.errSubstituteStream.toString());
}
项目:Ogar2-Server    文件:OgarServer.java   
private void setupLogging() {
    log.setUseParentHandlers(false);

    LogFormatter formatter = new LogFormatter();

    ConsoleHandler ch = new ConsoleHandler();
    ch.setFormatter(formatter);
    if (isDebugging()) {
        log.setLevel(Level.FINEST);
        ch.setLevel(Level.FINEST);
    } else {
        log.setLevel(Level.INFO);
        ch.setLevel(Level.INFO);
    }
    log.addHandler(ch);

    try {
        FileHandler fh = new FileHandler("server.log");
        fh.setFormatter(formatter);
        if (isDebugging()) {
            fh.setLevel(Level.FINEST);
        } else {
            ch.setLevel(Level.INFO);
        }
        log.addHandler(fh);
    } catch (IOException ex) {
        log.log(Level.SEVERE, "Error while adding FileHandler to logger. Logs will not be output to a file.", ex);
    }

}
项目:Reer    文件:JULRedirector.java   
@Override
public StandardOutputCapture start() {
    super.start();
    boolean shouldReadLoggingConfigFile = System.getProperty(READ_LOGGING_CONFIG_FILE_PROPERTY, "true").equals("true");
    if (!shouldReadLoggingConfigFile) {
        SingleMessageLogger.nagUserOfDiscontinuedProperty(READ_LOGGING_CONFIG_FILE_PROPERTY,
            "Change your test to work with your java.util.logging configuration file settings.");
    }
    if (!reset) {
        LogManager.getLogManager().reset();
        if (shouldReadLoggingConfigFile) {
            try {
                LogManager.getLogManager().readConfiguration();
            } catch (IOException error) {
                Logger.getLogger("").addHandler(new ConsoleHandler());
            }
        } else {
            Logger.getLogger("").addHandler(new ConsoleHandler());
        }
        reset = true;
    }
    return this;
}
项目:GitHub    文件:Main.java   
private static void enableHttp2FrameLogging() {
  frameLogger = Logger.getLogger(Http2.class.getName());
  frameLogger.setLevel(Level.FINE);
  ConsoleHandler handler = new ConsoleHandler();
  handler.setLevel(Level.FINE);
  handler.setFormatter(new SimpleFormatter() {
    @Override public String format(LogRecord record) {
      return Util.format("%s%n", record.getMessage());
    }
  });
  frameLogger.addHandler(handler);
}
项目:GitHub    文件:Main.java   
private static void enableHttp2FrameLogging() {
  frameLogger = Logger.getLogger(Http2.class.getName());
  frameLogger.setLevel(Level.FINE);
  ConsoleHandler handler = new ConsoleHandler();
  handler.setLevel(Level.FINE);
  handler.setFormatter(new SimpleFormatter() {
    @Override public String format(LogRecord record) {
      return Util.format("%s%n", record.getMessage());
    }
  });
  frameLogger.addHandler(handler);
}
项目:launcher-backend    文件:LoggingConfig.java   
public LoggingConfig() {
    try {
        // Load a properties file from class path java.util.logging.config.file
        final LogManager logManager = LogManager.getLogManager();
        URL configURL = getClass().getResource("/logging.properties");
        if (configURL != null) {
            try (InputStream is = configURL.openStream()) {
                logManager.readConfiguration(is);
            }
        } else {
            // Programmatic configuration
            System.setProperty("java.util.logging.SimpleFormatter.format",
                               "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%1$tL %4$-7s [%3$s] %5$s %6$s%n");

            final ConsoleHandler consoleHandler = new ConsoleHandler();
            consoleHandler.setLevel(Level.FINEST);
            consoleHandler.setFormatter(new SimpleFormatter());

            final Logger app = Logger.getLogger("app");
            app.setLevel(Level.FINEST);
            app.addHandler(consoleHandler);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:Pogamut3    文件:ServerRunner.java   
/**
 * Constructor.
 */
public ServerRunner() {
    log.setLevel(Level.ALL); 
    ConsoleHandler handler = new ConsoleHandler();
    handler.setFormatter(new SimpleFormatter());
    handler.setLevel(Level.ALL);
    log.addHandler(handler);

}
项目:Pogamut3    文件:Test00_SingleMultiWVTest.java   
public void setUp()
{
    agentId = new TeamedAgentId("Agent01");
    agentId.setTeamId( new TeamId("teamRED"));
    agentLogger = new AgentLogger(agentId);
    LifecycleBus bus = new LifecycleBus(agentLogger);

    Logger sharedLogger = Logger.getLogger("SharedLogger");
    sharedLogger.addHandler( new ConsoleHandler() );
    sharedLogger.setLevel( Level.INFO );
    agentLogger.setLevel(Level.INFO);
    agentLogger.addDefaultConsoleHandler();

    sharedWV = new EventDrivenSharedWorldViewStub( sharedLogger );

    ComponentStub starter = new ComponentStub(agentLogger, bus);

    localWV = new EventDrivenLocalWorldViewStub( new ComponentDependencies( ComponentDependencyType.STARTS_WITH ).add(starter), bus, agentLogger, sharedWV, agentId);

    starter.getController().manualStart("TEST");
    localWV.setCurrentTime( TimeKey.get(0));
}
项目:Pogamut3    文件:Test01_SharedWorldViewMultiAgent.java   
public static void createShared()
{
    globalLogger = Logger.getLogger("globalLogger");
    ConsoleHandler handler = new ConsoleHandler();
    globalLogger.addHandler(handler);
    handler.setLevel(Level.INFO);
    //LogFormatter formatter = new LogFormatter();
    //handler.setFormatter(formatter);
    globalLogger.setLevel( Level.INFO );
    sharedWV = new EventDrivenSharedWorldViewStub(globalLogger);
}
项目:bitbox    文件:Main.java   
public static void main(String[] args) {
    Logger log = Logger.getGlobal();
    ConsoleHandler handler = new ConsoleHandler();
    handler.setLevel(Level.ALL);
    log.addHandler(handler);
    log.setLevel(Level.ALL);
    JFrame fra = new JFrame("bitbox");
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    BaseConverter baseConverter = new BaseConverter();
    BitCombiner bitCombiner = new BitCombiner();
    BitPainter bitPainter = new BitPainter();
    SwingUtilities.invokeLater(() -> {
        fra.setSize(new Dimension(500, screenSize.height));
        fra.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        fra.setLayout(new GridLayout(GRID_SIZE, GRID_SIZE));
        fra.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
        fra.add(baseConverter);
        fra.add(bitCombiner);
        fra.add(bitPainter);
        fra.setVisible(true);
        log.fine("Created GUI");
    });
}
项目:Racter    文件:Log.java   
/**
 * Configure Logger
 *
 * @throws IOException
 */
protected void config() throws IOException
{
    if( Boolean.parseBoolean(this.config.get("log_console_status", "false")) ){
        consoleHandler = new ConsoleHandler();
        log.addHandler(consoleHandler);
        if( this.config.get("log_console_level", "SEVERE").equals("ALL") ){
            consoleHandler.setLevel(Level.ALL);
        }else if( this.config.get("log_console_level", "SEVERE").equals("CONFIG") ){
            consoleHandler.setLevel(Level.CONFIG);
        }else if( this.config.get("log_console_level", "SEVERE").equals("FINE") ){
            consoleHandler.setLevel(Level.FINE);
        }else if( this.config.get("log_console_level", "SEVERE").equals("FINER") ){
            consoleHandler.setLevel(Level.FINER);
        }else if( this.config.get("log_console_level", "SEVERE").equals("FINEST") ){
            consoleHandler.setLevel(Level.FINEST);
        }else if( this.config.get("log_console_level", "SEVERE").equals("INFO") ){
            consoleHandler.setLevel(Level.INFO);
        }else if( this.config.get("log_console_level", "SEVERE").equals("OFF") ){
            consoleHandler.setLevel(Level.OFF);
        }else if( this.config.get("log_console_level", "SEVERE").equals("SEVERE") ){
            consoleHandler.setLevel(Level.SEVERE);
        }else if( this.config.get("log_console_level", "SEVERE").equals("WARNING") ){
            consoleHandler.setLevel(Level.WARNING);
        }
    }

    if( Boolean.parseBoolean(this.config.get("log_file_status", "false")) ){
        fileHandler  = new FileHandler(this.config.get("log_file_path", "src/main/java/resources/app.log"),
            Integer.parseInt(this.config.get("log_file_limit", "1")),
            Integer.parseInt(this.config.get("log_file_count", "200000")),
            Boolean.parseBoolean(this.config.get("log_file_append", "true"))
        );
        log.addHandler(fileHandler);
        if( this.config.get("log_file_level", "SEVERE").equals("ALL") ){
            fileHandler.setLevel(Level.ALL);
        }else if( this.config.get("log_file_level", "SEVERE").equals("CONFIG") ){
            fileHandler.setLevel(Level.CONFIG);
        }else if( this.config.get("log_file_level", "SEVERE").equals("FINE") ){
            fileHandler.setLevel(Level.FINE);
        }else if( this.config.get("log_file_level", "SEVERE").equals("FINER") ){
            fileHandler.setLevel(Level.FINER);
        }else if( this.config.get("log_file_level", "SEVERE").equals("FINEST") ){
            fileHandler.setLevel(Level.FINEST);
        }else if( this.config.get("log_file_level", "SEVERE").equals("INFO") ){
            fileHandler.setLevel(Level.INFO);
        }else if( this.config.get("log_file_level", "SEVERE").equals("OFF") ){
            fileHandler.setLevel(Level.OFF);
        }else if( this.config.get("log_file_level", "SEVERE").equals("SEVERE") ){
            fileHandler.setLevel(Level.SEVERE);
        }else if( this.config.get("log_file_level", "SEVERE").equals("WARNING") ){
            fileHandler.setLevel(Level.WARNING);
        }
    }
}
项目:information-retrieval    文件:Log.java   
/**
 * Initialize the logger
 */
public static void init() {

    ConsoleHandler handler = new ConsoleHandler();
    // PUBLISH this level
    handler.setLevel(Level.FINEST);
    LOGGER.addHandler(handler);
    LOGGER.setLevel(Level.FINEST);
}
项目:JInsight    文件:TracingMetricRegistry.java   
private static Logger createMetricUpdateTracer() {
  Logger logger = Logger.getLogger(TracingMetricRegistry.class.getName() + ".metricUpdates");
  ConsoleHandler handler = new ConsoleHandler();
  handler.setFormatter(new Formatter() {
    @Override
    public String format(LogRecord record) {
      return ">>" + record.getMessage() + "\n";
    }
  });
  logger.addHandler(handler);
  logger.setUseParentHandlers(false);
  handler.setLevel(Level.ALL);
  //logger.setLevel(Level.ALL);

  return logger;
}
项目:jtsgen    文件:AbstractProcessorWithLogging.java   
@Override
    public synchronized void init(ProcessingEnvironment processingEnv) {
        super.init(processingEnv);
        final Optional<String> jtsgenLogLevel = Optional.ofNullable(processingEnv.getOptions().get("jtsgenLogLevel"));
        String packageName = AbstractProcessorWithLogging.class.getPackage().getName();
        final Logger logger = Logger.getLogger(packageName);
        if (jtsgenLogLevel.isPresent()) {
            Level level = jtsgenLogLevel
                    .map(
                            (x) -> {
                                try {
                                    return Level.parse(x.trim().toUpperCase());
                                } catch (IllegalArgumentException ex) {
                                    return Level.OFF;
                                }
                            }
                    ).orElse(Level.INFO);
            Formatter oneLineFormatter = new OneLineFormatter();
            ConsoleHandler consoleHandler = new ConsoleHandler();
            consoleHandler.setLevel(level);
            consoleHandler.setFormatter(oneLineFormatter);
            logger.setUseParentHandlers(false);
            logger.setLevel(level);

//        consoleHandler.setFormatter(oneLineFormatter);
            logger.addHandler(consoleHandler);
            LOG.log(Level.FINER,() -> String.format("LogLevel %s = %s ", packageName, level.getName()));
        } else {
            logger.setLevel(Level.OFF);
        }
    }
项目:Example.EMA.Java.SpeedGuide    文件:SpeedGuideConsumer.java   
public void setDebug(boolean debug)
{
    _debug = debug;
    _consumerClient.setDebug(debug);

    if (!debug)
    {
        final Logger parentLogger = Logger.getAnonymousLogger().getParent();

        // Disable console logger if debug mode not turned on
        for (Handler handler : parentLogger.getHandlers())
        {
            if ( handler instanceof ConsoleHandler )
                parentLogger.removeHandler(handler);
        }
    }
}
项目:monarch    文件:LogWrapper.java   
private static void addDefaultConsoleHandler(Logger logger, String errorMessage,
    String logFilePath) {
  ConsoleHandler consoleHandler = new ConsoleHandler();
  consoleHandler.setFormatter(new GemFireFormatter());
  logger.addHandler(consoleHandler);

  System.err
      .println("ERROR: Could not log to file: " + logFilePath + ". Reason: " + errorMessage);
  System.err.println("Logs will be written on Console.");
  try {
    Thread.sleep(3000); // sleep for 3 secs for the message to appear
  } catch (InterruptedException ignore) {
  }
}
项目:uavstack    文件:PLogger.java   
@Override
public void enableConsoleOut(boolean check) {

    if (check == true) {
        if (this.consoleHandler == null) {
            this.consoleHandler = new ConsoleHandler();
            this.consoleHandler.setLevel(this.level);
            this.consoleHandler.setFormatter(new DefaultLogFormatter());
        }
        log.addHandler(this.consoleHandler);
    }
    else {
        if (this.consoleHandler != null) {
            log.removeHandler(this.consoleHandler);
        }
    }
}
项目:openjdk-jdk10    文件:Security.java   
public static void initServer() throws Exception {
    String portstring = System.getProperty("port.number");
    port = portstring != null ? Integer.parseInt(portstring) : 0;
    portstring = System.getProperty("port.number1");
    proxyPort = portstring != null ? Integer.parseInt(portstring) : 0;

    Logger logger = Logger.getLogger("com.sun.net.httpserver");
    ConsoleHandler ch = new ConsoleHandler();
    logger.setLevel(Level.ALL);
    ch.setLevel(Level.ALL);
    logger.addHandler(ch);
    String root = System.getProperty ("test.src")+ "/docs";
    InetSocketAddress addr = new InetSocketAddress (port);
    s1 = HttpServer.create (addr, 0);
    if (s1 instanceof HttpsServer) {
        throw new RuntimeException ("should not be httpsserver");
    }
    HttpHandler h = new FileServerHandler (root);
    HttpContext c = s1.createContext ("/files", h);

    HttpHandler h1 = new RedirectHandler ("/redirect");
    HttpContext c1 = s1.createContext ("/redirect", h1);

    executor = Executors.newCachedThreadPool();
    s1.setExecutor (executor);
    s1.start();

    if (port == 0)
        port = s1.getAddress().getPort();
    else {
        if (s1.getAddress().getPort() != port)
            throw new RuntimeException("Error wrong port");
        System.out.println("Port was assigned by Driver");
    }
    System.out.println("HTTP server port = " + port);
    httproot = "http://127.0.0.1:" + port + "/files/";
    redirectroot = "http://127.0.0.1:" + port + "/redirect/";
    uri = new URI(httproot);
    fileuri = httproot + "foo.txt";
}
项目:Kyoko    文件:Kyoko.java   
public void start() throws LoginException, InterruptedException, RateLimitedException {
    running = true;

    // init logger
    AnsiConsole.systemInstall();
    log = Logger.getLogger("Kyoko");
    log.setUseParentHandlers(false);
    ColoredFormatter formatter = new ColoredFormatter();
    ConsoleHandler handler = new ConsoleHandler();
    handler.setFormatter(formatter);
    log.addHandler(handler);

    log.info("Kyoko v" + Constants.VERSION + " is starting...");

    i18n.loadMessages();

    JDABuilder builder = new JDABuilder(AccountType.BOT);
    if (settings.getToken() != null) {
        if (settings.getToken().equalsIgnoreCase("Change me")) {
            System.out.println("No token specified, please set it in config.json");
            System.exit(1);
        }
        builder.setToken(settings.getToken());
    }

    boolean gameEnabled = false;
    if (settings.getGame() != null && !settings.getGame().isEmpty()) {
        gameEnabled = true;
        builder.setGame(Game.of("booting..."));
    }

    builder.setAutoReconnect(true);
    builder.setBulkDeleteSplittingEnabled(false);
    builder.addEventListener(eventHandler);
    builder.setAudioEnabled(true);
    builder.setStatus(OnlineStatus.IDLE);
    jda = builder.buildBlocking();

    log.info("Invite link: " + "https://discordapp.com/oauth2/authorize?&client_id=" + jda.getSelfUser().getId() + "&scope=bot&permissions=" + Constants.PERMISSIONS);

    if (gameEnabled) {
        Thread t = new Thread(new Kyoko.BlinkThread());
        t.start();
    }

    registerCommands();
}
项目:scorekeeperfrontend    文件:AppSetup.java   
/**
 * Do some common setup for all applications at startup
 * @param name the application name used for Java logging and database logging
 */
public static void appSetup(String name)
{
    // Set our platform wide L&F 
    System.setProperty("swing.defaultlaf", "javax.swing.plaf.nimbus.NimbusLookAndFeel");
    UIDefaults defaults = UIManager.getLookAndFeelDefaults();
    defaults.put("Table.gridColor", new Color(140,140,140));
    defaults.put("Table.showGrid", true);

    // Set the program name which is used by PostgresqlDatabase to identify the app in logs
    System.setProperty("program.name", name);

    // Start with a fresh root set at warning
    Logger root = LogManager.getLogManager().getLogger("");
    Formatter format = new SingleLineFormatter();

    root.setLevel(Level.WARNING);
    for(Handler handler : root.getHandlers()) {
        root.removeHandler(handler);
    }

    // Set prefs levels before windows preference load barfs useless data on the user
    Logger.getLogger("java.util.prefs").setLevel(Level.SEVERE);
    // postgres JDBC spits out a lot of data even though we catch the exception
    Logger.getLogger("org.postgresql.jdbc").setLevel(Level.OFF);
    Logger.getLogger("org.postgresql.Driver").setLevel(Level.OFF);

    // Add console handler if running in debug mode
    if (Prefs.isDebug()) {
        ConsoleHandler ch = new ConsoleHandler();
        ch.setLevel(Level.ALL);
        ch.setFormatter(format);
        root.addHandler(ch);
    }

    // For our own logs, we can set super fine level or info depending on if debug mode and attach dialogs to those
    Logger applog = Logger.getLogger("org.wwscc");
    applog.setLevel(Prefs.isDebug() ? Level.FINEST : Level.INFO);
    applog.addHandler(new AlertHandler());

    Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(Thread t, Throwable e) {
            applog.log(Level.WARNING, String.format("\bUncaughtException in %s: %s", t, e), e);
        }});

    try {
        File logdir = Prefs.getLogDirectory().toFile();
        if (!logdir.exists())
            if (!logdir.mkdirs())
                throw new IOException("Can't create log directory " + logdir);
        FileHandler fh = new FileHandler(new File(logdir, name+".%g.log").getAbsolutePath(), 1000000, 10, true);
        fh.setFormatter(format);
        fh.setLevel(Level.ALL);
        root.addHandler(fh);
    } catch (IOException ioe) {
        JOptionPane.showMessageDialog(FocusManager.getCurrentManager().getActiveWindow(),
                "Unable to enable logging to file: " + ioe, "Log Error", JOptionPane.ERROR_MESSAGE);
    }

    // force the initialization of IdGenerator on another thread so app can start now without an odd delay later
    new Thread() {
        public void run() {
            IdGenerator.generateId();
        }
    }.start();
}