Search in sources :

Example 1 with LogCategory

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

the class SLF4JLogger method log.

/**
 * {@inheritDoc}
 */
@Override
public void log(final SessionLogEntry logEntry) {
    if (logEntry == null) {
        return;
    }
    final LogCategory category = LogCategory.toValue(logEntry.getNameSpace());
    if (category == null) {
        // Lets just silently return.
        return;
    }
    final int levelId = logEntry.getLevel();
    if (this.logLevels[category.getId()].shouldLog((byte) levelId)) {
        final Logger logger = LoggerFactory.getLogger(category.getNameSpace());
        final LogLevel level = LogLevel.toValue(levelId);
        // If EclipseLink LogLevel is ALL or FINEST but SLF4J TRACE is not enabled, return right away.
        if ((level == LogLevel.ALL || level == LogLevel.FINEST) && !logger.isTraceEnabled()) {
            return;
        }
        // If EclipseLink LogLevel is FINER or FINE but SLF4J DEBUG is not enabled, return right away.
        if ((level == LogLevel.FINER || level == LogLevel.FINE) && !logger.isDebugEnabled()) {
            return;
        }
        this.doLog(logger, logEntry, level);
    }
}
Also used : LogCategory(org.eclipse.persistence.logging.LogCategory) Logger(org.slf4j.Logger) LogLevel(org.eclipse.persistence.logging.LogLevel)

Example 2 with LogCategory

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

the class LogCategoryHelper method testToValue.

/**
 * Test {@code LogCategory.toValue(String)} method.
 */
public static void testToValue() {
    for (LogCategory category : LogCategory.values()) {
        String name = category.getName();
        String lower = name.toLowerCase();
        String upper = name.toUpperCase();
        LogCategory categoryFromName = LogCategory.toValue(name);
        LogCategory categoryFromLower = LogCategory.toValue(lower);
        LogCategory categoryFromUpper = LogCategory.toValue(upper);
        assertEquals("Logging category was not found for " + name, category, categoryFromName);
        assertEquals("Logging category was not found for " + lower, category, categoryFromLower);
        assertEquals("Logging category was not found for " + upper, category, categoryFromUpper);
    }
}
Also used : LogCategory(org.eclipse.persistence.logging.LogCategory)

Example 3 with LogCategory

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

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.");
    }
    logLevels[category.getId()] = LogLevel.toValue(level);
// TODO: Handle logging levels on SLF4J side too.
}
Also used : LogCategory(org.eclipse.persistence.logging.LogCategory)

Example 4 with LogCategory

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

the class SLF4JLogger method log.

@Override
public void log(final SessionLogEntry logEntry) {
    if (logEntry == null) {
        return;
    }
    final LogCategory category = LogCategory.toValue(logEntry.getNameSpace());
    if (category == null) {
        throw new IllegalArgumentException("Unknown logging category name.");
    }
    final byte levelId = (byte) logEntry.getLevel();
    if (logLevels[category.getId()].shouldLog(levelId)) {
        final LogLevel level = LogLevel.toValue(levelId);
        final Logger logger = getLogger(category);
        if (logEntry.hasException()) {
            if (shouldLogExceptionStackTrace()) {
                // Message is rendered on EclipseLink side. SLF4J gets final String. Exception is passed too.
                loggerCall[level.getId()].log(logger, formatMessage(logEntry), logEntry.getException());
            } else {
                // Exception message is rendered on EclipseLink side. SLF4J gets final String.
                loggerCall[level.getId()].log(logger, logEntry.getException().toString());
            }
        } else {
            // Message is rendered on EclipseLink side. SLF4J gets final String.
            loggerCall[level.getId()].log(logger, formatMessage(logEntry));
        }
    }
}
Also used : LogCategory(org.eclipse.persistence.logging.LogCategory) Logger(org.slf4j.Logger) LogLevel(org.eclipse.persistence.logging.LogLevel)

Example 5 with LogCategory

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

the class SLF4JLoggerHelper method testLogMessage.

/**
 * Test {@code SLF4JLogger.log(SessionLogEntry)} method with regular {@link String} message.
 * Matrix of logger level x category settings with all log entry log levels is being checked.
 */
public void testLogMessage() {
    // 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 SessionLogEntry logEntry = createLogEntry(category, messageLevel, message);
                // Logback log event additional check.
                final Check check = new Check() {

                    @Override
                    public void check(final ILoggingEvent logEvent) {
                        assertEquals("Logged message \"" + message + "\" must be stored as a message.", message, 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