Search in sources :

Example 6 with LogCategory

use of org.eclipse.persistence.logging.LogCategory in project adeptj-modules by AdeptJ.

the class SLF4JLogger method setLevel.

/**
 * Set the logging level for the specified logging category.
 *
 * @param level        The logging level to be set.
 * @param categoryName The {@link String} representation of an EclipseLink logging category.
 */
@Override
public void setLevel(final int level, final String categoryName) {
    final LogCategory category = LogCategory.toValue(categoryName);
    if (category == null) {
        throw new IllegalArgumentException("Unknown logging category name.");
    }
    this.logLevels[category.getId()] = LogLevel.toValue(level);
}
Also used : LogCategory(org.eclipse.persistence.logging.LogCategory)

Example 7 with LogCategory

use of org.eclipse.persistence.logging.LogCategory in project eclipselink by eclipse-ee4j.

the class LogCategoryHelper method testGetNameSpace.

/**
 * Test {@code LogCategory.getNameSpace()} method.
 * @throws NoSuchFieldException If there is a problem in {@code ReflectionHelper} call.
 * @throws SecurityException If there is a problem in {@code ReflectionHelper} call.
 * @throws IllegalArgumentException If there is a problem in {@code ReflectionHelper} call.
 * @throws IllegalAccessException If there is a problem in {@code ReflectionHelper} call.
 */
public static void testGetNameSpace() throws ReflectiveOperationException {
    final String namespacePrefix = ReflectionHelper.<String>getPrivateStatic(LogCategory.class, "NAMESPACE_PREFIX");
    for (LogCategory category : LogCategory.values()) {
        String name = category.getName();
        StringBuilder sb = new StringBuilder(namespacePrefix.length() + name.length());
        sb.append(namespacePrefix);
        sb.append(name);
        String nameSpace = sb.toString();
        assertEquals("Logger name space shall be " + nameSpace, nameSpace, category.getNameSpace());
    }
}
Also used : LogCategory(org.eclipse.persistence.logging.LogCategory)

Example 8 with LogCategory

use of org.eclipse.persistence.logging.LogCategory in project eclipselink by eclipse-ee4j.

the class SLF4JLoggerHelper method testLogExceptionStackTrace.

/**
 * Test {@code SLF4JLogger.log(SessionLogEntry)} method with {@link Throwable} and stack trace logging turned on.
 * Matrix of logger level x category settings with all log entry log levels is being checked.
 */
public void testLogExceptionStackTrace() {
    // Verify loggers for logger level x category matrix.
    for (LogCategory category : LogCategory.values()) {
        final String nameSpace = category.getNameSpace();
        final Logger categoryLogger = loggerContext.getLogger(nameSpace);
        categoryLogger.setLevel(Level.ALL);
        for (LogLevel loggerLevel : LogLevel.values()) {
            // Verify messages with all log levels.
            logger.setLevel(loggerLevel.getId(), category.getName());
            for (LogLevel messageLevel : LogLevel.values()) {
                final String message = "Log message";
                final String exceptionMessage = "Exception message";
                final Throwable exception = new RuntimeException(exceptionMessage);
                // Log entry without log message.
                final SessionLogEntry logEntry1 = createLogEntry(category, messageLevel, exception);
                // Log entry with log message.
                final SessionLogEntry logEntry2 = createLogEntry(category, messageLevel, message, exception);
                // Logback log event additional check for exception without log message.
                final Check check1 = new Check() {

                    @Override
                    public void check(final ILoggingEvent logEvent) {
                        final String eventMessage = logEvent.getMessage();
                        assertTrue("No message was passed so null or empty String must be stored as a message.", eventMessage == null || eventMessage.isEmpty());
                        assertEquals("Exception message must be stored in throwableProxy.", exceptionMessage, logEvent.getThrowableProxy().getMessage());
                    }
                };
                // Logback log event additional check for exception with log message.
                final Check check2 = new Check() {

                    @Override
                    public void check(final ILoggingEvent logEvent) {
                        assertEquals("Logged message \"" + message + "\" must be stored as a message.", message, logEvent.getMessage());
                        assertEquals("Exception message must be stored in throwableProxy.", exceptionMessage, logEvent.getThrowableProxy().getMessage());
                    }
                };
                testLogEntry(category, loggerLevel, messageLevel, categoryLogger, logEntry1, check1);
                testLogEntry(category, loggerLevel, messageLevel, categoryLogger, logEntry2, check2);
            }
        }
    }
}
Also used : LogCategory(org.eclipse.persistence.logging.LogCategory) Logger(ch.qos.logback.classic.Logger) SLF4JLogger(org.eclipse.persistence.logging.slf4j.SLF4JLogger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LogLevel(org.eclipse.persistence.logging.LogLevel) SessionLogEntry(org.eclipse.persistence.logging.SessionLogEntry)

Example 9 with LogCategory

use of org.eclipse.persistence.logging.LogCategory in project eclipselink by eclipse-ee4j.

the class SLF4JLoggerHelper method testLogExceptionWithoutStackTrace.

/**
 * Test {@code SLF4JLogger.log(SessionLogEntry)} method with {@link Throwable} and stack trace logging turned off.
 * Matrix of logger level x category settings with all log entry log levels is being checked.
 */
public void testLogExceptionWithoutStackTrace() {
    // Verify loggers for logger level x category matrix.
    for (LogCategory category : LogCategory.values()) {
        final String nameSpace = category.getNameSpace();
        final Logger categoryLogger = loggerContext.getLogger(nameSpace);
        categoryLogger.setLevel(Level.ALL);
        for (LogLevel loggerLevel : LogLevel.values()) {
            // Verify messages with all log levels.
            logger.setLevel(loggerLevel.getId(), category.getName());
            for (LogLevel messageLevel : LogLevel.values()) {
                final Throwable exception = new RuntimeException("Exception message");
                final SessionLogEntry logEntry = createLogEntry(category, messageLevel, exception);
                // Logback log event additional check.
                final Check check = new Check() {

                    @Override
                    public void check(final ILoggingEvent logEvent) {
                        assertEquals("Logged exception message \"" + exception.getMessage() + "\" must be stored as a message.", exception.toString(), logEvent.getMessage());
                        assertNull("There can't be any arguments for already rendered message.", logEvent.getArgumentArray());
                    }
                };
                testLogEntry(category, loggerLevel, messageLevel, categoryLogger, logEntry, check);
            }
        }
    }
}
Also used : LogCategory(org.eclipse.persistence.logging.LogCategory) Logger(ch.qos.logback.classic.Logger) SLF4JLogger(org.eclipse.persistence.logging.slf4j.SLF4JLogger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LogLevel(org.eclipse.persistence.logging.LogLevel) SessionLogEntry(org.eclipse.persistence.logging.SessionLogEntry)

Aggregations

LogCategory (org.eclipse.persistence.logging.LogCategory)9 LogLevel (org.eclipse.persistence.logging.LogLevel)5 Logger (ch.qos.logback.classic.Logger)3 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)3 SessionLogEntry (org.eclipse.persistence.logging.SessionLogEntry)3 SLF4JLogger (org.eclipse.persistence.logging.slf4j.SLF4JLogger)3 Logger (org.slf4j.Logger)2