Example usage for java.util.logging LogManager getLogManager

List of usage examples for java.util.logging LogManager getLogManager

Introduction

In this page you can find the example usage for java.util.logging LogManager getLogManager.

Prototype

public static LogManager getLogManager() 

Source Link

Document

Returns the global LogManager object.

Usage

From source file:com.moneydance.modules.features.importlist.util.Helper.java

public static void loadLoggerConfiguration() {
    try {//from w  w  w .java2s.  c o  m
        InputStream inputStream = getInputStreamFromResource(
                Helper.INSTANCE.getSettings().getLoggingPropertiesResource());
        LogManager.getLogManager().readConfiguration(inputStream);

    } catch (SecurityException e) {
        e.printStackTrace(System.err);
    } catch (IOException e) {
        e.printStackTrace(System.err);
    }
}

From source file:com.github.apetrelli.scafa.ScafaLauncher.java

public void initialize() {
    File home = new File(System.getProperty("user.home"));
    scafaDirectory = new File(home, ".scafa");
    ensureConfigDirectoryPresent(scafaDirectory);
    try (InputStream stream = new FileInputStream(new File(scafaDirectory, "logging.properties"))) {
        LogManager.getLogManager().readConfiguration(stream);
    } catch (IOException e) {
        LOG.log(Level.SEVERE, "Cannot load logging configuration, exiting", e);
        System.exit(1);/*from ww  w. j a v  a2  s .c om*/
    }
}

From source file:edu.usu.sdl.openstorefront.web.action.admin.LoggingAction.java

@DefaultHandler
public Resolution viewLoggers() {
    StringBuilder results = new StringBuilder();

    List<String> allLoggers = LogManager.getLoggingMXBean().getLoggerNames();
    Collections.sort(allLoggers);
    results.append(// ww w.  j a  v a  2 s  .  com
            "<table border='1'><tr style='background-color: lightgrey; '><th >Logger</th><th>Level</th><th>Handlers</th>");
    for (String name : allLoggers) {
        results.append("<tr>");
        Level levelLocal = LogManager.getLogManager().getLogger(name).getLevel();
        String levelName = "";
        if (levelLocal != null) {
            levelName = levelLocal.getName();
        }
        results.append("<td><b>").append(name).append("</b></td><td> ").append(levelName).append("</td>");

        results.append("<td>");
        Logger localLogger = LogManager.getLogManager().getLogger(name);
        for (Handler handlerLocal : localLogger.getHandlers()) {
            results.append(handlerLocal.getClass().getName()).append(" = ")
                    .append(handlerLocal.getLevel().getName()).append("<br>");
        }
        results.append("</td>");

        results.append("</tr>");
    }
    results.append("</table>");
    return new StreamingResolution("text/html", results.toString());
}

From source file:org.coconut.internal.util.LogHelperTest.java

@Test
public void JdkLogging() {
    Element eh = LogHelper.saveLogger(doc, bundle, e, "myLogger", Loggers.JDK.from("foo"));
    Logger l = LogHelper.readLog(eh);
    assertSame(Loggers.JDK.from("boo").getClass(), l.getClass());
    assertSame(LogManager.getLogManager().getLogger("foo"), Loggers.JDK.getAsJDKLogger(l));
}

From source file:org.tros.utils.logging.Logging.java

private static void loadFile(File logProp) {
    String definedLogFile = System.getProperty("torgo.logfile");
    StringBuilder sb = new StringBuilder();
    try {//  ww  w  .  ja  va2 s . co  m
        final Scanner scanner = new Scanner(logProp);
        boolean lookForFile = false;
        while (scanner.hasNextLine()) {
            String lineFromFile = scanner.nextLine();
            if (lineFromFile.startsWith("handlers") && lineFromFile.contains("java.util.logging.FileHandler")) {
                lookForFile = true;
            }
            if (lookForFile && definedLogFile != null
                    && lineFromFile.contains("java.util.logging.FileHandler.pattern")) {
                lineFromFile = "java.util.logging.FileHandler.pattern = " + definedLogFile;
            }
            sb.append(lineFromFile).append(System.getProperty("line.separator"));
        }

        try (BufferedInputStream fis = new BufferedInputStream(IOUtils.toInputStream(sb.toString(), "UTF-8"))) {
            LogManager.getLogManager().readConfiguration(fis);
        } catch (FileNotFoundException | SecurityException ex) {
            Logger.getLogger(Logging.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(Logging.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:org.springframework.boot.context.initializer.LoggingApplicationContextInitializerTests.java

@Before
public void init() throws SecurityException, IOException {
    LogManager.getLogManager()
            .readConfiguration(JavaLoggingSystem.class.getResourceAsStream("logging.properties"));
    this.initializer.initialize(new SpringApplication(), NO_ARGS);
}

From source file:org.springframework.boot.context.listener.LoggingApplicationListenerTests.java

@Before
public void init() throws SecurityException, IOException {
    LogManager.getLogManager()
            .readConfiguration(JavaLoggingSystem.class.getResourceAsStream("logging.properties"));
    this.initializer.onApplicationEvent(new SpringApplicationStartEvent(new SpringApplication(), NO_ARGS));
    new File("target/foo.log").delete();
}

From source file:org.apache.jena.atlas.logging.java.ConsoleHandlerStream.java

public ConsoleHandlerStream(OutputStream outputStream) {
    super(protectStdOutput(outputStream), new TextFormatter());

    LogManager manager = LogManager.getLogManager();
    ClassLoader classLoader = ClassLoader.getSystemClassLoader();
    String cname = getClass().getName();

    // -- Level/*w w  w. j  a  v a2  s  .  c  om*/
    Level level = Level.INFO;
    String pLevel = getProperty(manager, cname, "level");
    if (pLevel != null)
        level = Level.parse(pLevel);
    setLevel(level);

    // -- Formatter
    // The default is TextFormatter above
    // (we had to pass a Formatter of some kind to super(,)).
    String pFormatter = getProperty(manager, cname, "formatter");
    if (pFormatter != null) {
        try {
            Class<?> cls = classLoader.loadClass(pFormatter);
            setFormatter((Formatter) cls.newInstance());
        } catch (Exception ex) {
            System.err.println("Problems setting the logging formatter");
            ex.printStackTrace(System.err);
        }
    }

    // -- Filter
    String pFilter = getProperty(manager, cname, "filter");
    if (pFilter != null) {
        try {
            Class<?> cls = classLoader.loadClass(pFilter);
            setFilter((Filter) cls.newInstance());
        } catch (Exception ex) {
            System.err.println("Problems setting the logging filter");
            ex.printStackTrace(System.err);
        }
    }

    // -- Encoding : Default UTF-8
    String pEncoding = getProperty(manager, cname, "encoding");
    if (pEncoding == null)
        pEncoding = StandardCharsets.UTF_8.name();
    try {
        setEncoding(pEncoding);
    } catch (Exception e) {
        // That should work for UTF-8 as it is a required charset. 
        System.err.print("Failed to set encoding: " + e.getMessage());
    }
}