Java Code Examples for java.util.logging.ConsoleHandler#setFormatter()
The following examples show how to use
java.util.logging.ConsoleHandler#setFormatter() .
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: CacheListenersTest.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 2
Source File: ParametersInURITest.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 3
Source File: CacheWriterTest.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 4
Source File: AppTest.java From redpipe with Apache License 2.0 | 6 votes |
@Test public void testCdi(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") .as(BodyCodec.string()) .rxSend() .subscribe(body -> { context.assertEquals(200, body.statusCode()); context.assertEquals("hello response from event bus", body.body()); async.complete(); }, x -> { x.printStackTrace(); context.fail(x); async.complete(); }); }
Example 5
Source File: CacheLoaderTest.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 6
Source File: DenominatorD.java From denominator with Apache License 2.0 | 6 votes |
static void setupLogging() { final long start = currentTimeMillis(); ConsoleHandler handler = new ConsoleHandler(); handler.setLevel(Level.FINE); handler.setFormatter(new Formatter() { @Override public String format(LogRecord record) { return String.format("%7d - %s%n", record.getMillis() - start, record.getMessage()); } }); Logger[] loggers = { Logger.getLogger(DenominatorD.class.getPackage().getName()), Logger.getLogger(feign.Logger.class.getName()), Logger.getLogger(MockWebServer.class.getName()) }; for (Logger logger : loggers) { logger.setLevel(Level.FINE); logger.setUseParentHandlers(false); logger.addHandler(handler); } }
Example 7
Source File: JSRExamplesTest.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 8
Source File: Main.java From jpexs-decompiler with GNU General Public License v3.0 | 6 votes |
public static void initLogging(boolean debug) { try { Logger logger = Logger.getLogger(""); logger.setLevel(Configuration.logLevel); Handler[] handlers = logger.getHandlers(); for (int i = handlers.length - 1; i >= 0; i--) { logger.removeHandler(handlers[i]); } ConsoleHandler conHan = new ConsoleHandler(); conHan.setLevel(debug ? Level.CONFIG : Level.WARNING); SimpleFormatter formatterTxt = new SimpleFormatter(); conHan.setFormatter(formatterTxt); logger.addHandler(conHan); clearLogFile(); } catch (Exception ex) { throw new RuntimeException("Problems with creating the log files"); } }
Example 9
Source File: Seppuku.java From seppuku with GNU General Public License v3.0 | 5 votes |
/** * Setup a logger and set the format */ private void initLogger() { this.logger = Logger.getLogger(Seppuku.class.getName()); logger.setUseParentHandlers(false); final ConsoleHandler handler = new ConsoleHandler(); handler.setFormatter(new SeppukuFormatter()); logger.addHandler(handler); }
Example 10
Source File: LogsManager.java From RepoSense with MIT License | 5 votes |
/** * Creates a {@code ConsoleHandler} to output the log to console. */ private static ConsoleHandler createConsoleHandler() { ConsoleHandler consoleHandler = new ConsoleHandler(); consoleHandler.setLevel(currentConsoleLogLevel); consoleHandler.setFormatter(new CustomLogFormatter()); return consoleHandler; }
Example 11
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 12
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 13
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 14
Source File: OgarServer.java From Ogar2-Server with GNU General Public License v3.0 | 5 votes |
private void setupLogging() { log.setUseParentHandlers(false); LogFormatter formatter = new LogFormatter(); ConsoleHandler ch = new ConsoleHandler(); ch.setFormatter(formatter); if (isDebugging()) { log.setLevel(Level.FINEST); ch.setLevel(Level.FINEST); } else { log.setLevel(Level.INFO); ch.setLevel(Level.INFO); } log.addHandler(ch); try { FileHandler fh = new FileHandler("server.log"); fh.setFormatter(formatter); if (isDebugging()) { fh.setLevel(Level.FINEST); } else { ch.setLevel(Level.INFO); } log.addHandler(fh); } catch (IOException ex) { log.log(Level.SEVERE, "Error while adding FileHandler to logger. Logs will not be output to a file.", ex); } }
Example 15
Source File: UpgradeActions.java From irontest with Apache License 2.0 | 4 votes |
protected void upgrade(DefaultArtifactVersion systemDatabaseVersion, DefaultArtifactVersion jarFileVersion, String ironTestHome, String fullyQualifiedSystemDBURL, String user, String password) throws Exception { Formatter logFormatter = new LogFormatter(); ConsoleHandler consoleHandler = new ConsoleHandler(); consoleHandler.setFormatter(logFormatter); LOGGER.addHandler(consoleHandler); LOGGER.info("Upgrading Iron Test from v" + systemDatabaseVersion + " to v" + jarFileVersion + "."); Path upgradeWorkspace = Files.createTempDirectory("irontest-upgrade-"); Path logFilePath = Paths.get(upgradeWorkspace.toString(), "upgrade-from-v" + systemDatabaseVersion + "-to-v" + jarFileVersion + ".log"); FileHandler logFileHandler = new FileHandler(logFilePath.toString()); logFileHandler.setFormatter(logFormatter); LOGGER.addHandler(logFileHandler); LOGGER.info("Created temp upgrade directory " + upgradeWorkspace.toString()); List<ResourceFile> applicableSystemDBUpgrades = getApplicableUpgradeResourceFiles(systemDatabaseVersion, jarFileVersion, "db", "SystemDB", "sql"); boolean needsSystemDBUpgrade = !applicableSystemDBUpgrades.isEmpty(); if (needsSystemDBUpgrade) { System.out.println("Please manually backup <IronTest_Home>/database folder to your normal maintenance backup location. Type y and then Enter to confirm backup completion."); Scanner scanner = new Scanner(System.in); String line = null; while (!"y".equalsIgnoreCase(line)) { line = scanner.nextLine().trim(); } LOGGER.info("User confirmed system database backup completion."); } // do upgrade in the 'new' folder under the temp upgrade directory Path oldDir; Path newDir = null; if (needsSystemDBUpgrade) { oldDir = Paths.get(upgradeWorkspace.toString(), "old"); newDir = Paths.get(upgradeWorkspace.toString(), "new"); Files.createDirectory(oldDir); Files.createDirectory(newDir); upgradeSystemDB(ironTestHome, fullyQualifiedSystemDBURL, user, password, applicableSystemDBUpgrades, oldDir, newDir, jarFileVersion); } copyFilesToBeUpgraded(ironTestHome, systemDatabaseVersion, jarFileVersion); deleteOldJarsFromIronTestHome(ironTestHome); copyNewJarFromDistToIronTestHome(jarFileVersion, ironTestHome); boolean clearBrowserCacheNeeded = clearBrowserCacheIfNeeded(systemDatabaseVersion, jarFileVersion); // copy files from the 'new' folder to <IronTest_Home> if (needsSystemDBUpgrade) { String systemDBFileName = getSystemDBFileName(fullyQualifiedSystemDBURL); Path ironTestHomeSystemDatabaseFolder = Paths.get(ironTestHome, "database"); Path sourceFilePath = Paths.get(newDir.toString(), "database", systemDBFileName); Path targetFilePath = Paths.get(ironTestHomeSystemDatabaseFolder.toString(), systemDBFileName); Files.copy(sourceFilePath, targetFilePath, StandardCopyOption.REPLACE_EXISTING); LOGGER.info("Copied " + sourceFilePath + " to " + targetFilePath + "."); } String lineDelimiter = "------------------------------------------------------------------------"; LOGGER.info(lineDelimiter); LOGGER.info("UPGRADE SUCCESS"); LOGGER.info(lineDelimiter); LOGGER.info("You can start Iron Test now."); if (clearBrowserCacheNeeded) { LOGGER.info("If Iron Test page is already open, refresh the page (no need to restart browser)."); } LOGGER.info(lineDelimiter); LOGGER.info("Refer to " + logFilePath + " for upgrade logs."); }
Example 16
Source File: Main.java From lancoder with GNU General Public License v3.0 | 4 votes |
private static void buildLoggers(int verbosity) { Level loggingLevel = Level.SEVERE; if (verbosity > 6) { verbosity = 6; } switch (verbosity) { case 1: loggingLevel = Level.SEVERE; break; case 2: loggingLevel = Level.WARNING; break; case 3: loggingLevel = Level.INFO; break; case 4: loggingLevel = Level.FINE; break; case 5: loggingLevel = Level.FINER; break; case 6: loggingLevel = Level.FINEST; break; default: loggingLevel = Level.INFO; } LogManager manager = LogManager.getLogManager(); manager.reset(); logger.setLevel(loggingLevel); ConsoleHandler handler = new ConsoleHandler(); handler.setLevel(loggingLevel); handler.setFormatter(new LogFormatter()); logger.addHandler(handler); manager.addLogger(logger); }
Example 17
Source File: ClientMainFrame.java From Open-Lowcode with Eclipse Public License 2.0 | 4 votes |
/** * Initiate console log and file log * * @throws IOException if anything bad happens creating log giles */ public void initiateLog() throws IOException { Logger mainlogger = Logger.getLogger(""); for (int i = 0; i < mainlogger.getHandlers().length; i++) { mainlogger.removeHandler(mainlogger.getHandlers()[i]); } if (!nolog) { ConsoleHandler consolehandler = new ConsoleHandler(); consolehandler.setFormatter(new ConsoleFormatter()); consolehandler.setLevel(Level.ALL); consolefilter = new OpenLowcodeLogFilter(Level.FINER, "Console Filter", consolehandler); consolehandler.setFilter(consolefilter); mainlogger.addHandler(consolehandler); File file = new File("./log/"); if (!file.exists()) { boolean result = file.mkdir(); if (!result) throw new RuntimeException("Trying to create log folder " + file.getPath() + ", does not work"); } System.err.println("log folder = " + file.getAbsolutePath()); FileHandler logfilehandler = new FileHandler("./log/OLcClient%g.log", 10000000, 1000, true); logfilefilter = new OpenLowcodeLogFilter(Level.FINER, "Log File Filter", logfilehandler); logfilehandler.setFilter(logfilefilter); logfilehandler.setLevel(Level.ALL); logfilehandler.setFormatter(new FileFormatter(true)); mainlogger.addHandler(logfilehandler); mainlogger.setUseParentHandlers(false); Logger rootlogger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); for (int i = 0; i < rootlogger.getHandlers().length; i++) { rootlogger.removeHandler(rootlogger.getHandlers()[i]); } rootlogger.addHandler(logfilehandler); rootlogger.setLevel(Level.ALL); rootlogger.addHandler(consolehandler); rootlogger.setUseParentHandlers(false); } }
Example 18
Source File: Module.java From Open-Lowcode with Eclipse Public License 2.0 | 4 votes |
/** * This allows to launch from command line the generation of an application * * @param args an aray of strings with one element indicating the full path of * the main module of the application (e.g. * com.mycompany.myapp.Mymodule ) */ public static void main(String args[]) { long starttime = new Date().getTime(); ConsoleHandler handler = new ConsoleHandler(); handler.setFormatter(new ConsoleFormatter()); handler.setLevel(Level.INFO); Logger mainlogger = Logger.getLogger(""); for (int i = 0; i < mainlogger.getHandlers().length; i++) { mainlogger.removeHandler(mainlogger.getHandlers()[i]); } mainlogger.addHandler(handler); if (args.length == 0) { logger.severe("Error : syntax java org.openlowcode.design.module.Module class1 [class2] ..."); logger.severe( "where class1, class2 and following are the full class (with path) of the main module of your application"); System.exit(1); } String[] classpathlist = args; ArrayList<String> successfullmodules = new ArrayList<String>(); ArrayList<String> errormodules = new ArrayList<String>(); for (int i = 0; i < classpathlist.length; i++) { String classpath = classpathlist[i]; try { logger.info("will try to launch generation for class = " + classpath); Class<?> moduleclass = Class.forName(classpath); logger.info("Class generated"); Object module = moduleclass.newInstance(); logger.info("Object generated"); Module castedmodule = (Module) module; castedmodule.finalizemodel(); castedmodule.generateSources(); successfullmodules.add(classpath); } catch (Throwable e) { errormodules.add(classpath + " - " + e.getMessage() + "\n - " + e.getStackTrace()[0] + "\n - " + (e.getStackTrace().length > 1 ? e.getStackTrace()[1] : "")); logger.severe("Exception " + e.getMessage()); for (int s = 0; s < e.getStackTrace().length; s++) { logger.severe(" - " + e.getStackTrace()[s].toString()); } } } long endtime = new Date().getTime(); long executioninsec = (endtime - starttime) / 1000; System.err.println(" *** Generation Report *** " + args.length + " modules in " + executioninsec + "s"); for (int i = 0; i < successfullmodules.size(); i++) System.err.println(" SUCCESS " + successfullmodules.get(i)); for (int i = 0; i < errormodules.size(); i++) System.err.println(" ERROR " + errormodules.get(i)); }
Example 19
Source File: Main.java From FakeMCServer with GNU Affero General Public License v3.0 | 4 votes |
public static void main(final String[] args) { // parse args for(int index = 0; index < args.length; index++) { switch(args[index].toLowerCase()) { case "--help": display_help(); System.exit(0); return; case "--debug": case "-d": debug = true; System.out.println("debug mode enabled"); break; case "-v": case "--version": display_version(); System.exit(0); return; case "-h": case "--host": index++; host = args[index]; if("*".equals(host) || "any".equalsIgnoreCase(host)) host = "*"; break; case "-p": case "--port": index++; try { port = new Integer(Integer.parseInt(args[index])); } catch (NumberFormatException e) { System.out.println("invalid port argument"); e.printStackTrace(); System.exit(1); return; } break; default: System.out.println(); System.out.println("invalid option: "+args[index]); System.out.println(); System.exit(1); return; } } final ConsoleHandler handler = new ConsoleHandler(); handler.setFormatter(new LogFormatter()); log.addHandler(handler); log.setUseParentHandlers(false); display_header(); loadResources(); addShutdownHook(); startServer(); }
Example 20
Source File: OLcServerShutdown.java From Open-Lowcode with Eclipse Public License 2.0 | 4 votes |
/** * @param port */ public OLcServerShutdown(int port) { Logger mainlogger = Logger.getLogger(""); try { for (int i = 0; i < mainlogger.getHandlers().length; i++) { mainlogger.removeHandler(mainlogger.getHandlers()[i]); } ConsoleHandler consolehandler = new ConsoleHandler(); consolehandler.setFormatter(new ConsoleFormatter()); consolehandler.setLevel(Level.FINER); mainlogger.addHandler(consolehandler); File file = new File("./log/"); System.err.println("log folder = " + file.getAbsolutePath()); FileHandler logfilehandler = new FileHandler("./log/OpenLowcodeClient%g.log", 10000000, 1000, true); logfilehandler.setLevel(Level.FINEST); logfilehandler.setFormatter(new FileFormatter(true)); mainlogger.addHandler(logfilehandler); mainlogger.setUseParentHandlers(false); // ------------------------------------------------------------------------------ logger.severe("Connection to Open-Lowcode Server on localhost port " + port + " to send shutdown message"); Socket clientsocket = new Socket("localhost", port); MessageSimpleReader reader = new MessageSimpleReader( new BufferedReader(new InputStreamReader(clientsocket.getInputStream()), 9090)); MessageBufferedWriter writer = new MessageBufferedWriter( new BufferedWriter(new OutputStreamWriter(clientsocket.getOutputStream())), false); @SuppressWarnings("unused") AESCommunicator aescommunicator = AESCommunicator.performServerHandshake(reader, writer); writer.startNewMessage(); writer.startStructure("SHUTDOWN"); writer.endStructure("SHUTDOWN"); writer.endMessage(); writer.flushMessage(); logger.severe("Succesfully sent shutdown message to server on port " + port); reader.returnNextMessageStart(); reader.returnNextStartStructure("SHUTDOWNOK"); reader.returnNextEndStructure("SHUTDOWNOK"); reader.returnNextEndMessage(); logger.severe( "Got last message from server before shutdown, all connections are stopped. Server will stop in less than 50ms"); reader.close(); writer.close(); clientsocket.close(); } catch (Exception e) { logger.severe("could not execute correctly shutdown script: " + e.getMessage()); for (int i = 0; i < e.getStackTrace().length; i++) { logger.severe(e.getStackTrace()[i].toString()); } } }