|
| 1 | +/******************************************************************************** |
| 2 | + * Copyright (c) 2020 [Open Lowcode SAS](https://openlowcode.com/) |
| 3 | + * |
| 4 | + * This program and the accompanying materials are made available under the |
| 5 | + * terms of the Eclipse Public License 2.0 which is available at |
| 6 | + * http://www.eclipse.org/legal/epl-2.0 . |
| 7 | + * |
| 8 | + * SPDX-License-Identifier: EPL-2.0 |
| 9 | + ********************************************************************************/ |
| 10 | + |
| 11 | +package org.openlowcode.tools.trace; |
| 12 | + |
| 13 | +import java.util.logging.ConsoleHandler; |
| 14 | +import java.util.logging.Level; |
| 15 | +import java.util.logging.Logger; |
| 16 | + |
| 17 | +/** |
| 18 | + * This class provides standard settings for loggers for unitary test benches. |
| 19 | + * Those are typically classes that test complex standalone components of the |
| 20 | + * framework, such as PDF printing or RichText edition |
| 21 | + * |
| 22 | + * @author <a href="https://openlowcode.com/" rel="nofollow">Open Lowcode |
| 23 | + * SAS</a> |
| 24 | + * @since 1.5 |
| 25 | + */ |
| 26 | +public class DebugLoggerSetup { |
| 27 | + /** |
| 28 | + * setup logs that display in a compact way on console |
| 29 | + */ |
| 30 | + public static void setUpLogsForConsoleDebugging() { |
| 31 | + |
| 32 | + ConsoleHandler consolehandler = new ConsoleHandler(); |
| 33 | + consolehandler.setFormatter(new ConsoleFormatter()); |
| 34 | + |
| 35 | + Logger anonymouslogger = Logger.getLogger(""); |
| 36 | + for (int i = 0; i < anonymouslogger.getHandlers().length; i++) { |
| 37 | + anonymouslogger.removeHandler(anonymouslogger.getHandlers()[i]); |
| 38 | + } |
| 39 | + anonymouslogger.addHandler(consolehandler); |
| 40 | + anonymouslogger.setUseParentHandlers(false); |
| 41 | + anonymouslogger.setLevel(Level.ALL); |
| 42 | + |
| 43 | + |
| 44 | + // -------------------------------------------------------------- |
| 45 | + Logger rootlogger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); |
| 46 | + for (int i = 0; i < rootlogger.getHandlers().length; i++) { |
| 47 | + rootlogger.removeHandler(rootlogger.getHandlers()[i]); |
| 48 | + } |
| 49 | + rootlogger.addHandler(consolehandler); |
| 50 | + rootlogger.setUseParentHandlers(false); |
| 51 | + rootlogger.setLevel(Level.ALL); |
| 52 | + } |
| 53 | +} |
0 commit comments