java.util.logging.ConsoleHandler Java Examples
The following examples show how to use
java.util.logging.ConsoleHandler.
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: AppTest.java From redpipe with Apache License 2.0 | 6 votes |
@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 #2
Source File: Client.java From vjtools with Apache License 2.0 | 6 votes |
public static void main(String[] args) { Client client = new Client(); // Set the logger to use our all-on-one-line formatter. Logger l = Logger.getLogger(""); Handler[] hs = l.getHandlers(); for (int i = 0; i < hs.length; i++) { Handler h = hs[0]; if (h instanceof ConsoleHandler) { h.setFormatter(client.new OneLineSimpleLogger()); } } try { client.execute(args); } catch (Exception e) { e.printStackTrace(); } }
Example #3
Source File: Client.java From vjtools with Apache License 2.0 | 6 votes |
public static void main(String[] args) { Client client = new Client(); // Set the logger to use our all-on-one-line formatter. Logger l = Logger.getLogger(""); Handler[] hs = l.getHandlers(); for (int i = 0; i < hs.length; i++) { Handler h = hs[0]; if (h instanceof ConsoleHandler) { h.setFormatter(client.new OneLineSimpleLogger()); } } try { client.execute(args); } catch (Exception e) { e.printStackTrace(); } }
Example #4
Source File: IteratorTest.java From blazingcache with Apache License 2.0 | 6 votes |
@Before public void setupLogger() throws Exception { Level level = Level.SEVERE; Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { System.err.println("uncaughtException from thread " + t.getName() + ": " + e); e.printStackTrace(); } }); java.util.logging.LogManager.getLogManager().reset(); ConsoleHandler ch = new ConsoleHandler(); ch.setLevel(level); SimpleFormatter f = new SimpleFormatter(); ch.setFormatter(f); java.util.logging.Logger.getLogger("").setLevel(level); java.util.logging.Logger.getLogger("").addHandler(ch); }
Example #5
Source File: JaxrsHeaderPropagationTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testHeadersArePropagated() throws Exception { Logger logger = Logger.getLogger("org.eclipse.microprofile.rest.client.ext.DefaultClientHeadersFactoryImpl"); //NOPMD logger.setLevel(Level.ALL); ConsoleHandler h = new ConsoleHandler(); h.setLevel(Level.ALL); logger.addHandler(new ConsoleHandler()); final Response r = createWebClient("/jaxrs/propagate") .header("Header1", "Single") .header("MultiHeader", "value1", "value2", "value3") .get(); assertEquals(Status.OK.getStatusCode(), r.getStatus()); String propagatedHeaderContent = r.readEntity(String.class); System.out.println("propagatedHeaderContent: " + propagatedHeaderContent); assertTrue(propagatedHeaderContent.contains("Header1=Single")); assertTrue(propagatedHeaderContent.contains("MultiHeader=value1,value2,value3")); }
Example #6
Source File: PLogger.java From uavstack with Apache License 2.0 | 6 votes |
@Override public boolean enableConsoleOut(boolean check) { if (check == true) { if (this.consoleHandler == null) { this.consoleHandler = new ConsoleHandler(); this.consoleHandler.setLevel(this.level); this.consoleHandler.setFormatter(new DefaultLogFormatter()); } log.addHandler(this.consoleHandler); isEnableConsoleOutSus = true; } else { if (this.consoleHandler != null) { log.removeHandler(this.consoleHandler); } isEnableConsoleOutSus = false; } return isEnableConsoleOutSus; }
Example #7
Source File: EnvironmentSetup.java From component-runtime with Apache License 2.0 | 6 votes |
private static void jul() { final Logger root = Logger.getLogger(""); root.setLevel(Level.SEVERE); final Handler[] handlers = root.getHandlers(); Stream.of(handlers).forEach(root::removeHandler); final ConsoleHandler handler = new ConsoleHandler() { { setFormatter(new UnifiedFormatter()); } @Override protected synchronized void setOutputStream(final OutputStream out) throws SecurityException { super.setOutputStream(new StdErrStream()); } }; handler.setLevel(Level.SEVERE); root.addHandler(handler); }
Example #8
Source File: RemoteWriteTest.java From noa-libre with GNU Lesser General Public License v2.1 | 6 votes |
/** * Main entry point for the OpenOffice.org Remote Write Test. * * @param args arguments of the test * * @author Andreas Bröker * @date 17.08.2006 */ public static void main(String[] args) { if(args.length < 2) { System.out.println("NOA Remote Write Test"); System.out.println("-------------------"); System.out.println("Usage:"); System.out.println("RemoteWriteTest <host> <port>"); } else { LogManager.getLogManager().reset(); ConsoleHandler consoleHandler = new ConsoleHandler(); consoleHandler.setLevel(Level.FINEST); LOGGER.addHandler(consoleHandler); LOGGER.setLevel(Level.FINEST); try { FileHandler fileHandler = new FileHandler("log.xml"); fileHandler.setLevel(Level.FINEST); LOGGER.addHandler(fileHandler); } catch (Throwable throwable) { } RemoteWriteTest remoteWriteTest = new RemoteWriteTest(); remoteWriteTest.test(args[0], args[1]); } }
Example #9
Source File: DebugLoggerSetup.java From Open-Lowcode with Eclipse Public License 2.0 | 6 votes |
/** * setup logs that display in a compact way on console */ public static void setUpLogsForConsoleDebugging() { ConsoleHandler consolehandler = new ConsoleHandler(); consolehandler.setFormatter(new ConsoleFormatter()); Logger anonymouslogger = Logger.getLogger(""); for (int i = 0; i < anonymouslogger.getHandlers().length; i++) { anonymouslogger.removeHandler(anonymouslogger.getHandlers()[i]); } anonymouslogger.addHandler(consolehandler); anonymouslogger.setUseParentHandlers(false); anonymouslogger.setLevel(Level.ALL); // -------------------------------------------------------------- Logger rootlogger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); for (int i = 0; i < rootlogger.getHandlers().length; i++) { rootlogger.removeHandler(rootlogger.getHandlers()[i]); } rootlogger.addHandler(consolehandler); rootlogger.setUseParentHandlers(false); rootlogger.setLevel(Level.ALL); }
Example #10
Source File: Logging.java From api-mining with GNU General Public License v3.0 | 6 votes |
/** Set up console handler */ public static Handler setUpConsoleHandler() { final ConsoleHandler handler = new ConsoleHandler() { @Override protected void setOutputStream(final OutputStream out) throws SecurityException { super.setOutputStream(System.out); } }; handler.setLevel(Level.ALL); final Formatter formatter = new Formatter() { @Override public String format(final LogRecord record) { return record.getMessage(); } }; handler.setFormatter(formatter); return handler; }
Example #11
Source File: ManagementTest.java From blazingcache with Apache License 2.0 | 6 votes |
@Before public void setupLogger() throws Exception { Level level = Level.SEVERE; Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { System.err.println("uncaughtException from thread " + t.getName() + ": " + e); e.printStackTrace(); } }); java.util.logging.LogManager.getLogManager().reset(); ConsoleHandler ch = new ConsoleHandler(); ch.setLevel(level); SimpleFormatter f = new SimpleFormatter(); ch.setFormatter(f); java.util.logging.Logger.getLogger("").setLevel(level); java.util.logging.Logger.getLogger("").addHandler(ch); }
Example #12
Source File: Logging.java From nashorn with GNU General Public License v2.0 | 5 votes |
private static Logger instantiateLogger(final String name, final Level level) { final Logger logger = java.util.logging.Logger.getLogger(name); for (final Handler h : logger.getHandlers()) { logger.removeHandler(h); } logger.setLevel(level); logger.setUseParentHandlers(false); final Handler c = new ConsoleHandler(); c.setFormatter(new Formatter() { @Override public String format(final LogRecord record) { final StringBuilder sb = new StringBuilder(); sb.append('[') .append(record.getLoggerName()) .append("] ") .append(record.getMessage()) .append('\n'); return sb.toString(); } }); logger.addHandler(c); c.setLevel(level); return logger; }
Example #13
Source File: DriveSyncProvider.java From science-journal with Apache License 2.0 | 5 votes |
public DriveSyncProvider(Context context, Supplier<DriveApi> driveSupplier) { applicationContext = context.getApplicationContext(); accountMap = new HashMap<>(); this.driveSupplier = driveSupplier; if (ENABLE_HTTP_TRANSPORT_LOGGING) { Logger logger = Logger.getLogger(HttpTransport.class.getName()); logger.setLevel(Level.ALL); ConsoleHandler logHandler = new ConsoleHandler(); logHandler.setLevel(Level.ALL); logger.addHandler(logHandler); } }
Example #14
Source File: LogWrapper.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
private static void addDefaultConsoleHandler(Logger logger, String errorMessage, String logFilePath) { ConsoleHandler consoleHandler = new ConsoleHandler(); consoleHandler.setFormatter(new GemFireFormatter()); logger.addHandler(consoleHandler); System.err.println("ERROR: Could not log to file: " + logFilePath + ". Reason: " + errorMessage); System.err.println("Logs will be written on Console."); try { Thread.sleep(3000); //sleep for 3 secs for the message to appear } catch (InterruptedException ignore) {} }
Example #15
Source File: Security.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void initServer() throws Exception { String portstring = System.getProperty("port.number"); port = portstring != null ? Integer.parseInt(portstring) : 0; portstring = System.getProperty("port.number1"); proxyPort = portstring != null ? Integer.parseInt(portstring) : 0; Logger logger = Logger.getLogger("com.sun.net.httpserver"); ConsoleHandler ch = new ConsoleHandler(); logger.setLevel(Level.ALL); ch.setLevel(Level.ALL); logger.addHandler(ch); String root = System.getProperty ("test.src")+ "/docs"; InetSocketAddress addr = new InetSocketAddress (port); s1 = HttpServer.create (addr, 0); if (s1 instanceof HttpsServer) { throw new RuntimeException ("should not be httpsserver"); } HttpHandler h = new FileServerHandler (root); HttpContext c = s1.createContext ("/files", h); HttpHandler h1 = new RedirectHandler ("/redirect"); HttpContext c1 = s1.createContext ("/redirect", h1); executor = Executors.newCachedThreadPool(); s1.setExecutor (executor); s1.start(); if (port == 0) port = s1.getAddress().getPort(); else { if (s1.getAddress().getPort() != port) throw new RuntimeException("Error wrong port"); System.out.println("Port was assigned by Driver"); } System.out.println("HTTP server port = " + port); httproot = "http://127.0.0.1:" + port + "/files/"; redirectroot = "http://127.0.0.1:" + port + "/redirect/"; uri = new URI(httproot); fileuri = httproot + "foo.txt"; }
Example #16
Source File: AnonymousOdsFileWriterTest.java From fastods with GNU General Public License v3.0 | 5 votes |
@Before public final void setUp() { this.logger = PowerMock.createNiceMock(Logger.class); final ConsoleHandler handler = new ConsoleHandler(); handler.setLevel(Level.FINEST); this.logger.addHandler(handler); this.os = new ByteArrayOutputStream(); this.xmlUtil = XMLUtil.create(); this.odsElements = PowerMock.createMock(OdsElements.class); this.builder = PowerMock.createMock(ZipUTF8WriterBuilderImpl.class); this.odsFactory = OdsFactory.create(this.logger, Locale.US); }
Example #17
Source File: SessionLog.java From pumpernickel with MIT License | 5 votes |
SessionLog(File file, String appName) { this.file = file; logger = Logger.getLogger(appName); logger.addHandler(new ConsoleHandler()); logger.addHandler(new MyFileHandler(file)); LogManager.getLogManager().addLogger(logger); }
Example #18
Source File: DebugLogger.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static Logger instantiateLogger(final String name, final Level level) { final Logger logger = java.util.logging.Logger.getLogger(name); AccessController.doPrivileged(new PrivilegedAction<Void>() { @Override public Void run() { for (final Handler h : logger.getHandlers()) { logger.removeHandler(h); } logger.setLevel(level); logger.setUseParentHandlers(false); final Handler c = new ConsoleHandler(); c.setFormatter(new Formatter() { @Override public String format(final LogRecord record) { final StringBuilder sb = new StringBuilder(); sb.append('[') .append(record.getLoggerName()) .append("] ") .append(record.getMessage()) .append('\n'); return sb.toString(); } }); logger.addHandler(c); c.setLevel(level); return null; } }, createLoggerControlAccCtxt()); return logger; }
Example #19
Source File: Logging.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
private static Logger instantiateLogger(final String name, final Level level) { final Logger logger = java.util.logging.Logger.getLogger(name); for (final Handler h : logger.getHandlers()) { logger.removeHandler(h); } logger.setLevel(level); logger.setUseParentHandlers(false); final Handler c = new ConsoleHandler(); c.setFormatter(new Formatter() { @Override public String format(final LogRecord record) { final StringBuilder sb = new StringBuilder(); sb.append('[') .append(record.getLoggerName()) .append("] ") .append(record.getMessage()) .append('\n'); return sb.toString(); } }); logger.addHandler(c); c.setLevel(level); return logger; }
Example #20
Source File: StatusLogger.java From jatecs with GNU General Public License v3.0 | 5 votes |
public StatusLogger() { super(StatusLogger.class.getName(), null); Handler h = new ConsoleHandler(); h.setFormatter(new StatusOutputFormatter()); addHandler(h); setUseParentHandlers(false); setLevel(Level.ALL); }
Example #21
Source File: ExecutionLogger.java From jatecs with GNU General Public License v3.0 | 5 votes |
public ExecutionLogger() { super(ExecutionLogger.class.getName(), null); Handler h = new ConsoleHandler(); h.setFormatter(new StatusOutputFormatter()); addHandler(h); setUseParentHandlers(false); setLevel(Level.INFO); }
Example #22
Source File: VerbatimLogger.java From semanticvectors with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static VerbatimLogger getVerbatimLogger() { if (singletonLogger == null) { singletonLogger = new VerbatimLogger(); ConsoleHandler cs = new ConsoleHandler(); singletonFormatter = singletonLogger.new VerbatimFormatter(); cs.setFormatter(singletonFormatter); VerbatimLogger.underlyingLogger = Logger.getLogger("VerbatimLogger"); VerbatimLogger.underlyingLogger.setUseParentHandlers(false); for (Handler handler : underlyingLogger.getHandlers()) { underlyingLogger.removeHandler(handler); } underlyingLogger.addHandler(cs); } return singletonLogger; }
Example #23
Source File: EasyLinearEquationTest.java From secretshare with GNU Lesser General Public License v2.1 | 5 votes |
public static void enableLogging() { // example code to turn on ALL logging // // To see logging: // [a] set the handler's level // [b] add the handler // [c] set the logger's level Logger l = EasyLinearEquation.getLogger(); Handler lh = new ConsoleHandler(); lh.setFormatter(oneLineFormatter()); // don't forget to do this: lh.setLevel(Level.ALL); // alternative: write log to file: //lh = new FileHandler("log.txt"); // need this too: l.addHandler(lh); // and this: l.setLevel(Level.ALL); if (EasyLinearEquation.getLogger().isLoggable(Level.FINE)) { System.out.println("ok"); EasyLinearEquation.getLogger().fine("Hi there"); } else { System.out.println("failed"); } }
Example #24
Source File: AlipayLogger.java From alipay-sdk with Apache License 2.0 | 5 votes |
/** * 开启DEBUG级别日志(仅针对JDK14LOGGER,LOG4J请自行修改配置文件) * * @param isEnabled */ public static void setJDKDebugEnabled(Boolean isEnabled) { //如果使用JDK14LOGGER,将业务日志级别设为DEBUG(FINE) if (blog instanceof Jdk14Logger) { Jdk14Logger logger = (Jdk14Logger) blog; if (isEnabled) { logger.getLogger().setLevel(Level.FINE); Handler consoleHandler = new ConsoleHandler(); consoleHandler.setLevel(Level.FINE); logger.getLogger().addHandler(consoleHandler); } else { logger.getLogger().setLevel(Level.INFO); } } }
Example #25
Source File: LoggingManager.java From selenium with Apache License 2.0 | 5 votes |
public static void overrideSimpleFormatterWithTerseOneForConsoleHandler( Logger logger, boolean debugMode) { for (Handler handler : logger.getHandlers()) { if (handler instanceof ConsoleHandler) { final Formatter formatter; formatter = handler.getFormatter(); if (formatter instanceof SimpleFormatter) { final StdOutHandler stdOutHandler; final Level originalLevel; /* * DGF - Nobody likes the SimpleFormatter; surely they wanted our terse formatter instead. */ originalLevel = handler.getLevel(); handler.setFormatter(new TerseFormatter()); handler.setLevel(Level.WARNING); /* * Furthermore, we all want DEBUG/INFO on stdout and WARN/ERROR on stderr */ stdOutHandler = new StdOutHandler(); stdOutHandler.setFormatter(new TerseFormatter()); stdOutHandler.setFilter(new MaxLevelFilter(Level.INFO)); stdOutHandler.setLevel(originalLevel); logger.addHandler(stdOutHandler); if (debugMode) { if (originalLevel.intValue() > Level.FINE.intValue()) { stdOutHandler.setLevel(Level.FINE); } } } } } }
Example #26
Source File: BrewServer.java From SB_Elsinore_Server with MIT License | 5 votes |
/** * Initialize the logger. Look at the current logger and its parents to see * if it already has a handler setup. If not, it adds one. * * @param logger * The logger to initialize */ private void initializeLogger(final Logger logger) { if (logger.getHandlers().length == 0) { if (logger.getParent() != null && logger.getUseParentHandlers()) { initializeLogger(LOG.getParent()); } else { Handler newHandler = new ConsoleHandler(); logger.addHandler(newHandler); } } }
Example #27
Source File: LoggerFinderAPITest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public LoggerFinderAPITest(boolean verbose) { this.warnDuplicateMappings = verbose; for (Handler h : Logger.getLogger("").getHandlers()) { if (h instanceof ConsoleHandler) { Logger.getLogger("").removeHandler(h); } } Logger.getLogger("").addHandler( new Handler() { @Override public void publish(LogRecord record) { StringBuilder builder = new StringBuilder(); builder.append("GOT LogRecord: ") .append(record.getLevel().getLocalizedName()) .append(": [").append(record.getLoggerName()) .append("] ").append(record.getSourceClassName()) .append('.') .append(record.getSourceMethodName()).append(" -> ") .append(record.getMessage()) .append(' ') .append(record.getParameters() == null ? "" : Arrays.toString(record.getParameters())) ; System.out.println(builder); if (record.getThrown() != null) { record.getThrown().printStackTrace(System.out); } } @Override public void flush() {} @Override public void close() {} }); }
Example #28
Source File: HttpClient.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@Inject HttpClient(Loggers loggers, HttpClientConfiguration config, JsonUtils jsonUtils, Gson gson) { this.logger = loggers.get(getClass()); this.config = checkNotNull(config, "config"); this.jsonUtils = jsonUtils; this.gson = gson; ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("API HTTP Executor").build(); if (config.getThreads() > 0) { this.executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(config.getThreads())); } else { this.executorService = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool(threadFactory)); } this.requestFactory = this.createRequestFactory(); // By default the google http client is very noisy on http errors, // spitting out a long stack trace every time one try of a request // fails. Disabling the parent handlers (removes default console // handling) and adding our own handler that will only show the short // message makes the error output much more manageable. // See HttpRequest#986 for the offending line and HttpTransport#81 for // the logger definition (it's package private so we can't access it // directly). final Logger httpLogger = Logger.getLogger(HttpTransport.class.getName()); httpLogger.setUseParentHandlers(false); httpLogger.addHandler(new ConsoleHandler() { @Override public void publish(LogRecord record) { String message = record.getMessage(); if (record.getThrown() != null) message += ": " + record.getThrown().toString(); HttpClient.this.logger.log(record.getLevel(), message); } }); }
Example #29
Source File: FilterUtils.java From cas-server-security-filter with Apache License 2.0 | 5 votes |
public static void configureLogging(final Handler handler, final Logger logger) { for (final Handler h : logger.getHandlers()) { logger.removeHandler(h); } logger.setUseParentHandlers(false); if (handler == null) { final ConsoleHandler consoleHandler = new ConsoleHandler(); consoleHandler.setFormatter(new Formatter() { @Override public String format(final LogRecord record) { final StringBuffer sb = new StringBuffer(); sb.append("["); sb.append(record.getLevel().getName()); sb.append("]\t"); sb.append(formatMessage(record)); sb.append("\n"); return sb.toString(); } }); logger.addHandler(consoleHandler); } else { logger.addHandler(handler); } }
Example #30
Source File: DebugLogger.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private static Logger instantiateLogger(final String name, final Level level) { final Logger logger = java.util.logging.Logger.getLogger(name); AccessController.doPrivileged(new PrivilegedAction<Void>() { @Override public Void run() { for (final Handler h : logger.getHandlers()) { logger.removeHandler(h); } logger.setLevel(level); logger.setUseParentHandlers(false); final Handler c = new ConsoleHandler(); c.setFormatter(new Formatter() { @Override public String format(final LogRecord record) { final StringBuilder sb = new StringBuilder(); sb.append('[') .append(record.getLoggerName()) .append("] ") .append(record.getMessage()) .append('\n'); return sb.toString(); } }); logger.addHandler(c); c.setLevel(level); return null; } }, createLoggerControlAccCtxt()); return logger; }