本文整理汇总了Java中org.apache.logging.log4j.Logger.warn方法的典型用法代码示例。如果您正苦于以下问题:Java Logger.warn方法的具体用法?Java Logger.warn怎么用?Java Logger.warn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.logging.log4j.Logger
的用法示例。
在下文中一共展示了Logger.warn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: logGcOverhead
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
static void logGcOverhead(
final Logger logger,
final JvmMonitor.Threshold threshold,
final long current,
final long elapsed,
final long seq) {
switch (threshold) {
case WARN:
if (logger.isWarnEnabled()) {
logger.warn(OVERHEAD_LOG_MESSAGE, seq, TimeValue.timeValueMillis(current), TimeValue.timeValueMillis(elapsed));
}
break;
case INFO:
if (logger.isInfoEnabled()) {
logger.info(OVERHEAD_LOG_MESSAGE, seq, TimeValue.timeValueMillis(current), TimeValue.timeValueMillis(elapsed));
}
break;
case DEBUG:
if (logger.isDebugEnabled()) {
logger.debug(OVERHEAD_LOG_MESSAGE, seq, TimeValue.timeValueMillis(current), TimeValue.timeValueMillis(elapsed));
}
break;
}
}
示例4: test03
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
@Test
public void test03() {
// Logger logger = LogManager.getFormatterLogger();
Logger logger = LogManager.getLogger();
String name = "李志伟";
Date birthday = new Date();
logger.debug("用户名称:[{}], 日期:[{}]", name, birthday);
logger.info("用户名称:[{}], 日期:[{}]", name, birthday);
logger.warn("用户名称:[{}], 日期:[{}]", name, birthday);
logger.error("用户名称:[{}], 日期:[{}]", name, birthday);
logger.fatal("用户名称:[{}], 日期:[{}]", name, birthday);
logger.error("异常信息提示", new RuntimeException("异常信息"));
LogManager.shutdown();
}
示例5: applyAccessControlHeaderIfAllowed
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
/**
* If the given request's origin is present and a member of the allowed origins as decided by corsHeaderSetter
* sets the response Access-Control-Allow-Origin header to the request's origin.
*
* If not, sets the response code to 403 via resp.
*
* @param req the http request
* @param resp the http response
* @param corsHeaderSetter the source of truth on allowed origins
* @return whether req represents a request from an allowed origin.
*/
default boolean applyAccessControlHeaderIfAllowed(HttpServletRequest req, HttpServletResponse resp,
CorsHeaderSetter corsHeaderSetter)
{
Logger _logger = LogManager.getLogger(CorsAwareServlet.class.getName());
_logger.debug("entering");
// only allow CORS processing from origins we approve
boolean requestFromAllowedOrigin = corsHeaderSetter.applyAccessControlHeaderIfAllowed(req, resp);
if(!requestFromAllowedOrigin)
{
resp.setStatus(HttpStatus.FORBIDDEN_403);
_logger.warn("request from unauthorized origin.");
}
_logger.debug("exiting");
return requestFromAllowedOrigin;
}
示例6: validateStateIsFromCurrentMaster
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
/**
* In the case we follow an elected master the new cluster state needs to have the same elected master
* This method checks for this and throws an exception if needed
*/
public static void validateStateIsFromCurrentMaster(Logger logger, DiscoveryNodes currentNodes, ClusterState newClusterState) {
if (currentNodes.getMasterNodeId() == null) {
return;
}
if (!currentNodes.getMasterNodeId().equals(newClusterState.nodes().getMasterNodeId())) {
logger.warn("received a cluster state from a different master than the current one, rejecting (received {}, current {})", newClusterState.nodes().getMasterNode(), currentNodes.getMasterNode());
throw new IllegalStateException("cluster state from a different master than the current one, rejecting (received " + newClusterState.nodes().getMasterNode() + ", current " + currentNodes.getMasterNode() + ")");
}
}
示例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: loadShardPath
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
/**
* This method walks through the nodes shard paths to find the data and state path for the given shard. If multiple
* directories with a valid shard state exist the one with the highest version will be used.
* <b>Note:</b> this method resolves custom data locations for the shard.
*/
public static ShardPath loadShardPath(Logger logger, NodeEnvironment env, ShardId shardId, IndexSettings indexSettings) throws IOException {
final String indexUUID = indexSettings.getUUID();
final Path[] paths = env.availableShardPaths(shardId);
Path loadedPath = null;
for (Path path : paths) {
// EMPTY is safe here because we never call namedObject
ShardStateMetaData load = ShardStateMetaData.FORMAT.loadLatestState(logger, NamedXContentRegistry.EMPTY, path);
if (load != null) {
if (load.indexUUID.equals(indexUUID) == false && IndexMetaData.INDEX_UUID_NA_VALUE.equals(load.indexUUID) == false) {
logger.warn("{} found shard on path: [{}] with a different index UUID - this shard seems to be leftover from a different index with the same name. Remove the leftover shard in order to reuse the path with the current index", shardId, path);
throw new IllegalStateException(shardId + " index UUID in shard state was: " + load.indexUUID + " expected: " + indexUUID + " on shard path: " + path);
}
if (loadedPath == null) {
loadedPath = path;
} else{
throw new IllegalStateException(shardId + " more than one shard state found");
}
}
}
if (loadedPath == null) {
return null;
} else {
final Path dataPath;
final Path statePath = loadedPath;
if (indexSettings.hasCustomDataPath()) {
dataPath = env.resolveCustomLocation(indexSettings, shardId);
} else {
dataPath = statePath;
}
logger.debug("{} loaded data path [{}], state path [{}]", shardId, dataPath, statePath);
return new ShardPath(indexSettings.hasCustomDataPath(), dataPath, statePath, shardId);
}
}
示例9: parseVersion
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
public static Version parseVersion(@Nullable String version, Version defaultVersion, Logger logger) {
if (version == null) {
return defaultVersion;
}
try {
return Version.parse(version);
} catch (ParseException e) {
logger.warn((Supplier<?>) () -> new ParameterizedMessage("no version match {}, default to {}", version, defaultVersion), e);
return defaultVersion;
}
}
示例10: warnIfPreRelease
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
static void warnIfPreRelease(final Version version, final boolean isSnapshot, final Logger logger) {
if (!version.isRelease() || isSnapshot) {
logger.warn(
"version [{}] is a pre-release version of Elasticsearch and is not suitable for production",
displayVersion(version, isSnapshot));
}
}
示例11: test04
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
@Test
public void test04() {
Logger logger = LogManager.getLogger();
String name = "李志伟";
Date birthday = new Date();
for (int i = 0; i < 10000; i++) {
logger.debug("次数[{}] 用户名称:[{}], 日期:[{}]", i, name, birthday);
logger.info("次数[{}] 用户名称:[{}], 日期:[{}]", i, name, birthday);
logger.warn("次数[{}] 用户名称:[{}], 日期:[{}]", i, name, birthday);
logger.error("次数[{}] 用户名称:[{}], 日期:[{}]", i, name, birthday);
logger.fatal("次数[{}] 用户名称:[{}], 日期:[{}]", i, name, birthday);
}
LogManager.shutdown();
}
示例12: getAvailableMemory
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
/**
* Returns the available system memory (free + cached).
*
* @param logger the logger
* @return the available memory in bytes
*/
public static long getAvailableMemory(Logger logger) {
try {
BufferedReader br =
new BufferedReader(new InputStreamReader(new FileInputStream("/proc/meminfo")));
try {
long free = 0;
Pattern p = Pattern.compile("(.*)?:\\s+(\\d+)( kB)?");
String line;
while ((line = br.readLine()) != null) {
Matcher m = p.matcher(line);
if (m.matches() && ("MemFree".equals(m.group(1)) || "Cached".equals(m.group(1)))) {
free += Long.parseLong(m.group(2));
}
}
// convert to bytes
return 1024 * free;
} finally {
br.close();
}
} catch (IOException e) {
logger.warn("Error determining free memory", e);
return Long.MAX_VALUE;
}
}
示例13: 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...");
}
示例14: logSlowGc
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
static void logSlowGc(
final Logger logger,
final JvmMonitor.Threshold threshold,
final long seq,
final JvmMonitor.SlowGcEvent slowGcEvent,
BiFunction<JvmStats, JvmStats, String> pools) {
final String name = slowGcEvent.currentGc.getName();
final long elapsed = slowGcEvent.elapsed;
final long totalGcCollectionCount = slowGcEvent.currentGc.getCollectionCount();
final long currentGcCollectionCount = slowGcEvent.collectionCount;
final TimeValue totalGcCollectionTime = slowGcEvent.currentGc.getCollectionTime();
final TimeValue currentGcCollectionTime = slowGcEvent.collectionTime;
final JvmStats lastJvmStats = slowGcEvent.lastJvmStats;
final JvmStats currentJvmStats = slowGcEvent.currentJvmStats;
final ByteSizeValue maxHeapUsed = slowGcEvent.maxHeapUsed;
switch (threshold) {
case WARN:
if (logger.isWarnEnabled()) {
logger.warn(
SLOW_GC_LOG_MESSAGE,
name,
seq,
totalGcCollectionCount,
currentGcCollectionTime,
currentGcCollectionCount,
TimeValue.timeValueMillis(elapsed),
currentGcCollectionTime,
totalGcCollectionTime,
lastJvmStats.getMem().getHeapUsed(),
currentJvmStats.getMem().getHeapUsed(),
maxHeapUsed,
pools.apply(lastJvmStats, currentJvmStats));
}
break;
case INFO:
if (logger.isInfoEnabled()) {
logger.info(
SLOW_GC_LOG_MESSAGE,
name,
seq,
totalGcCollectionCount,
currentGcCollectionTime,
currentGcCollectionCount,
TimeValue.timeValueMillis(elapsed),
currentGcCollectionTime,
totalGcCollectionTime,
lastJvmStats.getMem().getHeapUsed(),
currentJvmStats.getMem().getHeapUsed(),
maxHeapUsed,
pools.apply(lastJvmStats, currentJvmStats));
}
break;
case DEBUG:
if (logger.isDebugEnabled()) {
logger.debug(
SLOW_GC_LOG_MESSAGE,
name,
seq,
totalGcCollectionCount,
currentGcCollectionTime,
currentGcCollectionCount,
TimeValue.timeValueMillis(elapsed),
currentGcCollectionTime,
totalGcCollectionTime,
lastJvmStats.getMem().getHeapUsed(),
currentJvmStats.getMem().getHeapUsed(),
maxHeapUsed,
pools.apply(lastJvmStats, currentJvmStats));
}
break;
}
}
示例15: onNonFatalUncaught
import org.apache.logging.log4j.Logger; //导入方法依赖的package包/类
void onNonFatalUncaught(final String threadName, final Throwable t) {
final Logger logger = Loggers.getLogger(ElasticsearchUncaughtExceptionHandler.class, loggingPrefixSupplier.get());
logger.warn((org.apache.logging.log4j.util.Supplier<?>)
() -> new ParameterizedMessage("uncaught exception in thread [{}]", threadName), t);
}