List of usage examples for java.util.logging FileHandler FileHandler
public FileHandler(String pattern) throws IOException, SecurityException
From source file:uk.ac.open.crc.jim.Jim.java
/** * Convenience constructor to create non static context to start * application./*w ww .j av a 2s . c o m*/ * */ private Jim() { this.fileArgumentList = new ArrayList<>(); this.settings = Settings.getInstance(); // set up the log file try { fileHandler = new FileHandler(System.currentTimeMillis() / 1000 + "-jim-log.xml"); LOGGER.addHandler(fileHandler); consoleHandler = new ConsoleHandler(); consoleHandler.setLevel(Level.WARNING); LOGGER.addHandler(consoleHandler); } catch (IOException ioEx) { LOGGER.log(Level.SEVERE, "Cannot open log file for writing: {0}", ioEx.toString()); } LOGGER.setLevel(Level.WARNING); // try to cut down the noise for other users }
From source file:node.Mailbox.java
/** * set up the mailbox//from ww w . j a va2 s . c o m * * @param _msgsSend * @param _evolveMsgsRecv * @param _ctrlMsgsRecv * @param reportSend2 */ public Mailbox(int _port, NodeList _nodeList, BlockingQueue<ControlMessage> _ctrlMsgsRecv, BlockingQueue<EvolveMessage> _evolveMsgsRecv, BlockingQueue<MessageWrapper<AbstractMessage>> _msgsSend, BlockingQueue<JSONObject> _reportSend) { // for now, hard-code REPORT to false REPORT = false; ctrlMsgsRecv = _ctrlMsgsRecv; evolveMsgsRecv = _evolveMsgsRecv; msgsSend = _msgsSend; reportSend = _reportSend; port = _port; nodeList = _nodeList; shutdown = false; try { log.setUseParentHandlers(false); Handler fh = new FileHandler("mailbox.log"); fh.setFormatter(new TextFormatter()); log.addHandler(fh); log.setLevel(Level.ALL); } catch (SecurityException e) { e.printStackTrace(); log.severe(ExceptionUtils.getStackTrace(e)); } catch (IOException e) { e.printStackTrace(); log.severe(ExceptionUtils.getStackTrace(e)); } Control.logOneTime("Mailbox started up"); }
From source file:dk.hippogrif.prettyxml.PrettyPrint.java
static String loadConfiguration(String resource) { try {/*ww w . j a v a2s . c o m*/ Properties prop = loadPropertiesResource(resource); // logging String loggingLevel = prop.getProperty("logging.Level"); if (loggingLevel != null) { Level level = Level.parse(loggingLevel); Logger l = Logger.getLogger("dk.hippogrif.prettyxml"); l.setLevel(level); if ("ConsoleHandler".equals(prop.getProperty("logging.Handler"))) { ConsoleHandler h = new ConsoleHandler(); h.setLevel(level); l.addHandler(h); } else if ("FileHandler".equals(prop.getProperty("logging.Handler"))) { FileHandler h = new FileHandler(System.getProperty("user.home") + "/prettyxml.log"); h.setLevel(level); l.addHandler(h); } logger.config("logging.Level=" + loggingLevel); } // version version = prop.getProperty("version", ""); logger.config("version=" + version); // wellknown encodings String s = prop.getProperty("encodings"); if (s == null) { throw new Exception("encodings missing in prettyxml.properties"); } encodings = s.split(";"); // wellknown property settings s = prop.getProperty("settings"); if (s == null) { throw new Exception("settings missing in prettyxml.properties"); } settings = s.split(";"); setting = new HashMap(); for (int i = 0; i < settings.length; i++) { String name = settings[i]; Properties props = loadPropertiesResource(name + ".properties"); checkProperties(props, false); setting.put(name, props); } // wellknown transformations s = prop.getProperty("transformations"); if (s == null) { throw new Exception("transformations missing in prettyxml.properties"); } transformations = s.split(";"); transformation = new HashMap(); for (int i = 0; i < transformations.length; i++) { String name = transformations[i]; transformation.put(name, mkTransformerResource(name + ".xslt")); } } catch (Exception e) { throw new RuntimeException(e); } return version; }
From source file:es.eucm.eadventure.editor.plugin.vignette.ProxySetup.java
private static void init() { proxyConfig = null;//from ww w . j a v a2 s. c om log = Logger.getLogger("es.eucm.eadventure.tracking.prv.service.ProxyConfig"); handler = null; try { handler = new FileHandler("proxy.log"); log.addHandler(handler); } catch (SecurityException e) { handler = null; e.printStackTrace(); } catch (IOException e) { handler = null; e.printStackTrace(); } //Log log = LogFactory.getLog( "es.eucm.eadventure.tracking.prv.service.ProxyConfig" ); log("Setting prop java.net.useSystemProxies=true"); System.setProperty("java.net.useSystemProxies", "true"); Proxy proxy = getProxy(); if (proxy != null) { InetSocketAddress addr = (InetSocketAddress) proxy.address(); if (addr == null) { log("No proxy detected"); System.out.println("NO PROXY"); } else { String host = addr.getHostName(); int port = addr.getPort(); proxyConfig = new ProxyConfig(); proxyConfig.setHostName(host); proxyConfig.setPort("" + port); proxyConfig.setProtocol("http"); log("Proxy detected: host=" + host + " port=" + port); System.setProperty("java.net.useSystemProxies", "false"); System.setProperty("http.proxyHost", host); System.setProperty("http.proxyPort", "" + port); log("Setting up system proxy host & port"); } } System.setProperty("java.net.useSystemProxies", "false"); log("Setting prop java.net.useSystemProxies=false"); init = true; }
From source file:eu.abc4trust.abce.pertubationtests.tud.section2.PA_II_2_2_1malformedCEuri.java
@BeforeClass public static void setupLogger() throws SecurityException, IOException { Handler fh = new FileHandler("PA-Section-2.2.1-malformedCE.log"); SimpleFormatter simpleFormatter = new SimpleFormatter(); fh.setFormatter(simpleFormatter);/*w w w . j a va 2s.c om*/ logger.addHandler(fh); }
From source file:org.hillview.utils.HillviewLogger.java
/** * Create a Hillview logger.// w w w .j a v a 2 s. c o m * @param role Who is doing the logging: web server, worker, test, etc. * @param filename File where logs are to be written. If null logs will be written to the * console. */ private HillviewLogger(String role, @Nullable String filename) { // Disable all default logging LogManager.getLogManager().reset(); this.logger = Logger.getLogger("Hillview"); this.machine = this.checkCommas(Utilities.getHostName()); this.role = this.checkCommas(role); this.logger.setLevel(Level.INFO); Formatter form = new SimpleFormatter() { final String[] components = new String[5]; final String newline = System.lineSeparator(); private final DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS"); @Override public synchronized String format(LogRecord record) { this.components[0] = HillviewLogger.this.checkCommas(df.format(new Date(record.getMillis()))); this.components[1] = HillviewLogger.this.role; this.components[2] = HillviewLogger.this.checkCommas(record.getLevel().toString()); this.components[3] = HillviewLogger.this.machine; this.components[4] = record.getMessage(); String result = String.join(",", components); return result + this.newline; } }; Handler handler; if (filename != null) { try { handler = new FileHandler(filename); } catch (IOException e) { throw new RuntimeException(e); } } else { handler = new ConsoleHandler(); } handler.setFormatter(form); logger.addHandler(handler); File currentDirectory = new File(new File(".").getAbsolutePath()); this.info("Starting logger", "Working directory: {0}", currentDirectory); }
From source file:org.openqa.selenium.server.log.LoggingManager.java
private static FileHandler registerNewSeleniumFileHandler(File logFile) throws IOException { FileHandler fileHandler;/* w w w . jav a 2 s .c o m*/ fileHandler = new FileHandler(logFile.getAbsolutePath()); seleniumFileHandlers.put(logFile, fileHandler); return fileHandler; }
From source file:org.bonitasoft.engine.home.BonitaHomeServer.java
public FileHandler getIncidentFileHandler(long tenantId) throws BonitaHomeNotSetException, IOException { final File incidentFile = FolderMgr.getTenantWorkFolder(getBonitaHomeFolder(), tenantId) .getFile("incidents.log"); return new FileHandler(incidentFile.getAbsolutePath()); }
From source file:eu.abc4trust.abce.pertubationtests.tud.section2.PA_II_2_2_7randomUID.java
@BeforeClass public static void setupLogger() throws SecurityException, IOException { Handler fh = new FileHandler("PA-Section-2.2.7randomUID.log"); SimpleFormatter simpleFormatter = new SimpleFormatter(); fh.setFormatter(simpleFormatter);// w ww . j a v a 2s . co m logger.addHandler(fh); }
From source file:at.bitfire.davdroid.App.java
public void reinitLogger() { // don't use Android default logging, we have our own handlers log.setUseParentHandlers(false);/*from w ww.j a v a 2s . c om*/ @Cleanup ServiceDB.OpenHelper dbHelper = new ServiceDB.OpenHelper(this); Settings settings = new Settings(dbHelper.getReadableDatabase()); boolean logToFile = settings.getBoolean(LOG_TO_EXTERNAL_STORAGE, false), logVerbose = logToFile || Log.isLoggable(log.getName(), Log.DEBUG); // set logging level according to preferences log.setLevel(logVerbose ? Level.ALL : Level.INFO); // remove all handlers for (Handler handler : log.getHandlers()) log.removeHandler(handler); // add logcat handler log.addHandler(LogcatHandler.INSTANCE); NotificationManagerCompat nm = NotificationManagerCompat.from(this); // log to external file according to preferences if (logToFile) { NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(R.drawable.ic_sd_storage_light).setLargeIcon(getLauncherBitmap(this)) .setContentTitle(getString(R.string.logging_davdroid_file_logging)).setLocalOnly(true); File dir = getExternalFilesDir(null); if (dir != null) try { String fileName = new File(dir, "davdroid-" + android.os.Process.myPid() + "-" + DateFormatUtils.format(System.currentTimeMillis(), "yyyyMMdd-HHmmss") + ".txt") .toString(); log.info("Logging to " + fileName); FileHandler fileHandler = new FileHandler(fileName); fileHandler.setFormatter(PlainTextFormatter.DEFAULT); log.addHandler(fileHandler); builder.setContentText(dir.getPath()) .setSubText(getString(R.string.logging_to_external_storage_warning)) .setCategory(NotificationCompat.CATEGORY_STATUS) .setPriority(NotificationCompat.PRIORITY_HIGH) .setStyle(new NotificationCompat.BigTextStyle() .bigText(getString(R.string.logging_to_external_storage, dir.getPath()))) .setOngoing(true); } catch (IOException e) { log.log(Level.SEVERE, "Couldn't create external log file", e); builder.setContentText(getString(R.string.logging_couldnt_create_file, e.getLocalizedMessage())) .setCategory(NotificationCompat.CATEGORY_ERROR); } else builder.setContentText(getString(R.string.logging_no_external_storage)); nm.notify(Constants.NOTIFICATION_EXTERNAL_FILE_LOGGING, builder.build()); } else nm.cancel(Constants.NOTIFICATION_EXTERNAL_FILE_LOGGING); }