setFormatter(config.getFormatter()); Level level = config.getLogLevel(); setLevel(level); baseLevel = level.equals(Level.ALL) ? Level.FINEST : level; flushLevel = config.getFlushLevel();
@Test public void testAddHandler() { expect(options.getProjectId()).andReturn(PROJECT).anyTimes(); expect(options.getService()).andReturn(logging); logging.setFlushSeverity(Severity.ERROR); expectLastCall().once(); logging.setWriteSynchronicity(Synchronicity.ASYNC); expectLastCall().andVoid(); logging.write(ImmutableList.of(FINEST_ENTRY), DEFAULT_OPTIONS); expectLastCall().once(); replay(options, logging); LoggingHandler handler = new LoggingHandler(LOG_NAME, options, DEFAULT_RESOURCE) { @Override public void close() { // Make close NOOP to avoid mock close exception } }; handler.setLevel(Level.ALL); handler.setFormatter(new TestFormatter()); Logger logger = Logger.getLogger(getClass().getName()); logger.setLevel(Level.ALL); LoggingHandler.addHandler(logger, handler); logger.log(newLogRecord(Level.FINEST, MESSAGE)); }
LogName logName = ProjectLogName.of(options.getProjectId(), logId); LoggingHandler handler = new LoggingHandler(logId, options); handler.setLevel(Level.INFO); Logger logger = Logger.getLogger(getClass().getName()); logger.addHandler(handler);
"us-central1-a")); LoggingHandler handler = new LoggingHandler(logId, options, resource); handler.setLevel(Level.WARNING); handler.setSynchronicity(Synchronicity.SYNC); Logger logger = Logger.getLogger(getClass().getName());
@Test public void testSyncWrite() { expect(options.getProjectId()).andReturn(PROJECT).anyTimes(); expect(options.getService()).andReturn(logging); LogEntry entry = LogEntry.newBuilder(Payload.StringPayload.of(MESSAGE)) .setSeverity(Severity.DEBUG) .addLabel("levelName", "FINEST") .addLabel("levelValue", String.valueOf(Level.FINEST.intValue())) .setTimestamp(123456789L) .build(); logging.setFlushSeverity(Severity.ERROR); expectLastCall().once(); logging.setWriteSynchronicity(Synchronicity.ASYNC); expectLastCall().once(); logging.setWriteSynchronicity(Synchronicity.SYNC); expectLastCall().once(); logging.write(ImmutableList.of(entry), DEFAULT_OPTIONS); expectLastCall().once(); replay(options, logging); LoggingHandler handler = new LoggingHandler(LOG_NAME, options, DEFAULT_RESOURCE); handler.setLevel(Level.ALL); handler.setSynchronicity(Synchronicity.SYNC); handler.setFormatter(new TestFormatter()); LogRecord record = new LogRecord(Level.FINEST, MESSAGE); record.setMillis(123456789L); handler.publish(record); }
public void testFlushLevel() { expect(options.getProjectId()).andReturn(PROJECT).anyTimes(); expect(options.getService()).andReturn(logging); logging.setFlushSeverity(Severity.ERROR); expectLastCall().once(); logging.setWriteSynchronicity(Synchronicity.ASYNC); expectLastCall().once(); logging.setFlushSeverity(Severity.WARNING); expectLastCall().once(); logging.write( ImmutableList.of( FINEST_ENTRY, FINER_ENTRY, FINE_ENTRY, CONFIG_ENTRY, INFO_ENTRY, WARNING_ENTRY), DEFAULT_OPTIONS); expectLastCall().once(); replay(options, logging); LoggingHandler handler = new LoggingHandler(LOG_NAME, options, DEFAULT_RESOURCE); handler.setLevel(Level.ALL); handler.setFlushLevel(Level.WARNING); handler.setFormatter(new TestFormatter()); handler.publish(newLogRecord(Level.FINEST, MESSAGE)); handler.publish(newLogRecord(Level.FINER, MESSAGE)); handler.publish(newLogRecord(Level.FINE, MESSAGE)); handler.publish(newLogRecord(Level.CONFIG, MESSAGE)); handler.publish(newLogRecord(Level.INFO, MESSAGE)); handler.publish(newLogRecord(Level.WARNING, MESSAGE)); }
setFormatter(config.getFormatter()); Level level = config.getLogLevel(); setLevel(level); baseLevel = level.equals(Level.ALL) ? Level.FINEST : level; flushLevel = config.getFlushLevel();