How to use TerseFormatter class of org.openqa.selenium.grid.log package

Best Selenium code snippet using org.openqa.selenium.grid.log.TerseFormatter

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

copy
1// Licensed to the Software Freedom Conservancy (SFC) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The SFC licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18package org.openqa.selenium.remote.server.log;
19
20import org.openqa.selenium.grid.log.LoggingOptions;
21import org.openqa.selenium.grid.log.TerseFormatter;
22
23import java.util.logging.ConsoleHandler;
24import java.util.logging.Formatter;
25import java.util.logging.Handler;
26import java.util.logging.Level;
27import java.util.logging.Logger;
28import java.util.logging.SimpleFormatter;
29
30/**
31 * Configure logging to Selenium taste.
32 */
33public class LoggingManager {
34
35  private static PerSessionLogHandler perSessionLogHandler =
36    new PerSessionLogHandler(4000, new TerseFormatter(LoggingOptions.DEFAULT_LOG_TIMESTAMP_FORMAT), false);
37
38  public static synchronized void configureLogging(boolean debugMode) {
39    final Logger currentLogger;
40
41    currentLogger = Logger.getLogger("");
42    overrideSimpleFormatterWithTerseOneForConsoleHandler(currentLogger, debugMode);
43    if (debugMode) {
44      currentLogger.setLevel(Level.FINE);
45    }
46  }
47
48  /**
49   * Provides a PerSessionLogHandler
50   */
51  public static synchronized PerSessionLogHandler perSessionLogHandler() {
52    return perSessionLogHandler;
53  }
54
55  public static void overrideSimpleFormatterWithTerseOneForConsoleHandler(
56    Logger logger,
57    boolean debugMode) {
58    for (Handler handler : logger.getHandlers()) {
59      if (handler instanceof ConsoleHandler) {
60        final Formatter formatter;
61
62        formatter = handler.getFormatter();
63        if (formatter instanceof SimpleFormatter) {
64          final StdOutHandler stdOutHandler;
65          final Level originalLevel;
66
67          /*
68           * DGF - Nobody likes the SimpleFormatter; surely they wanted our terse formatter instead.
69           */
70          originalLevel = handler.getLevel();
71          handler.setFormatter(new TerseFormatter(LoggingOptions.DEFAULT_LOG_TIMESTAMP_FORMAT));
72          handler.setLevel(Level.WARNING);
73
74          /*
75           * Furthermore, we all want DEBUG/INFO on stdout and WARN/ERROR on stderr
76           */
77          stdOutHandler = new StdOutHandler();
78          stdOutHandler.setFormatter(new TerseFormatter(LoggingOptions.DEFAULT_LOG_TIMESTAMP_FORMAT));
79          stdOutHandler.setFilter(new MaxLevelFilter(Level.INFO));
80          stdOutHandler.setLevel(originalLevel);
81          logger.addHandler(stdOutHandler);
82          if (debugMode) {
83            if (originalLevel.intValue() > Level.FINE.intValue()) {
84              stdOutHandler.setLevel(Level.FINE);
85            }
86          }
87        }
88      }
89    }
90  }
91}
92
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

...Most popular Stackoverflow questions on TerseFormatter

    No relevant questions found for this class 😞

Most used methods in TerseFormatter

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)