Search in sources :

Example 1 with LogLevel

use of org.eclipse.persistence.logging.LogLevel 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 LogLevel

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

the class JAXBUnmarshaller method setProperty.

/**
 * Set a property on the JAXBUnmarshaller. Attempting to set any unsupported
 * property will result in a jakarta.xml.bind.PropertyException.
 * @see org.eclipse.persistence.jaxb.UnmarshallerProperties
 */
@Override
public void setProperty(String key, Object value) throws PropertyException {
    if (key == null) {
        throw new IllegalArgumentException();
    }
    SessionLog logger = AbstractSessionLog.getLog();
    if (logger.shouldLog(SessionLog.FINE, SessionLog.MOXY)) {
        logger.log(SessionLog.FINE, SessionLog.MOXY, "moxy_set_unmarshaller_property", new Object[] { key, value });
    }
    if (MOXySystemProperties.moxyLogPayload != null && xmlUnmarshaller.isLogPayload() == null) {
        xmlUnmarshaller.setLogPayload(MOXySystemProperties.moxyLogPayload);
    }
    if (key.equals(UnmarshallerProperties.MEDIA_TYPE)) {
        MediaType mType = null;
        if (value instanceof MediaType) {
            mType = (MediaType) value;
        } else if (value instanceof String) {
            mType = MediaType.getMediaType((String) value);
        }
        if (mType == null) {
            throw new PropertyException(key, Constants.EMPTY_STRING);
        }
        xmlUnmarshaller.setMediaType(mType);
    } else if (key.equals(UnmarshallerProperties.UNMARSHALLING_CASE_INSENSITIVE)) {
        if (value == null) {
            throw new PropertyException(key, Constants.EMPTY_STRING);
        }
        xmlUnmarshaller.setCaseInsensitive((Boolean) value);
    } else if (key.equals(UnmarshallerProperties.AUTO_DETECT_MEDIA_TYPE)) {
        if (value == null) {
            throw new PropertyException(key, Constants.EMPTY_STRING);
        }
        xmlUnmarshaller.setAutoDetectMediaType((Boolean) value);
    } else if (key.equals(UnmarshallerProperties.JSON_ATTRIBUTE_PREFIX)) {
        xmlUnmarshaller.setAttributePrefix((String) value);
    } else if (UnmarshallerProperties.JSON_INCLUDE_ROOT.equals(key)) {
        if (value == null) {
            throw new PropertyException(key, Constants.EMPTY_STRING);
        }
        xmlUnmarshaller.setIncludeRoot((Boolean) value);
    } else if (UnmarshallerProperties.JSON_NAMESPACE_PREFIX_MAPPER.equals(key)) {
        if (value == null) {
            xmlUnmarshaller.setNamespaceResolver(null);
        } else if (value instanceof Map) {
            Map<String, String> namespaces = (Map<String, String>) value;
            NamespaceResolver nr = new NamespaceResolver();
            Iterator<Entry<String, String>> namesapcesIter = namespaces.entrySet().iterator();
            for (int i = 0; i < namespaces.size(); i++) {
                Entry<String, String> nextEntry = namesapcesIter.next();
                nr.put(nextEntry.getValue(), nextEntry.getKey());
            }
            xmlUnmarshaller.setNamespaceResolver(nr);
        } else if (value instanceof NamespacePrefixMapper) {
            xmlUnmarshaller.setNamespaceResolver(new PrefixMapperNamespaceResolver((NamespacePrefixMapper) value, null));
        }
    } else if (UnmarshallerProperties.JSON_VALUE_WRAPPER.equals(key)) {
        xmlUnmarshaller.setValueWrapper((String) value);
    } else if (UnmarshallerProperties.JSON_NAMESPACE_SEPARATOR.equals(key)) {
        if (value == null) {
            throw new PropertyException(key, Constants.EMPTY_STRING);
        }
        xmlUnmarshaller.setNamespaceSeparator((Character) value);
    } else if (UnmarshallerProperties.JSON_USE_XSD_TYPES_WITH_PREFIX.equals(key)) {
        xmlUnmarshaller.getJsonTypeConfiguration().setUseXsdTypesWithPrefix((Boolean) value);
    } else if (UnmarshallerProperties.JSON_TYPE_COMPATIBILITY.equals(key)) {
        xmlUnmarshaller.getJsonTypeConfiguration().setJsonTypeCompatibility((Boolean) value);
    } else if (UnmarshallerProperties.JSON_TYPE_ATTRIBUTE_NAME.equals(key)) {
        xmlUnmarshaller.getJsonTypeConfiguration().setJsonTypeAttributeName((String) value);
    } else if (UnmarshallerProperties.ID_RESOLVER.equals(key)) {
        setIDResolver((IDResolver) value);
    } else if (SUN_ID_RESOLVER.equals(key) || SUN_JSE_ID_RESOLVER.equals(key)) {
        if (value == null) {
            setIDResolver(null);
        } else {
            setIDResolver(new IDResolverWrapper(value));
        }
    } else if (UnmarshallerProperties.OBJECT_GRAPH.equals(key)) {
        if (value instanceof ObjectGraphImpl) {
            xmlUnmarshaller.setUnmarshalAttributeGroup(((ObjectGraphImpl) value).getAttributeGroup());
        } else if (value instanceof String || value == null) {
            xmlUnmarshaller.setUnmarshalAttributeGroup(value);
        } else {
            throw org.eclipse.persistence.exceptions.JAXBException.invalidValueForObjectGraph(value);
        }
    } else if (UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME.equals(key)) {
        xmlUnmarshaller.setWrapperAsCollectionName((Boolean) value);
    } else if (UnmarshallerProperties.BEAN_VALIDATION_MODE.equals(key)) {
        if (value == null) {
            throw new PropertyException(key, Constants.EMPTY_STRING);
        }
        this.beanValidationMode = ((BeanValidationMode) value);
    } else if (UnmarshallerProperties.BEAN_VALIDATION_FACTORY.equals(key)) {
        // Null value is allowed
        this.prefValidatorFactory = value;
    } else if (UnmarshallerProperties.BEAN_VALIDATION_GROUPS.equals(key)) {
        if (value == null) {
            throw new PropertyException(key, Constants.EMPTY_STRING);
        }
        this.beanValidationGroups = ((Class<?>[]) value);
    } else if (UnmarshallerProperties.BEAN_VALIDATION_NO_OPTIMISATION.equals(key)) {
        if (value == null) {
            throw new PropertyException(key, Constants.EMPTY_STRING);
        }
        this.bvNoOptimisation = ((boolean) value);
    } else if (UnmarshallerProperties.DISABLE_SECURE_PROCESSING.equals(key)) {
        if (value == null) {
            throw new PropertyException(key, Constants.EMPTY_STRING);
        }
        boolean disabled = value instanceof String ? Boolean.parseBoolean((String) value) : (boolean) value;
        xmlUnmarshaller.setDisableSecureProcessing(disabled);
    } else if (UnmarshallerProperties.MOXY_LOG_PAYLOAD.equals(key)) {
        xmlUnmarshaller.setLogPayload(((boolean) value));
    } else if (UnmarshallerProperties.MOXY_LOGGING_LEVEL.equals(key)) {
        if (value instanceof String) {
            AbstractSessionLog.getLog().setLevel(LogLevel.toValue((String) value).getId(), SessionLog.MOXY);
        } else {
            AbstractSessionLog.getLog().setLevel(((LogLevel) value).getId(), SessionLog.MOXY);
        }
    } else {
        throw new PropertyException(key, value);
    }
}
Also used : IDResolver(org.eclipse.persistence.oxm.IDResolver) PropertyException(jakarta.xml.bind.PropertyException) ObjectGraphImpl(org.eclipse.persistence.internal.jaxb.ObjectGraphImpl) LogLevel(org.eclipse.persistence.logging.LogLevel) PrefixMapperNamespaceResolver(org.eclipse.persistence.internal.oxm.record.namespaces.PrefixMapperNamespaceResolver) SessionLog(org.eclipse.persistence.logging.SessionLog) AbstractSessionLog(org.eclipse.persistence.logging.AbstractSessionLog) Entry(java.util.Map.Entry) IDResolverWrapper(org.eclipse.persistence.internal.jaxb.IDResolverWrapper) MediaType(org.eclipse.persistence.oxm.MediaType) PrefixMapperNamespaceResolver(org.eclipse.persistence.internal.oxm.record.namespaces.PrefixMapperNamespaceResolver) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) Map(java.util.Map) HashMap(java.util.HashMap) NamespacePrefixMapper(org.eclipse.persistence.oxm.NamespacePrefixMapper)

Example 3 with LogLevel

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

the class LogLevelHelper method testToValueIntFallBack.

/**
 * Test {@code LogLevel.toValue(int, LogLevel)} method.
 */
public static void testToValueIntFallBack() {
    // Check valid IDs with fall back value different from expected value.
    for (LogLevel level : LogLevel.values()) {
        int id = level.getId();
        LogLevel levelValue = level == LogLevel.ALL ? LogLevel.toValue(id, LogLevel.OFF) : LogLevel.toValue(id, LogLevel.ALL);
        assertEquals("Log level was not found for ID: " + id, level, levelValue);
    }
    // Check some invalid IDs, expecting LogLevel.ALL as fall back.
    final int[] invalidIds = new int[] { -2, -1, LogLevel.length, LogLevel.length + 1 };
    for (int id : invalidIds) {
        LogLevel level = LogLevel.toValue(id, LogLevel.ALL);
        assertEquals("Expected log level " + LogLevel.ALL.getName() + " for ID: " + id, level, LogLevel.ALL);
    }
}
Also used : LogLevel(org.eclipse.persistence.logging.LogLevel)

Example 4 with LogLevel

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

the class LogLevelHelper method testToValueString.

/**
 * Test {@code LogLevel.toValue(String)} method.
 */
public static void testToValueString() {
    // Check valid names.
    for (LogLevel level : LogLevel.values()) {
        String name = level.getName();
        String lower = name.toLowerCase();
        String upper = name.toUpperCase();
        LogLevel levelFromName = LogLevel.toValue(name);
        LogLevel levelFromLower = LogLevel.toValue(lower);
        LogLevel levelFromUpper = LogLevel.toValue(upper);
        assertEquals("Log level was not found for name: " + name, level, levelFromName);
        assertEquals("Log level was not found for name: " + lower, level, levelFromLower);
        assertEquals("Log level was not found for name: " + upper, level, levelFromUpper);
    }
    // Check some invalid names.
    final String[] invalidNames = new String[] { null, "", " " + LogLevel.ALL.getName(), LogLevel.ALL.getName() + " ", "unknown", "something", "AL", "ONFIG", "EVER" };
    for (String invalidName : invalidNames) {
        LogLevel level = LogLevel.toValue(invalidName);
        String levelName = level != null ? level.getName() : "null";
        assertEquals("Log level \"" + levelName + "\" was found for name: " + invalidName, null, level);
    }
}
Also used : LogLevel(org.eclipse.persistence.logging.LogLevel)

Example 5 with LogLevel

use of org.eclipse.persistence.logging.LogLevel 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)

Aggregations

LogLevel (org.eclipse.persistence.logging.LogLevel)10 LogCategory (org.eclipse.persistence.logging.LogCategory)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 PropertyException (jakarta.xml.bind.PropertyException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ObjectGraphImpl (org.eclipse.persistence.internal.jaxb.ObjectGraphImpl)2 AbstractSessionLog (org.eclipse.persistence.logging.AbstractSessionLog)2 SessionLog (org.eclipse.persistence.logging.SessionLog)2 MediaType (org.eclipse.persistence.oxm.MediaType)2 NamespacePrefixMapper (org.eclipse.persistence.oxm.NamespacePrefixMapper)2 Logger (org.slf4j.Logger)2 Entry (java.util.Map.Entry)1 IDResolverWrapper (org.eclipse.persistence.internal.jaxb.IDResolverWrapper)1 MapNamespacePrefixMapper (org.eclipse.persistence.internal.oxm.record.namespaces.MapNamespacePrefixMapper)1 NamespacePrefixMapperWrapper (org.eclipse.persistence.internal.oxm.record.namespaces.NamespacePrefixMapperWrapper)1 PrefixMapperNamespaceResolver (org.eclipse.persistence.internal.oxm.record.namespaces.PrefixMapperNamespaceResolver)1