Search in sources :

Example 96 with FileHandler

use of java.util.logging.FileHandler in project ignite by apache.

the class CommandHandler method setupJavaLogger.

/**
 * @return prepared JULs logger.
 */
private Logger setupJavaLogger() {
    Logger result = initLogger(CommandHandler.class.getName() + "Log");
    // Adding logging to file.
    try {
        String absPathPattern = new File(JavaLoggerFileHandler.logDirectory(U.defaultWorkDirectory()), "control-utility-%g.log").getAbsolutePath();
        FileHandler fileHandler = new FileHandler(absPathPattern, 5 * 1024 * 1024, 5);
        fileHandler.setFormatter(new JavaLoggerFormatter());
        result.addHandler(fileHandler);
    } catch (Exception e) {
        System.out.println("Failed to configure logging to file");
    }
    // Adding logging to console.
    result.addHandler(setupStreamHandler());
    return result;
}
Also used : JavaLoggerFormatter(org.apache.ignite.logger.java.JavaLoggerFormatter) Logger(java.util.logging.Logger) File(java.io.File) GridClientHandshakeException(org.apache.ignite.internal.client.GridClientHandshakeException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridClientConnectionResetException(org.apache.ignite.internal.client.impl.connection.GridClientConnectionResetException) GridClientDisconnectedException(org.apache.ignite.internal.client.GridClientDisconnectedException) GridServerUnreachableException(org.apache.ignite.internal.client.GridServerUnreachableException) GridClientAuthenticationException(org.apache.ignite.internal.client.GridClientAuthenticationException) GridClientClosedException(org.apache.ignite.internal.client.GridClientClosedException) FileHandler(java.util.logging.FileHandler) JavaLoggerFileHandler(org.apache.ignite.logger.java.JavaLoggerFileHandler)

Example 97 with FileHandler

use of java.util.logging.FileHandler in project ignite by apache.

the class JavaLoggerFileHandler method nodeId.

/**
 * Sets Node id and instantiates {@link FileHandler} delegate.
 *
 * @param app Application name.
 * @param workDir Path to the work directory.
 * @param nodeId Node id.
 */
public void nodeId(@Nullable String app, UUID nodeId, String workDir) throws IgniteCheckedException, IOException {
    if (delegate != null)
        return;
    String clsName = getClass().getName();
    String ptrn = manager.getProperty(clsName + ".pattern");
    if (ptrn == null)
        ptrn = "%{app}-%{id8}.%g.log";
    String fileName = ptrn.replace("%{app}", app != null ? app : "ignite").replace("%{id8}", U.id8(nodeId));
    ptrn = new File(logDirectory(workDir), fileName).getAbsolutePath();
    int limit = getIntProperty(clsName + ".limit", 0);
    if (limit < 0)
        limit = 0;
    int cnt = getIntProperty(clsName + ".count", 1);
    if (cnt <= 0)
        cnt = 1;
    boolean append = getBooleanProperty(clsName + ".append", false);
    FileHandler delegate0;
    synchronized (this) {
        if (delegate != null)
            return;
        delegate = delegate0 = new FileHandler(ptrn, limit, cnt, append);
    }
    delegate0.setLevel(getLevel());
    delegate0.setFormatter(getFormatter());
    delegate0.setEncoding(getEncoding());
    delegate0.setFilter(getFilter());
    delegate0.setErrorManager(getErrorManager());
}
Also used : File(java.io.File) FileHandler(java.util.logging.FileHandler)

Example 98 with FileHandler

use of java.util.logging.FileHandler in project j2objc by google.

the class OldFileHandlerTest method testFileHandler_4params.

public void testFileHandler_4params() throws Exception {
    int limit = 120;
    int count = 1;
    boolean append = false;
    do {
        append = !append;
        handler = new FileHandler("%t/log/string", limit, count, append);
        assertEquals("character encoding is non equal to actual value", "iso-8859-1", handler.getEncoding());
        assertNotNull("Filter is null", handler.getFilter());
        assertNotNull("Formatter is null", handler.getFormatter());
        assertEquals("is non equal to actual value", Level.FINE, handler.getLevel());
        assertNotNull("ErrorManager is null", handler.getErrorManager());
        handler.publish(r);
        handler.close();
        // append mode is true
        for (int i = 0; i < 3; i++) {
            handler = new FileHandler("%t/log/string", limit, count, append);
            handler.publish(r);
            handler.close();
        }
        if (append) {
            assertFileContent(TEMPPATH + SEP + "log", "/string", new LogRecord[] { r, null, r, null, r, null, r }, new MockFormatter());
        } else {
            assertFileContent(TEMPPATH + SEP + "log", "/string", new LogRecord[] { r }, new MockFormatter());
        }
    } while (append);
    try {
        new FileHandler("", limit, count, true);
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
    // expected
    }
    try {
        new FileHandler("%t/log/string", -1, count, false);
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
    // expected
    }
    try {
        new FileHandler("%t/log/string", limit, 0, true);
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
    // expected
    }
}
Also used : FileHandler(java.util.logging.FileHandler)

Example 99 with FileHandler

use of java.util.logging.FileHandler in project j2objc by google.

the class OldFileHandlerTest method testInvalidParams.

// This test fails on RI. Doesn't parse special pattern \"%t/%h."
public void testInvalidParams() throws IOException {
    // bad directory, IOException, append
    try {
        new FileHandler("%t/baddir/multi%g", true);
        fail("should throw IO exception");
    } catch (IOException e) {
    }
    File file = new File(TEMPPATH + SEP + "baddir" + SEP + "multi0");
    assertFalse(file.exists());
    try {
        new FileHandler("%t/baddir/multi%g", false);
        fail("should throw IO exception");
    } catch (IOException e) {
    }
    file = new File(TEMPPATH + SEP + "baddir" + SEP + "multi0");
    assertFalse(file.exists());
    try {
        new FileHandler("%t/baddir/multi%g", 12, 4);
        fail("should throw IO exception");
    } catch (IOException e) {
    }
    file = new File(TEMPPATH + SEP + "baddir" + SEP + "multi0");
    assertFalse(file.exists());
    try {
        new FileHandler("%t/java%u", -1, -1);
        fail("should throw IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }
}
Also used : IOException(java.io.IOException) File(java.io.File) FileHandler(java.util.logging.FileHandler)

Example 100 with FileHandler

use of java.util.logging.FileHandler in project Payara by payara.

the class LoggingExclusionTest method initializeLoggingTest.

private void initializeLoggingTest(String excludeFields) throws Exception {
    Globals.setDefaultHabitat(serviceLocatorMock);
    VersionInfo versionInfo = new VersionInfo() {

        @Override
        public String getAbbreviatedProductName() {
            return ABBREVIATED_PRODUCT;
        }

        @Override
        public String getVersionPrefix() {
            return VERSION_PREFIX;
        }

        @Override
        public String getMajorVersion() {
            return VERSION_MAJOR;
        }

        @Override
        public String getMinorVersion() {
            return VERSION_MINOR;
        }

        @Override
        public String getUpdateVersion() {
            return VERSION_UPDATE;
        }
    };
    Mockito.when(serviceLocatorMock.getService(VersionInfo.class)).thenReturn(versionInfo);
    File basePath = new File(BASE_PATH);
    basePath.mkdirs();
    // Add a file handler with UniformLogFormatter
    uniformFormatHandler = new FileHandler(ULF_LOG);
    uniformFormatHandler.setLevel(Level.FINE);
    uniformFormatHandler.setFormatter(new UniformLogFormatter(excludeFields));
    // Add a file handler with ODLLogFormatter
    odlFormatHandler = new FileHandler(ODL_LOG);
    odlFormatHandler.setLevel(Level.FINE);
    odlFormatHandler.setFormatter(new ODLLogFormatter(excludeFields));
    // Add a file handler with JSONLogFormatter
    jsonFormatHandler = new FileHandler(JSON_LOG);
    jsonFormatHandler.setLevel(Level.FINE);
    jsonFormatHandler.setFormatter(new JSONLogFormatter(excludeFields));
    consoleHandler = new ConsoleHandler();
    consoleHandler.setFormatter(new UniformLogFormatter(excludeFields));
    LOGGER.addHandler(uniformFormatHandler);
    LOGGER.addHandler(odlFormatHandler);
    LOGGER.addHandler(jsonFormatHandler);
    boolean enableConsoleHandler = Boolean.getBoolean(LoggingExclusionTest.class.getName() + ".enableConsoleHandler");
    if (enableConsoleHandler) {
        LOGGER.addHandler(consoleHandler);
    }
    LOGGER.setUseParentHandlers(false);
    LOGGER.setLevel(Level.FINE);
}
Also used : VersionInfo(org.glassfish.api.VersionInfo) JSONLogFormatter(fish.payara.enterprise.server.logging.JSONLogFormatter) File(java.io.File) ConsoleHandler(java.util.logging.ConsoleHandler) FileHandler(java.util.logging.FileHandler)

Aggregations

FileHandler (java.util.logging.FileHandler)139 SimpleFormatter (java.util.logging.SimpleFormatter)59 IOException (java.io.IOException)49 File (java.io.File)48 Logger (java.util.logging.Logger)36 Handler (java.util.logging.Handler)34 ConsoleHandler (java.util.logging.ConsoleHandler)15 Properties (java.util.Properties)14 BalancerRunner (org.mobicents.tools.sip.balancer.BalancerRunner)13 Formatter (java.util.logging.Formatter)12 Config (edu.neu.ccs.pyramid.configuration.Config)11 Date (java.util.Date)11 LogRecord (java.util.logging.LogRecord)10 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 Level (java.util.logging.Level)4 Pair (edu.neu.ccs.pyramid.util.Pair)3 FileInputStream (java.io.FileInputStream)3 FileNotFoundException (java.io.FileNotFoundException)3 LogFormat (de.Keyle.MyPet.api.util.LogFormat)2 CTFT (edu.neu.ccs.pyramid.calibration.CTFT)2