java.util.logging.SimpleFormatter Java Examples

The following examples show how to use java.util.logging.SimpleFormatter. 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: LoggingConfig.java    From launchpad-missioncontrol with Apache License 2.0 7 votes vote down vote up
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();
    }
}
 
Example #2
Source File: SerializeLogRecord.java    From dragonwell8_jdk with GNU General Public License v2.0 7 votes vote down vote up
/**
 * Deserializes the Base64 encoded string returned by {@link
 * #getBase64()}, format the obtained LogRecord using a
 * SimpleFormatter, and checks that the string representation obtained
 * matches the original string representation returned by {@link
 * #getString()}.
 */
protected void dotest() {
    try {
        final String base64 = getBase64();
        final ByteArrayInputStream bais =
                new ByteArrayInputStream(Base64.getDecoder().decode(base64));
        final ObjectInputStream ois = new ObjectInputStream(bais);
        final LogRecord record = (LogRecord)ois.readObject();
        final SimpleFormatter formatter = new SimpleFormatter();
        String expected = getString();
        String str2 = formatter.format(record);
        check(expected, str2);
        System.out.println(str2);
        System.out.println("PASSED: "+this.getClass().getName()+"\n");
    } catch (IOException | ClassNotFoundException x) {
        throw new RuntimeException(x);
    }
}
 
Example #3
Source File: SerializeLogRecord.java    From TencentKona-8 with GNU General Public License v2.0 7 votes vote down vote up
/**
 * Deserializes the Base64 encoded string returned by {@link
 * #getBase64()}, format the obtained LogRecord using a
 * SimpleFormatter, and checks that the string representation obtained
 * matches the original string representation returned by {@link
 * #getString()}.
 */
protected void dotest() {
    try {
        final String base64 = getBase64();
        final ByteArrayInputStream bais =
                new ByteArrayInputStream(Base64.getDecoder().decode(base64));
        final ObjectInputStream ois = new ObjectInputStream(bais);
        final LogRecord record = (LogRecord)ois.readObject();
        final SimpleFormatter formatter = new SimpleFormatter();
        String expected = getString();
        String str2 = formatter.format(record);
        check(expected, str2);
        System.out.println(str2);
        System.out.println("PASSED: "+this.getClass().getName()+"\n");
    } catch (IOException | ClassNotFoundException x) {
        throw new RuntimeException(x);
    }
}
 
Example #4
Source File: QueryEventListener.java    From emr-presto-query-event-listener with Apache License 2.0 6 votes vote down vote up
public void createLogFile()
{

    SimpleDateFormat dateTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    String timeStamp = dateTime.format(new Date());
    StringBuilder logPath = new StringBuilder();

    logPath.append("/var/log/presto/queries-");
    logPath.append(timeStamp);
    logPath.append(".%g.log");

    try {
        logger = Logger.getLogger(loggerName);
        fh = new FileHandler(logPath.toString(), 524288000, 5, true);
        logger.addHandler(fh);
        logger.setUseParentHandlers(false);
        SimpleFormatter formatter = new SimpleFormatter();
        fh.setFormatter(formatter);
    }
    catch (IOException e) {
        logger.info(e.getMessage());
    }
}
 
Example #5
Source File: SerializeLogRecord.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Deserializes the Base64 encoded string returned by {@link
 * #getBase64()}, format the obtained LogRecord using a
 * SimpleFormatter, and checks that the string representation obtained
 * matches the original string representation returned by {@link
 * #getString()}.
 */
protected void dotest() {
    try {
        final String base64 = getBase64();
        final ByteArrayInputStream bais =
                new ByteArrayInputStream(Base64.getDecoder().decode(base64));
        final ObjectInputStream ois = new ObjectInputStream(bais);
        final LogRecord record = (LogRecord)ois.readObject();
        final SimpleFormatter formatter = new SimpleFormatter();
        String expected = getString();
        String str2 = formatter.format(record);
        check(expected, str2);
        System.out.println(str2);
        System.out.println("PASSED: "+this.getClass().getName()+"\n");
    } catch (IOException | ClassNotFoundException x) {
        throw new RuntimeException(x);
    }
}
 
Example #6
Source File: SerializeLogRecord.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Deserializes the Base64 encoded string returned by {@link
 * #getBase64()}, format the obtained LogRecord using a
 * SimpleFormatter, and checks that the string representation obtained
 * matches the original string representation returned by {@link
 * #getString()}.
 */
protected void dotest() {
    try {
        final String base64 = getBase64();
        final ByteArrayInputStream bais =
                new ByteArrayInputStream(Base64.getDecoder().decode(base64));
        final ObjectInputStream ois = new ObjectInputStream(bais);
        final LogRecord record = (LogRecord)ois.readObject();
        final SimpleFormatter formatter = new SimpleFormatter();
        String expected = getString();
        String str2 = formatter.format(record);
        check(expected, str2);
        System.out.println(str2);
        System.out.println("PASSED: "+this.getClass().getName()+"\n");
    } catch (IOException | ClassNotFoundException x) {
        throw new RuntimeException(x);
    }
}
 
Example #7
Source File: ExceptionTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Test PayaraException with no parameters specified throwing
 * and logging.
 */
@Test
public void testPayaraExceptionWithNothing() {
    // this message must match PayaraIdeException() constructor
    // log message.
    String gfieMsg = "Caught PayaraIdeException.";
    java.util.logging.Logger logger = Logger.getLogger();
    Level logLevel = logger.getLevel();
    OutputStream logOut = new ByteArrayOutputStream(256);
    Handler handler = new StreamHandler(logOut, new SimpleFormatter());
    handler.setLevel(Level.WARNING);
    logger.addHandler(handler);       
    logger.setLevel(Level.WARNING);
    try {
        throw new PayaraIdeException();
    } catch (PayaraIdeException gfie) {
        handler.flush();
    } finally {
        logger.removeHandler(handler);
        handler.close();
        logger.setLevel(logLevel);
    }
    String logMsg = logOut.toString();
    int contains = logMsg.indexOf(gfieMsg);
    assertTrue(contains > -1);
}
 
Example #8
Source File: ExceptionTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Test PayaraException with message throwing and logging.
 */
@Test
public void testPayaraExceptionWithMsg() {
    String gfieMsg = "Test exception";
    java.util.logging.Logger logger = Logger.getLogger();
    Level logLevel = logger.getLevel();
    OutputStream logOut = new ByteArrayOutputStream(256);
    Handler handler = new StreamHandler(logOut, new SimpleFormatter());
    handler.setLevel(Level.WARNING);
    logger.addHandler(handler);       
    logger.setLevel(Level.WARNING);
    try {
        throw new PayaraIdeException(gfieMsg);
    } catch (PayaraIdeException gfie) {
        handler.flush();
    } finally {
        logger.removeHandler(handler);
        handler.close();
        logger.setLevel(logLevel);
    }
    String logMsg = logOut.toString();
    int contains = logMsg.indexOf(gfieMsg);
    assertTrue(contains > -1);
}
 
Example #9
Source File: SerializeLogRecord.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Deserializes the Base64 encoded string returned by {@link
 * #getBase64()}, format the obtained LogRecord using a
 * SimpleFormatter, and checks that the string representation obtained
 * matches the original string representation returned by {@link
 * #getString()}.
 */
protected void dotest() {
    try {
        final String base64 = getBase64();
        final ByteArrayInputStream bais =
                new ByteArrayInputStream(Base64.getDecoder().decode(base64));
        final ObjectInputStream ois = new ObjectInputStream(bais);
        final LogRecord record = (LogRecord)ois.readObject();
        final SimpleFormatter formatter = new SimpleFormatter();
        String expected = getString();
        String str2 = formatter.format(record);
        check(expected, str2);
        System.out.println(str2);
        System.out.println("PASSED: "+this.getClass().getName()+"\n");
    } catch (IOException | ClassNotFoundException x) {
        throw new RuntimeException(x);
    }
}
 
Example #10
Source File: SerializeLogRecord.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Deserializes the Base64 encoded string returned by {@link
 * #getBase64()}, format the obtained LogRecord using a
 * SimpleFormatter, and checks that the string representation obtained
 * matches the original string representation returned by {@link
 * #getString()}.
 */
protected void dotest() {
    try {
        final String base64 = getBase64();
        final ByteArrayInputStream bais =
                new ByteArrayInputStream(Base64.getDecoder().decode(base64));
        final ObjectInputStream ois = new ObjectInputStream(bais);
        final LogRecord record = (LogRecord)ois.readObject();
        final SimpleFormatter formatter = new SimpleFormatter();
        String expected = getString();
        String str2 = formatter.format(record);
        check(expected, str2);
        System.out.println(str2);
        System.out.println("PASSED: "+this.getClass().getName()+"\n");
    } catch (IOException | ClassNotFoundException x) {
        throw new RuntimeException(x);
    }
}
 
Example #11
Source File: ExceptionTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Test GlassFishException with no parameters specified throwing
 * and logging.
 */
@Test
public void testGlassFishExceptionWithNothing() {
    // this message must match GlassFishIdeException() constructor
    // log message.
    String gfieMsg = "Caught GlassFishIdeException.";
    java.util.logging.Logger logger = Logger.getLogger();
    Level logLevel = logger.getLevel();
    OutputStream logOut = new ByteArrayOutputStream(256);
    Handler handler = new StreamHandler(logOut, new SimpleFormatter());
    handler.setLevel(Level.WARNING);
    logger.addHandler(handler);       
    logger.setLevel(Level.WARNING);
    try {
        throw new GlassFishIdeException();
    } catch (GlassFishIdeException gfie) {
        handler.flush();
    } finally {
        logger.removeHandler(handler);
        handler.close();
        logger.setLevel(logLevel);
    }
    String logMsg = logOut.toString();
    int contains = logMsg.indexOf(gfieMsg);
    assertTrue(contains > -1);
}
 
Example #12
Source File: ExceptionTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Test GlassFishException with message throwing and logging.
 */
@Test
public void testGlassFishExceptionWithMsg() {
    String gfieMsg = "Test exception";
    java.util.logging.Logger logger = Logger.getLogger();
    Level logLevel = logger.getLevel();
    OutputStream logOut = new ByteArrayOutputStream(256);
    Handler handler = new StreamHandler(logOut, new SimpleFormatter());
    handler.setLevel(Level.WARNING);
    logger.addHandler(handler);       
    logger.setLevel(Level.WARNING);
    try {
        throw new GlassFishIdeException(gfieMsg);
    } catch (GlassFishIdeException gfie) {
        handler.flush();
    } finally {
        logger.removeHandler(handler);
        handler.close();
        logger.setLevel(logLevel);
    }
    String logMsg = logOut.toString();
    int contains = logMsg.indexOf(gfieMsg);
    assertTrue(contains > -1);
}
 
Example #13
Source File: LoggerRule.java    From jenkins-test-harness with MIT License 6 votes vote down vote up
/**
 * Initializes log record capture, in addition to merely printing it.
 * This allows you to call {@link #getRecords} and/or {@link #getMessages} later.
 * @param maximum the maximum number of records to keep (any further will be discarded)
 * @return this rule, for convenience
 */
public LoggerRule capture(int maximum) {
    messages = new ArrayList<>();
    ringHandler = new RingBufferLogHandler(maximum) {
        final Formatter f = new SimpleFormatter(); // placeholder instance for what should have been a static method perhaps
        @Override
        public synchronized void publish(LogRecord record) {
            super.publish(record);
            String message = f.formatMessage(record);
            Throwable x = record.getThrown();
            synchronized (messages) {
                messages.add(message == null && x != null ? x.toString() : message);
            }
        }
    };
    ringHandler.setLevel(Level.ALL);
    for (Logger logger : loggers.keySet()) {
        logger.addHandler(ringHandler);
    }
    return this;
}
 
Example #14
Source File: LogFileHandlerTestCase.java    From vespa with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleLogging() throws IOException {
    File logFile = temporaryFolder.newFile("testLogFileG1.txt");

  //create logfilehandler
  LogFileHandler h = new LogFileHandler();
  h.setFilePattern(logFile.getAbsolutePath());
  h.setFormatter(new SimpleFormatter());
  h.setRotationTimes("0 5 ...");

  //write log
  LogRecord lr = new LogRecord(Level.INFO, "testDeleteFileFirst1");
  h.publish(lr);
  h.flush();
  h.shutdown();
}
 
Example #15
Source File: AppTest.java    From redpipe with Apache License 2.0 6 votes vote down vote up
@Test
public void testCdiInjection(TestContext context) {
  final ConsoleHandler consoleHandler = new ConsoleHandler();
  consoleHandler.setLevel(Level.FINEST);
  consoleHandler.setFormatter(new SimpleFormatter());

  final Logger app = Logger.getLogger("org.jboss.weld.vertx");
  app.setLevel(Level.FINEST);
  app.addHandler(consoleHandler);

  Async async = context.async();
    webClient.get("/test/injection")
    .as(BodyCodec.string())
    .rxSend()
    .subscribe(body -> {
        context.assertEquals(200, body.statusCode());
        async.complete();
    }, x -> { 
        x.printStackTrace();
        context.fail(x);
        async.complete();
    });
}
 
Example #16
Source File: GemFireXDDataExtractorImpl.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
protected void configureLogger() throws SecurityException, IOException {
  if (logger == null) {
    logger = Logger.getLogger(LOGGER_NAME);
  }
  logger.setUseParentHandlers(false);
  logFileHandler = new FileHandler(logFilePath);
  logFileHandler.setFormatter(new SimpleFormatter());
  Level logLevel = Level.INFO;
  try {
    logLevel = Level.parse(logLevelString);
  } catch (IllegalArgumentException e) {
    logInfo("Unrecognized log level :" + logLevelString + " defaulting to :" + logLevel);
  }
  logFileHandler.setLevel(logLevel);
  logger.addHandler(logFileHandler);
}
 
Example #17
Source File: ThreadedFileHandler.java    From xframium-java with GNU General Public License v3.0 6 votes vote down vote up
public void configureHandler( Level baseLevel )
{
    
    
    Handler[] hList = LogManager.getLogManager().getLogger( "" ).getHandlers();
    for ( Handler h : hList )
    {
        if ( h instanceof ThreadedFileHandler )
            return;
    }
    
    setLevel( baseLevel );
    setFormatter( new SimpleFormatter() );
    
    LogManager.getLogManager().getLogger( "" ).addHandler( this );
}
 
Example #18
Source File: SerializeLogRecord.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Deserializes the Base64 encoded string returned by {@link
 * #getBase64()}, format the obtained LogRecord using a
 * SimpleFormatter, and checks that the string representation obtained
 * matches the original string representation returned by {@link
 * #getString()}.
 */
protected void dotest() {
    try {
        final String base64 = getBase64();
        final ByteArrayInputStream bais =
                new ByteArrayInputStream(Base64.getDecoder().decode(base64));
        final ObjectInputStream ois = new ObjectInputStream(bais);
        final LogRecord record = (LogRecord)ois.readObject();
        final SimpleFormatter formatter = new SimpleFormatter();
        String expected = getString();
        String str2 = formatter.format(record);
        check(expected, str2);
        System.out.println(str2);
        System.out.println("PASSED: "+this.getClass().getName()+"\n");
    } catch (IOException | ClassNotFoundException x) {
        throw new RuntimeException(x);
    }
}
 
Example #19
Source File: SerializeLogRecord.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Deserializes the Base64 encoded string returned by {@link
 * #getBase64()}, format the obtained LogRecord using a
 * SimpleFormatter, and checks that the string representation obtained
 * matches the original string representation returned by {@link
 * #getString()}.
 */
protected void dotest() {
    try {
        final String base64 = getBase64();
        final ByteArrayInputStream bais =
                new ByteArrayInputStream(Base64.getDecoder().decode(base64));
        final ObjectInputStream ois = new ObjectInputStream(bais);
        final LogRecord record = (LogRecord)ois.readObject();
        final SimpleFormatter formatter = new SimpleFormatter();
        String expected = getString();
        String str2 = formatter.format(record);
        check(expected, str2);
        System.out.println(str2);
        System.out.println("PASSED: "+this.getClass().getName()+"\n");
    } catch (IOException | ClassNotFoundException x) {
        throw new RuntimeException(x);
    }
}
 
Example #20
Source File: SerializeLogRecord.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Deserializes the Base64 encoded string returned by {@link
 * #getBase64()}, format the obtained LogRecord using a
 * SimpleFormatter, and checks that the string representation obtained
 * matches the original string representation returned by {@link
 * #getString()}.
 */
protected void dotest() {
    try {
        final String base64 = getBase64();
        final ByteArrayInputStream bais =
                new ByteArrayInputStream(Base64.getDecoder().decode(base64));
        final ObjectInputStream ois = new ObjectInputStream(bais);
        final LogRecord record = (LogRecord)ois.readObject();
        final SimpleFormatter formatter = new SimpleFormatter();
        String expected = getString();
        String str2 = formatter.format(record);
        check(expected, str2);
        System.out.println(str2);
        System.out.println("PASSED: "+this.getClass().getName()+"\n");
    } catch (IOException | ClassNotFoundException x) {
        throw new RuntimeException(x);
    }
}
 
Example #21
Source File: HandlersConfigTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void run() {
    // MemoryHandler

    check(new MemoryHandler(),
        Level.ALL, null, null, SimpleFormatter.class,
        ConfiguredHandler.class, 1000, Level.SEVERE);

    check(new MemoryHandler(new SpecifiedHandler(), 100, Level.WARNING),
        Level.ALL, null, null, SimpleFormatter.class,
        SpecifiedHandler.class, 100, Level.WARNING);

    // StreamHandler

    check(new StreamHandler(),
        Level.INFO, null, null, SimpleFormatter.class,
        null);

    check(new StreamHandler(System.out, new SpecifiedFormatter()),
        Level.INFO, null, null, SpecifiedFormatter.class,
        System.out);

    // ConsoleHandler

    check(new ConsoleHandler(),
        Level.INFO, null, null, SimpleFormatter.class,
        System.err);

    // SocketHandler (use the ServerSocket's port)

    try {
        check(new SocketHandler("localhost", serverSocket.getLocalPort()),
            Level.ALL, null, null, XMLFormatter.class);
    } catch (IOException e) {
        throw new RuntimeException("Can't connect to localhost:" + serverSocket.getLocalPort(), e);
    }
}
 
Example #22
Source File: LoggerUtil.java    From sagacity-sqltoy with Apache License 2.0 5 votes vote down vote up
public static Logger getLogger() {
	if (logger == null) {
		logger = Logger.getLogger("sagacity.quickvo");
		logger.setLevel(Level.ALL);
		try {
			Handler handler = new FileHandler(FileUtil.linkPath(QuickVOConstants.BASE_LOCATE, "quickvo.log"));
			handler.setFormatter(new SimpleFormatter());
			logger.addHandler(handler);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	return logger;
}
 
Example #23
Source File: GoogleLoggerTest.java    From flogger with Apache License 2.0 5 votes vote down vote up
private String logRecordToString(LogRecord logRecord) {
  StringBuilder sb = new StringBuilder();
  String message = new SimpleFormatter().formatMessage(logRecord);
  sb.append(logRecord.getLevel()).append(": ").append(message).append("\n");

  Throwable thrown = logRecord.getThrown();
  if (thrown != null) {
    sb.append(thrown);
  }
  return sb.toString().trim();
}
 
Example #24
Source File: Learner.java    From statelearner with Apache License 2.0 5 votes vote down vote up
public void configureLogging(String output_dir) throws SecurityException, IOException {
	LearnLogger loggerLearnlib = LearnLogger.getLogger("de.learnlib");
	loggerLearnlib.setLevel(Level.ALL);
	FileHandler fhLearnlibLog = new FileHandler(output_dir + "/learnlib.log");
	loggerLearnlib.addHandler(fhLearnlibLog);
	fhLearnlibLog.setFormatter(new SimpleFormatter());
	
	LearnLogger loggerLearner = LearnLogger.getLogger(Learner.class.getSimpleName());
	loggerLearner.setLevel(Level.ALL);
	FileHandler fhLearnerLog = new FileHandler(output_dir + "/learner.log");
	loggerLearner.addHandler(fhLearnerLog);
	fhLearnerLog.setFormatter(new SimpleFormatter());
	loggerLearner.addHandler(new ConsoleHandler());
	
	LearnLogger loggerLearningQueries = LearnLogger.getLogger("learning_queries");
	loggerLearningQueries.setLevel(Level.ALL);
	FileHandler fhLearningQueriesLog = new FileHandler(output_dir + "/learning_queries.log");
	loggerLearningQueries.addHandler(fhLearningQueriesLog);
	fhLearningQueriesLog.setFormatter(new SimpleFormatter());
	loggerLearningQueries.addHandler(new ConsoleHandler());		

	LearnLogger loggerEquivalenceQueries = LearnLogger.getLogger("equivalence_queries");
	loggerEquivalenceQueries.setLevel(Level.ALL);
	FileHandler fhEquivalenceQueriesLog = new FileHandler(output_dir + "/equivalence_queries.log");
	loggerEquivalenceQueries.addHandler(fhEquivalenceQueriesLog);
	fhEquivalenceQueriesLog.setFormatter(new SimpleFormatter());
	loggerEquivalenceQueries.addHandler(new ConsoleHandler());	
}
 
Example #25
Source File: LoggingSpanExporterTest.java    From opentelemetry-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testFlush() {
  final AtomicBoolean flushed = new AtomicBoolean(false);
  Logger.getLogger(LoggingSpanExporter.class.getName())
      .addHandler(
          new StreamHandler(System.err, new SimpleFormatter()) {
            @Override
            public synchronized void flush() {
              flushed.set(true);
            }
          });
  exporter.flush();
  assertThat(flushed.get()).isTrue();
}
 
Example #26
Source File: NettyClientInteropServlet.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
public String getLogOutput() {
  SimpleFormatter formatter = new SimpleFormatter();
  StringBuilder sb = new StringBuilder();
  for (LogRecord loggedMessage : loggedMessages) {
    sb.append(formatter.format(loggedMessage));
  }
  return sb.toString();
}
 
Example #27
Source File: LogsManager.java    From RepoSense with MIT License 5 votes vote down vote up
/**
 * Creates a {@code FileHandler} for the log file.
 *
 * @throws IOException if there are problems opening the file.
 */
private static FileHandler createFileHandler() throws IOException {
    Path path = logFolderLocation.resolve(LOG_FOLDER_NAME).resolve(LOG_FILE_NAME);
    FileHandler fileHandler = new FileHandler(path.toString(), MAX_FILE_SIZE_IN_BYTES, FILE_COUNT, true);
    fileHandler.setFormatter(new SimpleFormatter());
    fileHandler.setLevel(currentFileLogLevel);
    return fileHandler;
}
 
Example #28
Source File: ExceptionTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Test PayaraException with message and cause <code>Throwable</code>
 * throwing and logging.
 */
@Test
public void testPayaraExceptionWithMsgAndCause() {
    String gfieMsg = "Test exception";
    String causeMsg = "Cause exception";
    java.util.logging.Logger logger = Logger.getLogger();
    Level logLevel = logger.getLevel();
    OutputStream logOut = new ByteArrayOutputStream(256);
    Handler handler = new StreamHandler(logOut, new SimpleFormatter());
    handler.setLevel(Level.WARNING);
    logger.addHandler(handler);       
    logger.setLevel(Level.WARNING);
    try {
        try {
            throw new Exception(causeMsg);
        } catch (Exception e) {
            throw new PayaraIdeException(gfieMsg, e);
        }
    } catch (PayaraIdeException gfie) {
        handler.flush();
    } finally {
        logger.removeHandler(handler);
        handler.close();
        logger.setLevel(logLevel);
    }
    String logMsg = logOut.toString();
    int containsGfieMsg = logMsg.indexOf(gfieMsg);
    int containsCauseMsg = logMsg.indexOf(causeMsg);
    assertTrue(containsGfieMsg > -1 && containsCauseMsg > -1);
}
 
Example #29
Source File: Log.java    From aws-codecommit-trigger-plugin with Apache License 2.0 5 votes vote down vote up
public static Log get(Class clazz, PrintStream out, boolean autoFormat) throws IOException {
    Log log = get(clazz);
    log.autoFormat = autoFormat;

    log.streamHandler = new StreamHandler(out, new SimpleFormatter());
    log.logger.addHandler(log.streamHandler);

    return log;
}
 
Example #30
Source File: CatalogModelTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testDepResolver() throws URISyntaxException, CatalogModelException, IOException {
    
    Logger logger = Logger.getLogger(CatalogModelTest.class.getName());
    logger.setLevel(Level.ALL);
    StreamHandler sh = new MyHandler(System.out, new SimpleFormatter());
    sh.setLevel(logger.getLevel());
    //logger.addHandler(sh);
    CatalogFileWrapperDOMImpl.TEST_ENVIRONMENT = true;
    File catFile = new File(System.getProperty("java.io.tmpdir")+File.separator+CatalogWriteModel.PUBLIC_CATALOG_FILE_NAME+CatalogWriteModel.CATALOG_FILE_EXTENSION+".girish");
    catFile.delete();
    catFile.createNewFile();
    FileObject catFO = FileUtil.toFileObject(FileUtil.normalizeFile(catFile));
    URL url = getClass().getResource("dummyFile.txt");
    FileObject peerfo = FileUtil.toFileObject(new File(url.toURI()).getAbsoluteFile());
    System.out.println(catFile);
    CatalogWriteModel drz = new MyCatalogWriteModel(catFO);
    //CatalogWriteModel drz = new MyCatalogWriteModel(new File(System.getProperty("java.io.tmpdir")));
    drz.addURI(new URI("dummy/dummy"), peerfo);
    int length = drz.getCatalogEntries().size();
    
    assertEquals(1, length);
    
    //System.out.println("%%%%"+drz.getModelSource(new URI("dummy/dummy")).getFileObject());
    
    //System.out.println("$$$$"+LSResourceResolverFactory.getDefault().resolveResource(null, null, null, "dummy/dummy", url.toURI().toString()).getSystemId());
    
    //assertTrue(LSResourceResolverFactory.getDefault().resolveResource(null, null, null, "dummy/dummy", url.toURI().toString()).getSystemId().endsWith("dummyFile.txt"));
    
    FileObject fob = (FileObject) drz.getModelSource(new URI("dummy/dummy")).getLookup().lookup(FileObject.class);
    
    assertNotNull(fob);
    
    drz.removeURI(new URI("dummy/dummy"));
    
    length = drz.getCatalogEntries().size();
    
    assertEquals(0, length);
}