本文整理汇总了Java中org.slf4j.Logger.warn方法的典型用法代码示例。如果您正苦于以下问题:Java Logger.warn方法的具体用法?Java Logger.warn怎么用?Java Logger.warn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.slf4j.Logger
的用法示例。
在下文中一共展示了Logger.warn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: warn
import org.slf4j.Logger; //导入方法依赖的package包/类
public static void warn(Logger log, Throwable th, String msg) {
if (!log.isWarnEnabled()) {
return;
}
// this operation is expensive, hence don't abuse it.
StackTraceElement[] traces = Thread.currentThread().getStackTrace();
if (traces.length > 2) {
StackTraceElement trace = traces[2];
log.warn("({} {}) {}, {}: {}", trace.getMethodName(), trace.getLineNumber(), msg,
th.getClass().getName(), getMessage(th));
} else {
log.warn("{}, {}: {}", msg, th.getClass().getName(), getMessage(th));
}
log.debug(msg, th);
}
示例2: supplyAndLog
import org.slf4j.Logger; //导入方法依赖的package包/类
static <OUTPUT, THROWABLE extends Throwable> OUTPUT supplyAndLog(
Logger log, CheckedSupplier<OUTPUT, THROWABLE> supplier, Supplier<String> name)
throws THROWABLE {
final OUTPUT output;
try {
output = supplier.get();
} catch (Throwable t) {
if (log.isTraceEnabled()) {
log.trace("Failed to " + name.get(), t);
} else if (log.isWarnEnabled()){
log.warn("Failed to " + name.get() + ": " + t);
}
throw (THROWABLE)t;
}
if (log.isTraceEnabled()) {
log.trace("Successfully supplied " + name.get());
}
return output;
}
示例3: attempt
import org.slf4j.Logger; //导入方法依赖的package包/类
/** Attempt to wait the given condition to return true multiple times. */
static void attempt(
BooleanSupplier condition, int numAttempts, long sleepMs, String name, Logger log)
throws InterruptedException {
Objects.requireNonNull(condition, "condition == null");
Preconditions.assertTrue(numAttempts > 0, () -> "numAttempts = " + numAttempts + " <= 0");
Preconditions.assertTrue(sleepMs >= 0L, () -> "sleepMs = " + sleepMs + " < 0");
for(int i = 1; i <= numAttempts; i++) {
if (condition.getAsBoolean()) {
return;
}
if (log != null && log.isWarnEnabled()) {
log.warn("FAILED " + name + " attempt #" + i + "/" + numAttempts
+ ": sleep " + sleepMs + "ms and then retry.");
}
if (sleepMs > 0) {
Thread.sleep(sleepMs);
}
}
if (!condition.getAsBoolean()) {
throw new IllegalStateException("Failed " + name + " for " + numAttempts + " attempts.");
}
}
示例4: getRequestJsonObject
import org.slf4j.Logger; //导入方法依赖的package包/类
protected JsonObject getRequestJsonObject(Logger logger, boolean logFailedRequests) {
JsonObject chart = new JsonObject();
chart.addProperty("chartId", chartId);
try {
JsonObject data = getChartData();
if (data == null) {
// If the data is null we don't send the chart.
return null;
}
chart.add("data", data);
} catch (Throwable t) {
if (logFailedRequests) {
logger.warn("Failed to get data for custom chart with id {}", chartId, t);
}
return null;
}
return chart;
}
示例5: regiesterVIServlet
import org.slf4j.Logger; //导入方法依赖的package包/类
protected static final void regiesterVIServlet(ServletContext context,Logger logger){
try {
ServletRegistration.Dynamic asr = context.addServlet("VIApiServlet", VIApiServlet.class);
if (asr != null) {
asr.setLoadOnStartup(Integer.MAX_VALUE);
asr.addMapping("/@in/api/*");
} else {
logger.warn("Servlet VIApiServlet already exists");
}
ServletRegistration ssr = context.addServlet("VIHttpServlet", StaticContentServlet.class);
if (ssr != null) {
ssr.addMapping("/@in/*");
} else {
logger.warn("Servlet VIHttpServlet already exists");
}
}catch (Throwable e){
logger.error("VI register servlet failed",e);
}
}
示例6: doFinalWriteOf404
import org.slf4j.Logger; //导入方法依赖的package包/类
/**
* 最后成功或异常的输出都调用这里。
*
* @param response
* @param jResponse
*/
private final void doFinalWriteOf404(WRequest request, WResponse response, JResponse jResponse)
{
try
{
Object rs = jResponse;
if (responseHandle != null)
{
rs = responseHandle.toResponseOf404(request, response, jResponse);
}
response.write(rs);
} catch (IOException e)
{
Throwable ex = getCause(e);
Logger LOGGER = logger(null);
LOGGER.warn(ex.getMessage(), ex);
}
}
示例7: execute
import org.slf4j.Logger; //导入方法依赖的package包/类
@Override
public Object execute(String path, String user, int permission, Logger logger, Map<String, Object> params) throws Exception {
Object rtn = "";
AppInfo appInfo = ComponentManager.getStatus(AppInfo.class);
String opPath = path.substring(startPath.length()).toLowerCase();
if(!(user!=null && user.length()>2 && user.equals(appInfo.getAppOwner())) && !"uvtrace".equals(opPath)) {
throw new NoPermissionException();
}
switch (opPath){
case "markdown":
if(!appInfo.isStatusSourceEnabled()){
throw new Exception("can't markdwon. because statusSources be disabled!");
}
OwnerJudge.getInstance().toAbnormal();
logger.warn(user + " markdown the app.");
break;
case "markup":
if(!appInfo.isStatusSourceEnabled()){
throw new Exception("can't markup. because statusSources be disabled!");
}
OwnerJudge.getInstance().toNormal();
logger.warn(user + " markup the app.");
break;
case "enablestatussource":
appInfo.enableStatusSource();
logger.warn(user + " enable statusSources.");
break;
case "disablestatussource":
appInfo.disableStatusSource();
logger.warn(user + " disable statusSources.");
break;
case "uvtrace":
eventLogger.fireEvent(HttpUtil.getJsonParamVal(params.get("name")));
break;
}
return rtn;
}
示例8: logReq
import org.slf4j.Logger; //导入方法依赖的package包/类
/**
* Print logs of http request.
*/
public static void logReq(Logger logger, HttpServletRequest req) {
String queryStr = req.getQueryString();
if (queryStr == null || queryStr.length() == 0) {
logger.info(req.getMethod() + " " + req.getRequestURI());
} else {
try {
queryStr = URLDecoder.decode(queryStr, "UTF-8");
} catch (UnsupportedEncodingException e) {
logger.warn(e.getMessage());
}
logger.info(req.getMethod() + " " + req.getRequestURI() + "?" + queryStr);
}
}
示例9: createNodeInfo
import org.slf4j.Logger; //导入方法依赖的package包/类
@Override
public NodeInfo createNodeInfo(NodeDto node) throws IOException {
if (node == null) {
throw new IllegalArgumentException();
}
Logger log = LoggerFactory.getLogger(getClass());
try {
String ipAddress = DtoUtil.getStringOrNull(node, MPLSNMS_ATTR.MANAGEMENT_IP);
String snmpRO = DtoUtil.getStringOrNull(node, MPLSNMS_ATTR.SNMP_COMMUNITY);
String userName = DtoUtil.getStringOrNull(node, MPLSNMS_ATTR.TELNET_ACCOUNT);
String userPass = DtoUtil.getStringOrNull(node, MPLSNMS_ATTR.TELNET_PASSWORD);
String adminName = DtoUtil.getStringOrNull(node, MPLSNMS_ATTR.ADMIN_ACCOUNT);
String adminPass = DtoUtil.getStringOrNull(node, MPLSNMS_ATTR.ADMIN_PASSWORD);
if (ipAddress == null) {
throw new IllegalStateException("magament ip address is mandatory.");
}
if (snmpRO == null) {
throw new IllegalStateException("SNMP community string (RO) is mandatory.");
}
NodeInfo nodeinfo = new NodeInfo(node.getName());
InetAddress inetAddress = InetAddress.getByAddress(
VossMiscUtility.getByteFormIpAddress(ipAddress));
nodeinfo.addIpAddress(inetAddress);
nodeinfo.setCommunityStringRO(snmpRO);
nodeinfo.setUserAccount(userName);
nodeinfo.setUserPassword(userPass);
nodeinfo.setAdminAccount(adminName);
nodeinfo.setAdminPassword(adminPass);
nodeinfo.addSupportedProtocol(ProtocolPort.SNMP_V2C_GETBULK);
nodeinfo.addSupportedProtocol(ProtocolPort.TELNET);
return nodeinfo;
} catch (UnknownHostException e) {
log.warn("failed to create node-info: " + node.getName(), e);
return null;
}
}
示例10: resetOffsetByTimestamp
import org.slf4j.Logger; //导入方法依赖的package包/类
/**
* Reset consumer topic offset according to time
*
* @param messageModel which model
* @param instanceName which instance
* @param consumerGroup consumer group
* @param topic topic
* @param timestamp time
* @throws Exception
*/
public static void resetOffsetByTimestamp(
final MessageModel messageModel,
final String instanceName,
final String consumerGroup,
final String topic,
final long timestamp) throws Exception {
final Logger log = ClientLogger.getLog();
DefaultMQPullConsumer consumer = new DefaultMQPullConsumer(consumerGroup);
consumer.setInstanceName(instanceName);
consumer.setMessageModel(messageModel);
consumer.start();
Set<MessageQueue> mqs = null;
try {
mqs = consumer.fetchSubscribeMessageQueues(topic);
if (mqs != null && !mqs.isEmpty()) {
TreeSet<MessageQueue> mqsNew = new TreeSet<MessageQueue>(mqs);
for (MessageQueue mq : mqsNew) {
long offset = consumer.searchOffset(mq, timestamp);
if (offset >= 0) {
consumer.updateConsumeOffset(mq, offset);
log.info("resetOffsetByTimestamp updateConsumeOffset success, {} {} {}",
consumerGroup, offset, mq);
}
}
}
} catch (Exception e) {
log.warn("resetOffsetByTimestamp Exception", e);
throw e;
} finally {
if (mqs != null) {
consumer.getDefaultMQPullConsumerImpl().getOffsetStore().persistAll(mqs);
}
consumer.shutdown();
}
}
示例11: canGetArtifact
import org.slf4j.Logger; //导入方法依赖的package包/类
/**
* Determine if the specified driver is capable of taking screenshots.
*
* @param optDriver optional web driver object
* @param logger SLF4J logger object
* @return 'true' if driver can take screenshots; otherwise 'false
*/
public static boolean canGetArtifact(Optional<WebDriver> optDriver, Logger logger) {
if (optDriver.isPresent()) {
WebDriver driver = optDriver.get();
if (driver instanceof TakesScreenshot) {
return true;
} else {
String message = "This driver is not capable of taking a screenshot. If a screenshot is desired, use"
+ " a WebDriver implementation that supports screenshots. For more information, see https://"
+ "seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/TakesScreenshot.html";
logger.warn(message);
}
}
return false;
}
示例12: logErrors
import org.slf4j.Logger; //导入方法依赖的package包/类
public void logErrors(Logger logger) {
if (logger.isErrorEnabled()) {
for (String msg : errors) {
logger.warn("{} invalid: {}", getEntityClass().getSimpleName(), msg);
}
}
}
示例13: validateAndLog
import org.slf4j.Logger; //导入方法依赖的package包/类
public boolean validateAndLog(BlockHeader header, Logger logger) {
ValidationResult result = validate(header);
if (!result.success && logger.isErrorEnabled()) {
logger.warn("{} invalid {}", getEntityClass(), result.error);
}
return result.success;
}
示例14: warn
import org.slf4j.Logger; //导入方法依赖的package包/类
public void warn(Logger log, String message, Throwable e) {
if (printStream != null) {
printStream.println(colored(COLOR_WARNING, "WARNING: " + message + " " + e));
e.printStackTrace(printStream);
} else {
log.warn(message, e);
}
}
示例15: doLog
import org.slf4j.Logger; //导入方法依赖的package包/类
public static void doLog(String s, LogLevel logLevel, Logger logger) {
switch (logLevel) {
case ERROR: {
logger.error(s);
break;
}
case WARN: {
logger.warn(s);
break;
}
case INFO: {
logger.info(s);
break;
}
case DEBUG: {
logger.debug(s);
break;
}
case TRACE: {
logger.trace(s);
break;
}
default: {
logger.error(s);
break;
}
}
}