本文整理汇总了Java中org.apache.logging.log4j.Logger.trace方法的典型用法代码示例。如果您正苦于以下问题:Java Logger.trace方法的具体用法?Java Logger.trace怎么用?Java Logger.trace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.logging.log4j.Logger
的用法示例。
在下文中一共展示了Logger.trace方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: publish
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
@Override
public void publish(LogRecord record) {
Logger logger = getLogger(record.getLoggerName());
Throwable exception = record.getThrown();
Level level = record.getLevel();
String message = getFormatter().formatMessage(record);
if (level == Level.SEVERE) {
logger.error(message, exception);
} else if (level == Level.WARNING) {
logger.warn(message, exception);
} else if (level == Level.INFO) {
logger.info(message, exception);
} else if (level == Level.CONFIG) {
logger.debug(message, exception);
} else {
logger.trace(message, exception);
}
}
示例2: testLocationInfoTest
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
public void testLocationInfoTest() throws IOException, UserException {
setupLogging("location_info");
final Logger testLogger = ESLoggerFactory.getLogger("test");
testLogger.error("This is an error message");
testLogger.warn("This is a warning message");
testLogger.info("This is an info message");
testLogger.debug("This is a debug message");
testLogger.trace("This is a trace message");
final String path =
System.getProperty("es.logs.base_path") +
System.getProperty("file.separator") +
System.getProperty("es.logs.cluster_name") +
".log";
final List<String> events = Files.readAllLines(PathUtils.get(path));
assertThat(events.size(), equalTo(5));
final String location = "org.elasticsearch.common.logging.EvilLoggerTests.testLocationInfoTest";
// the first message is a warning for unsupported configuration files
assertLogLine(events.get(0), Level.ERROR, location, "This is an error message");
assertLogLine(events.get(1), Level.WARN, location, "This is a warning message");
assertLogLine(events.get(2), Level.INFO, location, "This is an info message");
assertLogLine(events.get(3), Level.DEBUG, location, "This is a debug message");
assertLogLine(events.get(4), Level.TRACE, location, "This is a trace message");
}
示例3: buildShardLevelInfo
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
static void buildShardLevelInfo(Logger logger, ShardStats[] stats, ImmutableOpenMap.Builder<String, Long> newShardSizes,
ImmutableOpenMap.Builder<ShardRouting, String> newShardRoutingToDataPath, ClusterState state) {
MetaData meta = state.getMetaData();
for (ShardStats s : stats) {
IndexMetaData indexMeta = meta.index(s.getShardRouting().index());
newShardRoutingToDataPath.put(s.getShardRouting(), s.getDataPath());
long size = s.getStats().getStore().sizeInBytes();
String sid = ClusterInfo.shardIdentifierFromRouting(s.getShardRouting());
if (logger.isTraceEnabled()) {
logger.trace("shard: {} size: {}", sid, size);
}
if (indexMeta != null && indexMeta.isIndexUsingShadowReplicas()) {
// Shards on a shared filesystem should be considered of size 0
if (logger.isTraceEnabled()) {
logger.trace("shard: {} is using shadow replicas and will be treated as size 0", sid);
}
size = 0;
}
newShardSizes.put(sid, size);
}
}
示例4: ChildMemoryCircuitBreaker
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
/**
* Create a circuit breaker that will break if the number of estimated
* bytes grows above the limit. All estimations will be multiplied by
* the given overheadConstant. Uses the given oldBreaker to initialize
* the starting offset.
* @param settings settings to configure this breaker
* @param parent parent circuit breaker service to delegate tripped breakers to
* @param name the name of the breaker
* @param oldBreaker the previous circuit breaker to inherit the used value from (starting offset)
*/
public ChildMemoryCircuitBreaker(BreakerSettings settings, ChildMemoryCircuitBreaker oldBreaker,
Logger logger, HierarchyCircuitBreakerService parent, String name) {
this.name = name;
this.settings = settings;
this.memoryBytesLimit = settings.getLimit();
this.overheadConstant = settings.getOverhead();
if (oldBreaker == null) {
this.used = new AtomicLong(0);
this.trippedCount = new AtomicLong(0);
} else {
this.used = oldBreaker.used;
this.trippedCount = oldBreaker.trippedCount;
}
this.logger = logger;
if (logger.isTraceEnabled()) {
logger.trace("creating ChildCircuitBreaker with settings {}", this.settings);
}
this.parent = parent;
}
示例5: MemoryCircuitBreaker
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
/**
* Create a circuit breaker that will break if the number of estimated
* bytes grows above the limit. All estimations will be multiplied by
* the given overheadConstant. Uses the given oldBreaker to initialize
* the starting offset.
* @param limit circuit breaker limit
* @param overheadConstant constant multiplier for byte estimations
* @param oldBreaker the previous circuit breaker to inherit the used value from (starting offset)
*/
public MemoryCircuitBreaker(ByteSizeValue limit, double overheadConstant, MemoryCircuitBreaker oldBreaker, Logger logger) {
this.memoryBytesLimit = limit.getBytes();
this.overheadConstant = overheadConstant;
if (oldBreaker == null) {
this.used = new AtomicLong(0);
this.trippedCount = new AtomicLong(0);
} else {
this.used = oldBreaker.used;
this.trippedCount = oldBreaker.trippedCount;
}
this.logger = logger;
if (logger.isTraceEnabled()) {
logger.trace("Creating MemoryCircuitBreaker with a limit of {} bytes ({}) and a overhead constant of {}",
this.memoryBytesLimit, limit, this.overheadConstant);
}
}
示例6: writeObjectToServletOutputStream
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
/**
* Appends the string form of the given JSON object to the body of the given HTTP response using the UTF-8
* charset.
*
* @param obj the object to append
* @param response the http response to which's body the object should be appended
* @throws IOException if there is an error appending the object.
*/
default void writeObjectToServletOutputStream(JSONObject obj, HttpServletResponse response) throws IOException
{
Logger logger = LogManager.getLogger(JsonResponseServlet.class.getName());
logger.debug("entering");
String objAsString = obj.toString(2);
logger.trace("objAsString=" + objAsString);
ByteBuffer byteBuffer = UTF_8.encode(objAsString);
byte[] responseBodyBytes=new byte[byteBuffer.limit()];
byteBuffer.get(responseBodyBytes);
response.getOutputStream().write(responseBodyBytes);
logger.debug("exiting");
}
示例7: MergePolicyConfig
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
MergePolicyConfig(Logger logger, IndexSettings indexSettings) {
this.logger = logger;
double forceMergeDeletesPctAllowed = indexSettings.getValue(INDEX_MERGE_POLICY_EXPUNGE_DELETES_ALLOWED_SETTING); // percentage
ByteSizeValue floorSegment = indexSettings.getValue(INDEX_MERGE_POLICY_FLOOR_SEGMENT_SETTING);
int maxMergeAtOnce = indexSettings.getValue(INDEX_MERGE_POLICY_MAX_MERGE_AT_ONCE_SETTING);
int maxMergeAtOnceExplicit = indexSettings.getValue(INDEX_MERGE_POLICY_MAX_MERGE_AT_ONCE_EXPLICIT_SETTING);
// TODO is this really a good default number for max_merge_segment, what happens for large indices, won't they end up with many segments?
ByteSizeValue maxMergedSegment = indexSettings.getValue(INDEX_MERGE_POLICY_MAX_MERGED_SEGMENT_SETTING);
double segmentsPerTier = indexSettings.getValue(INDEX_MERGE_POLICY_SEGMENTS_PER_TIER_SETTING);
double reclaimDeletesWeight = indexSettings.getValue(INDEX_MERGE_POLICY_RECLAIM_DELETES_WEIGHT_SETTING);
this.mergesEnabled = indexSettings.getSettings()
.getAsBooleanLenientForPreEs6Indices(indexSettings.getIndexVersionCreated(), INDEX_MERGE_ENABLED, true, new DeprecationLogger(logger));
if (mergesEnabled == false) {
logger.warn("[{}] is set to false, this should only be used in tests and can cause serious problems in production environments", INDEX_MERGE_ENABLED);
}
maxMergeAtOnce = adjustMaxMergeAtOnceIfNeeded(maxMergeAtOnce, segmentsPerTier);
mergePolicy.setNoCFSRatio(indexSettings.getValue(INDEX_COMPOUND_FORMAT_SETTING));
mergePolicy.setForceMergeDeletesPctAllowed(forceMergeDeletesPctAllowed);
mergePolicy.setFloorSegmentMB(floorSegment.getMbFrac());
mergePolicy.setMaxMergeAtOnce(maxMergeAtOnce);
mergePolicy.setMaxMergeAtOnceExplicit(maxMergeAtOnceExplicit);
mergePolicy.setMaxMergedSegmentMB(maxMergedSegment.getMbFrac());
mergePolicy.setSegmentsPerTier(segmentsPerTier);
mergePolicy.setReclaimDeletesWeight(reclaimDeletesWeight);
if (logger.isTraceEnabled()) {
logger.trace("using [tiered] merge mergePolicy with expunge_deletes_allowed[{}], floor_segment[{}], max_merge_at_once[{}], max_merge_at_once_explicit[{}], max_merged_segment[{}], segments_per_tier[{}], reclaim_deletes_weight[{}]",
forceMergeDeletesPctAllowed, floorSegment, maxMergeAtOnce, maxMergeAtOnceExplicit, maxMergedSegment, segmentsPerTier, reclaimDeletesWeight);
}
}
示例8: canOpenIndex
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
/**
* Returns <code>true</code> iff the given location contains an index an the index
* can be successfully opened. This includes reading the segment infos and possible
* corruption markers.
*/
public static boolean canOpenIndex(Logger logger, Path indexLocation, ShardId shardId, NodeEnvironment.ShardLocker shardLocker) throws IOException {
try {
tryOpenIndex(indexLocation, shardId, shardLocker, logger);
} catch (Exception ex) {
logger.trace((Supplier<?>) () -> new ParameterizedMessage("Can't open index for path [{}]", indexLocation), ex);
return false;
}
return true;
}
示例9: tryOpenIndex
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
/**
* Tries to open an index for the given location. This includes reading the
* segment infos and possible corruption markers. If the index can not
* be opened, an exception is thrown
*/
public static void tryOpenIndex(Path indexLocation, ShardId shardId, NodeEnvironment.ShardLocker shardLocker, Logger logger) throws IOException, ShardLockObtainFailedException {
try (ShardLock lock = shardLocker.lock(shardId, TimeUnit.SECONDS.toMillis(5));
Directory dir = new SimpleFSDirectory(indexLocation)) {
failIfCorrupted(dir, shardId);
SegmentInfos segInfo = Lucene.readSegmentInfos(dir);
logger.trace("{} loaded segment info [{}]", shardId, segInfo);
}
}
示例10: trace
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
public static void trace(Class<?> clazz, String msg, Throwable t) {
final Logger logger = LogManager.getLogger(clazz);
if (logger.isTraceEnabled()) {
logger.trace(msg, t);
}
}
示例11: testLogs
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
/**
* @author wasiq.bhamla
* @since 17-Jun-2017 6:18:03 PM
*/
@Test
public void testLogs () {
final Logger log = LogManager.getLogger (TestLogging.class);
log.info ("Testing info...");
log.warn ("Testing warn...");
log.error ("Testing error...");
log.debug ("Testing debug...");
log.trace ("Testing trace...");
log.fatal ("Testing fatal...");
}
示例12: getPluginBundles
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
static List<Bundle> getPluginBundles(Path pluginsDirectory) throws IOException {
Logger logger = Loggers.getLogger(PluginsService.class);
// TODO: remove this leniency, but tests bogusly rely on it
if (!isAccessibleDirectory(pluginsDirectory, logger)) {
return Collections.emptyList();
}
List<Bundle> bundles = new ArrayList<>();
try (DirectoryStream<Path> stream = Files.newDirectoryStream(pluginsDirectory)) {
for (Path plugin : stream) {
if (FileSystemUtils.isHidden(plugin)) {
logger.trace("--- skip hidden plugin file[{}]", plugin.toAbsolutePath());
continue;
}
logger.trace("--- adding plugin [{}]", plugin.toAbsolutePath());
final PluginInfo info;
try {
info = PluginInfo.readFromProperties(plugin);
} catch (IOException e) {
throw new IllegalStateException("Could not load plugin descriptor for existing plugin ["
+ plugin.getFileName() + "]. Was the plugin built before 2.0?", e);
}
List<URL> urls = new ArrayList<>();
try (DirectoryStream<Path> jarStream = Files.newDirectoryStream(plugin, "*.jar")) {
for (Path jar : jarStream) {
// normalize with toRealPath to get symlinks out of our hair
urls.add(jar.toRealPath().toUri().toURL());
}
}
final Bundle bundle = new Bundle();
bundles.add(bundle);
bundle.plugins.add(info);
bundle.urls.addAll(urls);
}
}
return bundles;
}
示例13: testLogOutput
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
/**
* Verifies that writing to a Log4j logger will end up in the LogWriter's output.
*/
@Test
public final void testLogOutput() throws IOException {
// Create the appender
final StringWriter stringWriter = new StringWriter();
final PureLogWriter logWriter =
new PureLogWriter(InternalLogWriter.FINEST_LEVEL, new PrintWriter(stringWriter), "");
final AppenderContext[] contexts = new AppenderContext[2];
contexts[0] = LogService.getAppenderContext(); // root context
contexts[1] = LogService.getAppenderContext(LogService.BASE_LOGGER_NAME); // "org.apache"
// context
this.appender =
LogWriterAppender.create(contexts, LogService.MAIN_LOGGER_NAME, logWriter, null);
final Logger logger = LogService.getLogger();
// set the level to TRACE
Configurator.setLevel(LogService.BASE_LOGGER_NAME, Level.TRACE);
Configurator.setLevel(LogService.MAIN_LOGGER_NAME, Level.TRACE);
assertEquals(Level.TRACE, logger.getLevel());
logger.trace("TRACE MESSAGE");
assertTrue(Pattern.compile(".*\\[finest .*TRACE MESSAGE.*", Pattern.DOTALL)
.matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
logger.debug("DEBUG MESSAGE");
assertTrue(Pattern.compile(".*\\[fine .*DEBUG MESSAGE.*", Pattern.DOTALL)
.matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
logger.info("INFO MESSAGE");
assertTrue(Pattern.compile(".*\\[info .*INFO MESSAGE.*", Pattern.DOTALL)
.matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
logger.warn("ExpectedStrings: WARNING MESSAGE");
assertTrue(Pattern.compile(".*\\[warning .*WARNING MESSAGE.*", Pattern.DOTALL)
.matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
logger.error("ExpectedStrings: ERROR MESSAGE");
assertTrue(Pattern.compile(".*\\[error .*ERROR MESSAGE.*", Pattern.DOTALL)
.matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
logger.fatal("ExpectedStrings: FATAL MESSAGE");
assertTrue(Pattern.compile(".*\\[severe .*FATAL MESSAGE.*", Pattern.DOTALL)
.matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
final Logger lowerLevelLogger =
LogService.getLogger(LogService.BASE_LOGGER_NAME + ".subpackage");
lowerLevelLogger.fatal("ExpectedStrings: FATAL MESSAGE");
assertTrue(Pattern.compile(".*\\[severe .*FATAL MESSAGE.*", Pattern.DOTALL)
.matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
this.appender.destroy();
assertFalse(Configurator.getLoggerConfig(LogService.BASE_LOGGER_NAME).getAppenders()
.containsKey(this.appender.getName()));
}