當前位置: 首頁>>代碼示例>>Java>>正文


Java ThreadContextMap類代碼示例

本文整理匯總了Java中org.apache.logging.log4j.spi.ThreadContextMap的典型用法代碼示例。如果您正苦於以下問題:Java ThreadContextMap類的具體用法?Java ThreadContextMap怎麽用?Java ThreadContextMap使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ThreadContextMap類屬於org.apache.logging.log4j.spi包,在下文中一共展示了ThreadContextMap類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: equals

import org.apache.logging.log4j.spi.ThreadContextMap; //導入依賴的package包/類
@Override
public boolean equals(final Object obj) {
    if (this == obj) {
        return true;
    }
    if (obj == null) {
        return false;
    }
    if (!(obj instanceof ThreadContextMap)) {
        return false;
    }
    final ThreadContextMap other = (ThreadContextMap) obj;
    final Map<String, String> map = this.localMap.get();
    final Map<String, String> otherMap = other.getImmutableMapOrNull();
    if (map == null) {
        if (otherMap != null) {
            return false;
        }
    } else if (!map.equals(otherMap)) {
        return false;
    }
    return true;
}
 
開發者ID:oldratlee,項目名稱:log4j2-ttl-thread-context-map,代碼行數:24,代碼來源:TtlThreadContextMap.java

示例2: writeInternal

import org.apache.logging.log4j.spi.ThreadContextMap; //導入依賴的package包/類
@Override
protected void writeInternal(final LogEvent event, final Serializable serializable) {
    for (int i = 0; i < columnMappings.size(); i++) {
        final ColumnMapping columnMapping = columnMappings.get(i);
        if (ThreadContextMap.class.isAssignableFrom(columnMapping.getType())
            || ReadOnlyStringMap.class.isAssignableFrom(columnMapping.getType())) {
            values[i] = event.getContextData().toMap();
        } else if (ThreadContextStack.class.isAssignableFrom(columnMapping.getType())) {
            values[i] = event.getContextStack().asList();
        } else if (Date.class.isAssignableFrom(columnMapping.getType())) {
            values[i] = DateTypeConverter.fromMillis(event.getTimeMillis(), columnMapping.getType().asSubclass(Date.class));
        } else {
            values[i] = TypeConverters.convert(columnMapping.getLayout().toSerializable(event),
                columnMapping.getType(), null);
        }
    }
    final BoundStatement boundStatement = preparedStatement.bind(values);
    if (batchStatement == null) {
        session.execute(boundStatement);
    } else {
        batchStatement.add(boundStatement);
    }
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:24,代碼來源:CassandraManager.java

示例3: build

import org.apache.logging.log4j.spi.ThreadContextMap; //導入依賴的package包/類
@Override
public ColumnMapping build() {
    if (pattern != null) {
        layout = PatternLayout.newBuilder()
            .withPattern(pattern)
            .withConfiguration(configuration)
            .build();
    }
    if (!(layout == null
        || literal == null
        || Date.class.isAssignableFrom(type)
        || ReadOnlyStringMap.class.isAssignableFrom(type)
        || ThreadContextMap.class.isAssignableFrom(type)
        || ThreadContextStack.class.isAssignableFrom(type))) {
        LOGGER.error("No 'layout' or 'literal' value specified and type ({}) is not compatible with ThreadContextMap, ThreadContextStack, or java.util.Date for the mapping", type, this);
        return null;
    }
    if (literal != null && parameter != null) {
        LOGGER.error("Only one of 'literal' or 'parameter' can be set on the column mapping {}", this);
        return null;
    }
    return new ColumnMapping(name, source, layout, literal, parameter, type);
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:24,代碼來源:ColumnMapping.java

示例4: writeInternal

import org.apache.logging.log4j.spi.ThreadContextMap; //導入依賴的package包/類
@Override
protected void writeInternal(final LogEvent event, final Serializable serializable) {
    StringReader reader = null;
    try {
        if (!this.isRunning() || this.connection == null || this.connection.isClosed() || this.statement == null
                || this.statement.isClosed()) {
            throw new AppenderLoggingException(
                    "Cannot write logging event; JDBC manager not connected to the database.");
        }

        if (serializable instanceof MapMessage) {
            setFields((MapMessage<?, ?>) serializable);
        }
        int i = 1; // JDBC indices start at 1
        for (final ColumnMapping mapping : this.columnMappings) {
            if (ThreadContextMap.class.isAssignableFrom(mapping.getType())
                    || ReadOnlyStringMap.class.isAssignableFrom(mapping.getType())) {
                this.statement.setObject(i++, event.getContextData().toMap());
            } else if (ThreadContextStack.class.isAssignableFrom(mapping.getType())) {
                this.statement.setObject(i++, event.getContextStack().asList());
            } else if (Date.class.isAssignableFrom(mapping.getType())) {
                this.statement.setObject(i++, DateTypeConverter.fromMillis(event.getTimeMillis(),
                        mapping.getType().asSubclass(Date.class)));
            } else {
                StringLayout layout = mapping.getLayout();
                if (layout != null) {
                    if (Clob.class.isAssignableFrom(mapping.getType())) {
                        this.statement.setClob(i++, new StringReader(layout.toSerializable(event)));
                    } else if (NClob.class.isAssignableFrom(mapping.getType())) {
                        this.statement.setNClob(i++, new StringReader(layout.toSerializable(event)));
                    } else {
                        final Object value = TypeConverters.convert(layout.toSerializable(event), mapping.getType(),
                                null);
                        if (value == null) {
                            this.statement.setNull(i++, Types.NULL);
                        } else {
                            this.statement.setObject(i++, value);
                        }
                    }
                }
            }
        }
        for (final ColumnConfig column : this.columnConfigs) {
            if (column.isEventTimestamp()) {
                this.statement.setTimestamp(i++, new Timestamp(event.getTimeMillis()));
            } else if (column.isClob()) {
                reader = new StringReader(column.getLayout().toSerializable(event));
                if (column.isUnicode()) {
                    this.statement.setNClob(i++, reader);
                } else {
                    this.statement.setClob(i++, reader);
                }
            } else if (column.isUnicode()) {
                this.statement.setNString(i++, column.getLayout().toSerializable(event));
            } else {
                this.statement.setString(i++, column.getLayout().toSerializable(event));
            }
        }

        if (this.isBatchSupported) {
            this.statement.addBatch();
        } else if (this.statement.executeUpdate() == 0) {
            throw new AppenderLoggingException(
                    "No records inserted in database table for log event in JDBC manager.");
        }
    } catch (final SQLException e) {
        throw new AppenderLoggingException("Failed to insert record for log event in JDBC manager: " +
                e.getMessage(), e);
    } finally {
        Closer.closeSilently(reader);
    }
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:73,代碼來源:JdbcDatabaseManager.java


注:本文中的org.apache.logging.log4j.spi.ThreadContextMap類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。