List of usage examples for java.util.logging LogManager getLogManager
public static LogManager getLogManager()
From source file:com.castlabs.dash.dashfragmenter.Main.java
public Logger setupLogger() { Logger logger = Logger.getLogger("dash"); InputStream stream;// ww w .j av a 2s .c o m if (verbose) { stream = com.castlabs.dash.dashfragmenter.AbstractCommand.class .getResourceAsStream("/log-verbose.properties"); } else { stream = com.castlabs.dash.dashfragmenter.AbstractCommand.class.getResourceAsStream("/log.properties"); } try { LogManager.getLogManager().readConfiguration(stream); } catch (IOException e) { throw new RuntimeException(e); } return logger; }
From source file:org.hillview.utils.HillviewLogger.java
/** * Create a Hillview logger.// w ww .j a va2 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.mp4parser.tools.Main.java
public Logger setupLogger() { Logger logger = Logger.getLogger("tools"); InputStream stream;//from w ww. j a v a 2 s .c o m if (verbose) { stream = Main.class.getResourceAsStream("/log-verbose.properties"); } else { stream = Main.class.getResourceAsStream("/log.properties"); } try { LogManager.getLogManager().readConfiguration(stream); } catch (IOException e) { throw new RuntimeException(e); } logger.setLevel(Level.FINE); logger.addHandler(new java.util.logging.ConsoleHandler()); logger.setUseParentHandlers(false); return logger; }
From source file:JCurl.java
public ResponseEntity<String> execute(String... args) throws Exception { final LoggerContext context = initLogging(); System.out.println("Starting jCurl in " + System.getProperty("user.dir")); OptionSet optionSet = parseOptionSet(args); if (optionSet == null) { return null; }// www.j av a 2s. co m final JCurlRequestOptions options = new JCurlRequestOptions(); String url = String.valueOf(optionSet.nonOptionArguments().get(0)); options.setUrl(url); JCurlEngineType engineType = JCurlEngineType.URL; if (optionSet.has("engine")) { engineType = JCurlEngineType.valueOf(optionSet.valueOf(engineOptionSpec).toUpperCase()); } if (optionSet.has("verbose")) { LogManager.getLogManager().getLogger("").setLevel(java.util.logging.Level.ALL); context.getLogger(Logger.ROOT_LOGGER_NAME).setLevel(Level.ALL); } if (optionSet.has("count")) { options.setCount(Integer.valueOf("" + optionSet.valueOf("count"))); } if (optionSet.has("header")) { for (String header : optionSet.valuesOf(headerSpec)) { String[] vals = header.split(":"); if (vals.length == 1) { options.setHeader(vals[0].trim(), null); } else { options.setHeader(vals[0].trim(), vals[1].trim()); } } } return engineType.getEngine().submit(options); }
From source file:org.springframework.boot.logging.LoggingApplicationListenerTests.java
@Before public void init() throws SecurityException, IOException { LogManager.getLogManager() .readConfiguration(JavaLoggingSystem.class.getResourceAsStream("logging.properties")); this.initializer.onApplicationEvent(new ApplicationStartedEvent(new SpringApplication(), NO_ARGS)); new File("target/foo.log").delete(); new File(tmpDir() + "/spring.log").delete(); }
From source file:org.lilyproject.runtime.cli.LilyRuntimeCli.java
private void run(String[] args) throws Exception { // Forward JDK logging to SLF4J LogManager.getLogManager().reset(); LogManager.getLogManager().getLogger("").addHandler(new SLF4JBridgeHandler()); LogManager.getLogManager().getLogger("").setLevel(Level.ALL); Options cliOptions = new Options(); Option confDirsOption = OptionBuilder.withArgName("confdir").hasArg() .withDescription("The Lily runtime configuration directory. Can be multiple paths separated by " + File.pathSeparator) .withLongOpt("confdir").create('c'); cliOptions.addOption(confDirsOption); Option repositoryLocationOption = OptionBuilder.withArgName("maven-repo-path").hasArg() .withDescription(//from w w w .j av a2 s . c o m "Location of the (Maven-style) artifact repository. Use comma-separated entries to " + "specify multiple locations which will be searched in the order as specified.") .withLongOpt("repository").create('r'); cliOptions.addOption(repositoryLocationOption); Option disabledModulesOption = OptionBuilder.withArgName("mod-id1,mod-id2,...").hasArg() .withDescription("Comma-separated list of modules that should be disabled.") .withLongOpt("disable-modules").create('i'); cliOptions.addOption(disabledModulesOption); Option disableClassSharingOption = OptionBuilder .withDescription("Disable optional sharing of classes between modules") .withLongOpt("disable-class-sharing").create('d'); cliOptions.addOption(disableClassSharingOption); Option consoleLoggingOption = OptionBuilder.withArgName("loglevel").hasArg() .withDescription("Enable logging to console for the root log category with specified loglevel " + "(debug, info, warn, error)") .withLongOpt("console-logging").create('l'); cliOptions.addOption(consoleLoggingOption); Option consoleLogCatOption = OptionBuilder.withArgName("logcategory").hasArg() .withDescription("Enable console logging only for this category") .withLongOpt("console-log-category").create('m'); cliOptions.addOption(consoleLogCatOption); Option logConfigurationOption = OptionBuilder.withArgName("config").hasArg() .withDescription("Log4j configuration file (properties or .xml)").withLongOpt("log-configuration") .create("o"); cliOptions.addOption(logConfigurationOption); Option classLoadingLoggingOption = OptionBuilder .withDescription("Print information about the classloader setup (at startup).") .withLongOpt("classloader-log").create("z"); cliOptions.addOption(classLoadingLoggingOption); Option verboseOption = OptionBuilder.withDescription("Prints lots of information.").withLongOpt("verbose") .create("v"); cliOptions.addOption(verboseOption); Option quietOption = OptionBuilder.withDescription("Suppress normal output.").withLongOpt("quiet") .create("q"); cliOptions.addOption(quietOption); Option sourceLocationsOption = OptionBuilder.withArgName("sourcelocationfile").hasArg() .withDescription( "Path to property file containing alternate source location directory for artifacts.") .withLongOpt("source-locations").create("s"); cliOptions.addOption(sourceLocationsOption); Option modeOption = OptionBuilder.withArgName("modename").hasArg() .withDescription("The runtime mode: prototype, production").withLongOpt("runtime-mode").create("p"); cliOptions.addOption(modeOption); Option versionOption = OptionBuilder.withDescription( "Don't start the service, only dump the version info string for the module defined with -Dlilyruntime.info.module") .withLongOpt("version").create("V"); cliOptions.addOption(versionOption); Option helpOption = new Option("h", "help", false, "Shows help"); cliOptions.addOption(helpOption); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; boolean showHelp = false; try { cmd = parser.parse(cliOptions, args); } catch (ParseException e) { showHelp = true; } if (showHelp || cmd.hasOption(helpOption.getOpt())) { printHelp(cliOptions); System.exit(1); } Logging.setupLogging(cmd.hasOption(verboseOption.getOpt()), cmd.hasOption(quietOption.getOpt()), cmd.hasOption(classLoadingLoggingOption.getOpt()), cmd.getOptionValue(logConfigurationOption.getOpt()), cmd.getOptionValue(consoleLoggingOption.getOpt()), cmd.getOptionValue(consoleLogCatOption.getOpt())); try { Logging.registerLog4jMBeans(); } catch (JMException e) { infolog.error("Unable to register log4j JMX control", e); } infolog.info("Starting the Lily Runtime."); List<File> confDirs = new ArrayList<File>(); if (!cmd.hasOption(confDirsOption.getOpt())) { File confDir = new File(DEFAULT_CONF_DIR).getAbsoluteFile(); if (!confDir.exists()) { System.out.println("Default configuration directory " + DEFAULT_CONF_DIR + " not found in current directory: " + confDir.getAbsolutePath()); System.out .println("To specify another location, use the -" + confDirsOption.getOpt() + " argument"); System.exit(1); } confDirs.add(confDir); } else { String confPathArg = cmd.getOptionValue(confDirsOption.getOpt()); String[] confPaths = confPathArg.split(File.pathSeparator); for (String confPath : confPaths) { confPath = confPath.trim(); if (confPath.length() == 0) { continue; } File confDir = new File(confPath); if (!confDir.exists()) { System.out.println( "Specified configuration directory does not exist: " + confDir.getAbsolutePath()); System.exit(1); } confDirs.add(confDir); } } ArtifactRepository artifactRepository; if (cmd.hasOption(repositoryLocationOption.getOpt())) { artifactRepository = new ChainedMaven2StyleArtifactRepository( cmd.getOptionValue(repositoryLocationOption.getOpt())); } else { File maven2Repository = findLocalMavenRepository(); infolog.info("Using local Maven repository at " + maven2Repository.getAbsolutePath()); artifactRepository = new Maven2StyleArtifactRepository(maven2Repository); } Set<String> disabledModuleIds = getDisabledModuleIds(cmd.getOptionValue(disabledModulesOption.getOpt())); SourceLocations sourceLocations; if (cmd.hasOption(sourceLocationsOption.getOpt())) { File file = new File(cmd.getOptionValue(sourceLocationsOption.getOpt())).getAbsoluteFile(); if (!file.exists()) { System.out.println( "The specified source locations property file does not exist: " + file.getAbsolutePath()); System.exit(1); } InputStream is = null; try { is = new FileInputStream(file); sourceLocations = new SourceLocations(is, file.getParent()); } catch (Throwable t) { throw new LilyRTException("Problem reading source locations property file.", t); } finally { IOUtils.closeQuietly(is); } } else { sourceLocations = new SourceLocations(); } LilyRuntimeSettings settings = new LilyRuntimeSettings(); settings.setConfManager(new ConfManagerImpl(confDirs)); settings.setDisabledModuleIds(disabledModuleIds); settings.setRepository(artifactRepository); settings.setSourceLocations(sourceLocations); settings.setEnableArtifactSharing(!cmd.hasOption(disableClassSharingOption.getOpt())); LilyRuntime runtime = new LilyRuntime(settings); if (cmd.hasOption(modeOption.getOpt())) { String optionValue = cmd.getOptionValue(modeOption.getOpt()); Mode mode = Mode.byName(optionValue); runtime.setMode(mode); } if (cmd.hasOption(versionOption.getOpt())) { System.out.println(runtime.buildModel().moduleInfo(System.getProperty("lilyruntime.info.module"))); System.exit(0); } try { runtime.start(); Runtime.getRuntime().addShutdownHook(new Thread(new ShutdownHandler(runtime))); printStartedMessage(); } catch (Throwable e) { e.printStackTrace(); System.err.println("Startup failed. Will try to shutdown and exit."); try { runtime.stop(); } finally { System.exit(1); } } }
From source file:gov.nrel.bacnet.consumer.BACnet.java
public BACnet(Config t_config) { config = t_config;/* w ww . j a v a2 s. c o m*/ tracker = new TaskTracker(); localDevice = null; logHandler = null; try { logger.info("starting. Loading logging.properties first to log to a file in logs directory"); FileInputStream configFile = new FileInputStream(config.getLoggingPropertiesFileName()); LogManager.getLogManager().readConfiguration(configFile); if (config.getVerboseLogging()) { logger.setLevel(Level.INFO); } if (config.getVeryVerboseLogging()) { logger.setLevel(Level.ALL); } logger.info("Starting now that logger properties are loaded"); LocalDevice.setExceptionListener(new MyExceptionListener()); initialize(config); } catch (Throwable e) { logger.log(Level.WARNING, "exception starting", e); } }
From source file:edu.usu.sdl.openstorefront.web.action.admin.LoggingAction.java
@HandlesEvent("UpdateLogLevel") public Resolution updateLogLevel() { Logger localLogger = LogManager.getLogManager().getLogger(logger); if (localLogger != null) { if (StringUtils.isNotBlank(level)) { localLogger.setLevel(Level.parse(level)); } else {/*from www .j a v a 2 s.co m*/ localLogger.setLevel(null); } log.log(Level.INFO, SecurityUtil.adminAuditLogMessage(getContext().getRequest())); } else { throw new OpenStorefrontRuntimeException("Unable to find logger", "Check name"); } return viewLoggers(); }
From source file:org.icefaces.samples.showcase.util.SourceCodeLoaderConnection.java
@PostConstruct private void initialize() { // If no logger exists for this class, create and add a new one if ((logger = LogManager.getLogManager().getLogger(this.getClass().getName())) == null) { logger = Logger.getLogger(this.getClass().getName()); LogManager.getLogManager().addLogger(logger); }/*from ww w. j a va 2s .c o m*/ // Pull the maximum cache size from web.xml using FacesUtils // We'll default this value if it isn't found MAX_CACHE_SIZE = Integer.parseInt( FacesUtils.getFacesParameter("org.icefaces.samples.showcase.MAX_SOURCE_CACHE_SIZE", "20971520")); // Next we'll try to build a URL to load the source from // This is basically http://localhost:8080/showcase/, but the port and address could change // We'll try to dynamically get this from the ExternalContext request, otherwise we'll check it from the web.xml // and finally just default it Object request = FacesContext.getCurrentInstance().getExternalContext().getRequest(); if ((request != null) && (request instanceof HttpServletRequest)) { HttpServletRequest httpRequest = (HttpServletRequest) request; String hostName = "localhost"; try { //construct a url (SOURCE_SERVLET_URL) from getLocalName is not reliable //should use host from requestURL. URL requestUrl = new URL(httpRequest.getRequestURL().toString()); hostName = requestUrl.getHost(); } catch (MalformedURLException mfException) { } IS_SECURE = httpRequest.isSecure(); String protocol = IS_SECURE ? "https://" : "http://"; SOURCE_SERVLET_URL = protocol + hostName + ":" + httpRequest.getLocalPort() + httpRequest.getContextPath() + "/"; } else { String fromFile = FacesUtils.getFacesParameter("org.icefaces.samples.showcase.SOURCE_SERVLET_URL"); if (fromFile != null) { SOURCE_SERVLET_URL = fromFile; } else { SOURCE_SERVLET_URL = "http://localhost:8080/comp-suite/"; } } SOURCE_SERVLET_URL += "sourcecodeStream.html?path="; //logger.info("Reading source code from url [" + SOURCE_SERVLET_URL + "]."); }
From source file:org.geefive.salesforce.soqleditor.SFDCConnectionManager.java
public SFDCConnectionManager(LogInInterface loginIface, String uname, String pword, boolean isPrd) { InputStream propertyInputStream = null; userName = uname;// w w w .ja v a2 s.c o m password = pword; isProduction = isPrd; loginInterface = loginIface; try { File logDir = new File("log"); if (!logDir.exists()) { logDir.mkdir(); } propertyInputStream = this.getClass().getResourceAsStream("logging.properties"); LogManager.getLogManager().readConfiguration(propertyInputStream); preferences.load(propertyInputStream); logger = Logger.getLogger("Cirrostratus"); } catch (IOException ex) { logger.info("WARNING: Could not open configuration file"); logger.info("WARNING: Logging not configured (console output only)"); ex.printStackTrace(); } finally { try { propertyInputStream.close(); } catch (Exception ex) { } } logger.info("starting Cirrostratus"); }