io.vertx.core.logging.Logger Java Examples
The following examples show how to use
io.vertx.core.logging.Logger.
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: ConditionalLogger.java From prebid-server-java with Apache License 2.0 | 6 votes |
public ConditionalLogger(String key, Logger logger) { this.key = key; // can be null this.logger = Objects.requireNonNull(logger); messageToCount = Caffeine.newBuilder() .maximumSize(CACHE_MAXIMUM_SIZE) .expireAfterWrite(EXPIRE_CACHE_DURATION, TimeUnit.HOURS) .<String, AtomicInteger>build() .asMap(); messageToWait = Caffeine.newBuilder() .maximumSize(CACHE_MAXIMUM_SIZE) .expireAfterWrite(EXPIRE_CACHE_DURATION, TimeUnit.HOURS) .<String, Long>build() .asMap(); }
Example #2
Source File: Runner.java From vxms with Apache License 2.0 | 6 votes |
public static void main(String[] args) { // Use logback for logging File logbackFile = new File("config", "logback.xml"); System.setProperty("logback.configurationFile", logbackFile.getAbsolutePath()); System.setProperty(LoggerFactory.LOGGER_DELEGATE_FACTORY_CLASS_NAME, SLF4JLogDelegateFactory.class.getName()); Logger log = LoggerFactory.getLogger(Runner.class); // Setup the http server log.info("Starting server for: http://localhost:8080/hello"); Vertx vertx = Vertx.vertx(); Router router = Router.router(vertx); router.route("/hello").handler(rc -> { log.info("Got hello request"); rc.response().end("World"); }); vertx.createHttpServer() .requestHandler(router::accept) .listen(8080); }
Example #3
Source File: AdminHandler.java From prebid-server-java with Apache License 2.0 | 6 votes |
@Override public void handle(RoutingContext context) { final HttpServerRequest request = context.request(); final BiConsumer<Logger, String> loggingLevelModifier; final int records; final String loggingLevel = request.getParam(LOGGING_PARAM); final String recordsAsString = request.getParam(RECORDS_PARAM); try { loggingLevelModifier = loggingLevel(loggingLevel); records = records(recordsAsString); } catch (IllegalArgumentException e) { context.response() .setStatusCode(HttpResponseStatus.BAD_REQUEST.code()) .end(e.getMessage()); return; } adminManager.setupByCounter(AdminManager.COUNTER_KEY, records, loggingLevelModifier, onFinish()); context.response() .end(String.format("Logging level was changed to %s, for %s requests", loggingLevel, recordsAsString)); }
Example #4
Source File: AdminHandler.java From prebid-server-java with Apache License 2.0 | 6 votes |
private static BiConsumer<Logger, String> loggingLevel(String level) { if (StringUtils.isEmpty(level)) { throw new IllegalArgumentException("Logging level cannot be empty"); } switch (level) { case "info": return Logger::info; case "warn": return Logger::warn; case "trace": return Logger::trace; case "error": return Logger::error; case "fatal": return Logger::fatal; case "debug": return Logger::debug; default: throw new IllegalArgumentException(String.format("Invalid logging level: %s", level)); } }
Example #5
Source File: AdminManagerTest.java From prebid-server-java with Apache License 2.0 | 6 votes |
@Test public void shouldExecuteByTime() throws InterruptedException { // given adminManager.setupByTime(KEY, 1000, (BiConsumer<Logger, String>) Logger::info, (BiConsumer<Logger, String>) (logger, text) -> logger.info(String.format("Done %s", text))); // when for (int i = 0; i < 15; i++) { adminManager.accept(KEY, logger, "Text"); Thread.sleep(100); } // then verify(logger, times(10)).info("Text"); verify(logger, times(5)).info("Done Text"); }
Example #6
Source File: AsyncFileReaderImpl.java From sfs with Apache License 2.0 | 5 votes |
public AsyncFileReaderImpl(Context context, long startPosition, int bufferSize, long length, AsynchronousFileChannel dataFile, Logger log) { this.log = log; this.bufferSize = bufferSize; this.readPos = startPosition; this.bytesRemaining = length; this.startPosition = startPosition; this.ch = dataFile; this.context = context; }
Example #7
Source File: AsyncFileWriterImpl.java From sfs with Apache License 2.0 | 5 votes |
public AsyncFileWriterImpl(long startPosition, WriteQueueSupport<AsyncFileWriter> writeQueueSupport, Context context, AsynchronousFileChannel dataFile, Logger log) { this.log = log; this.startPosition = startPosition; this.writePos = startPosition; this.ch = dataFile; this.context = context; this.writeQueueSupport = writeQueueSupport; this.lastWriteTime = System.currentTimeMillis(); }
Example #8
Source File: AsyncUtils.java From nubes with Apache License 2.0 | 5 votes |
static <T> Handler<AsyncResult<T>> logIfFailed(final String msg, final Logger log) { return res -> { if (res.failed()) { if (msg != null) { log.error(msg, res.cause()); } else { log.error(res.cause()); } } }; }
Example #9
Source File: AdminManagerTest.java From prebid-server-java with Apache License 2.0 | 5 votes |
@Test public void shouldReturnFalseIfKeyIsMissing() { // given adminManager.setupByCounter(KEY, 20, (BiConsumer<Logger, String>) Logger::info, (BiConsumer<Logger, String>) (logger, text) -> logger.info(String.format("Done %s", text))); // when boolean contains = adminManager.contains("WrongKey"); // then assertThat(contains).isFalse(); }
Example #10
Source File: AdminManagerTest.java From prebid-server-java with Apache License 2.0 | 5 votes |
@Test public void shouldReturnTrueIfAdminManagerContainsKey() { // given adminManager.setupByCounter(KEY, 20, (BiConsumer<Logger, String>) Logger::info, (BiConsumer<Logger, String>) (logger, text) -> logger.info(String.format("Done %s", text))); // when boolean contains = adminManager.contains(KEY); // then assertThat(contains).isTrue(); }
Example #11
Source File: AdminManagerTest.java From prebid-server-java with Apache License 2.0 | 5 votes |
@Test public void shouldExecuteFixedAmountOfTimes() { // given adminManager.setupByCounter(KEY, 20, (BiConsumer<Logger, String>) Logger::info, (BiConsumer<Logger, String>) (logger, text) -> logger.info(String.format("Done %s", text))); // when for (int i = 0; i < 30; i++) { adminManager.accept(KEY, logger, "Text"); } // then verify(logger, times(20)).info("Text"); verify(logger, times(10)).info("Done Text"); }
Example #12
Source File: AdminHandler.java From prebid-server-java with Apache License 2.0 | 5 votes |
private static BiConsumer<Logger, String> defaultLogModifier(Logger defaultLogger) { if (defaultLogger.isTraceEnabled()) { return Logger::trace; } else if (defaultLogger.isDebugEnabled()) { return Logger::debug; } else if (defaultLogger.isInfoEnabled()) { return Logger::info; } else if (defaultLogger.isWarnEnabled()) { return Logger::warn; } return Logger::error; }
Example #13
Source File: ConditionalLogger.java From prebid-server-java with Apache License 2.0 | 5 votes |
/** * Calls {@link Consumer} if the given time for specified key is not exceeded. */ private void log(String key, long duration, TimeUnit unit, Consumer<Logger> consumer) { final long currentTime = Instant.now().toEpochMilli(); final String resolvedKey = ObjectUtils.defaultIfNull(this.key, key); final long endTime = messageToWait.computeIfAbsent(resolvedKey, ignored -> calculateEndTime(duration, unit)); if (currentTime >= endTime) { messageToWait.replace(resolvedKey, endTime, calculateEndTime(duration, unit)); consumer.accept(logger); } }
Example #14
Source File: ConditionalLogger.java From prebid-server-java with Apache License 2.0 | 5 votes |
/** * Calls {@link Consumer} if the given limit for specified key is not exceeded. */ private void log(String key, int limit, Consumer<Logger> consumer) { final String resolvedKey = ObjectUtils.defaultIfNull(this.key, key); final AtomicInteger count = messageToCount.computeIfAbsent(resolvedKey, ignored -> new AtomicInteger()); if (count.incrementAndGet() >= limit) { count.set(0); consumer.accept(logger); } }
Example #15
Source File: ApimanVerticleBase.java From apiman with Apache License 2.0 | 4 votes |
protected Logger getLogger() { return log; }
Example #16
Source File: VertxLoggerDelegate.java From apiman with Apache License 2.0 | 4 votes |
public VertxApimanLogger(Logger logger) { this.logger = logger; }
Example #17
Source File: EBInMemoryRegistry.java From apiman with Apache License 2.0 | 4 votes |
@Override public Logger log() { return log; }
Example #18
Source File: ConditionalLogger.java From prebid-server-java with Apache License 2.0 | 4 votes |
public ConditionalLogger(Logger logger) { this(null, logger); }
Example #19
Source File: VerticleHelper.java From vertx-swagger with Apache License 2.0 | 4 votes |
public VerticleHelper(Logger logger) { this.logger = logger; }
Example #20
Source File: VerticleHelper.java From vertx-swagger with Apache License 2.0 | 4 votes |
public VerticleHelper(Logger logger) { this.logger = logger; }
Example #21
Source File: VerticleHelper.java From vertx-swagger with Apache License 2.0 | 4 votes |
public VerticleHelper(Logger logger) { this.logger = logger; }
Example #22
Source File: VerticleHelper.java From vertx-swagger with Apache License 2.0 | 4 votes |
public VerticleHelper(Logger logger) { this.logger = logger; }
Example #23
Source File: AdminHandler.java From prebid-server-java with Apache License 2.0 | 4 votes |
private BiConsumer<Logger, String> onFinish() { return (logger, message) -> defaultLogModifier(logger).accept(logger, message); }
Example #24
Source File: EBRegistryProxyHandler.java From apiman with Apache License 2.0 | votes |
Logger log();