本文整理了Java中org.slf4j.LoggerFactory.getLogger()
方法的一些代码示例,展示了LoggerFactory.getLogger()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LoggerFactory.getLogger()
方法的具体详情如下:
包路径:org.slf4j.LoggerFactory
类名称:LoggerFactory
方法名:getLogger
[英]Return a logger named corresponding to the class passed as parameter, using the statically bound ILoggerFactory instance.
[中]使用静态绑定的iLogger工厂实例,返回与作为参数传递的类相对应的名为的记录器。
代码示例来源:origin: apache/zookeeper
public static synchronized void setTextTraceLevel(long mask) {
traceMask = mask;
final Logger LOG = LoggerFactory.getLogger(ZooTrace.class);
LOG.info("Set text trace mask to 0x" + Long.toHexString(mask));
}
代码示例来源:origin: apache/zeppelin
private void logException(Exception e) {
Logger logger = LoggerFactory.getLogger(Resource.class);
logger.error(e.getMessage(), e);
}
代码示例来源:origin: apache/nifi
@Override
public void log(int level, String message) {
LoggerFactory.getLogger(SFTPTransfer.class).debug("SFTP Log: {}", message);
}
});
代码示例来源:origin: SonarSource/sonarqube
@Test
public void testNoStdout() throws UnsupportedEncodingException {
System.setOut(new PrintStream(out, false, StandardCharsets.UTF_8.name()));
conf.setLogOutput(listener);
LoggingConfigurator.apply(conf);
Logger logger = LoggerFactory.getLogger(this.getClass());
logger.error(TEST_STR);
logger.info(TEST_STR);
logger.debug(TEST_STR);
assertThat(out.size()).isEqualTo(0);
}
代码示例来源:origin: thinkaurelius/titan
/**
* Create a {@link Slf4jReporter} attached to the Titan Metrics registry.
* <p>
* If {@code loggerName} is null, or if it is non-null but
* {@link LoggerFactory#getLogger(loggerName)} returns null, then Metrics's
* default Slf4j logger name is used instead.
*
* @param reportInterval
* time to wait between writing metrics to the Slf4j
* logger
* @param loggerName
* the name of the Slf4j logger that receives metrics
*/
public synchronized void addSlf4jReporter(Duration reportInterval, String loggerName) {
if (null != slf4jReporter) {
log.debug("Metrics Slf4jReporter already active; not creating another");
return;
}
Slf4jReporter.Builder b = Slf4jReporter.forRegistry(getRegistry());
if (null != loggerName) {
Logger l = LoggerFactory.getLogger(loggerName);
if (null != l) {
b.outputTo(l);
} else {
log.error("Logger with name {} could not be obtained", loggerName);
}
}
slf4jReporter = b.build();
slf4jReporter.start(reportInterval.toMillis(), TimeUnit.MILLISECONDS);
}
代码示例来源:origin: SonarSource/sonarqube
private void checkRecommendedParameter(String url, String val) {
if (!url.contains(val)) {
LoggerFactory.getLogger(getClass()).warn("JDBC URL is recommended to have the property '{}'", val);
}
}
}
代码示例来源:origin: apache/nifi
@Override
public void run() {
final Logger stdOutLogger = LoggerFactory.getLogger("org.apache.nifi.StdOut");
final InputStream in = process.getInputStream();
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
String line;
while ((line = reader.readLine()) != null) {
stdOutLogger.info(line);
}
} catch (IOException e) {
defaultLogger.error("Failed to read from NiFi's Standard Out stream", e);
}
}
});
代码示例来源:origin: alibaba/jstorm
Package logbackPackage = Package.getPackage(LOGBACK_CLASSIC);
if (logbackPackage == null) {
LOG.warn("Logback is not in the classpath!");
return false;
Logger loggerObtained = LoggerFactory.getLogger(loggerName);
if (loggerObtained == null) {
LOG.warn("No logger for the name: {}", loggerName);
return false;
LOG.warn("No such log level: {}", logLevelUpper);
return false;
method.invoke(loggerObtained, params);
LOG.info("LogBack level set to {} for the logger '{}'", logLevelUpper, loggerName);
return true;
} catch (NoClassDefFoundError e) {
代码示例来源:origin: igniterealtime/Openfire
final String id ) throws DocumentException, IOException, XmlPullParserException
final Logger log = LoggerFactory.getLogger(Log.getName() + "[Authenticate connection for: " + localDomain + " to: " + remoteDomain + "]" );
log.debug("Remote server is offering dialback: {}, EXTERNAL SASL: {}", dialbackOffered, saslEXTERNALoffered );
log.debug( "Trying to authenticate with EXTERNAL SASL." );
result = attemptSASLexternal(connection, xpp, reader, localDomain, remoteDomain, id, openingStream);
if (result == null) {
log.debug( "Failed to authenticate with EXTERNAL SASL." );
} else {
log.debug( "Successfully authenticated with EXTERNAL SASL." );
return result;
} else {
log.warn( "Unable to secure and authenticate connection: Exhausted all options." );
return null;
代码示例来源:origin: org.apache.logging.log4j/log4j-slf4j-impl
@Test
public void testClassLogger() throws Exception {
final ListAppender app = ctx.getListAppender("Class").clear();
final Logger logger = LoggerFactory.getLogger("ClassLogger");
logger.info("Ignored message contents.");
logger.warn("Verifying the caller class is still correct.");
logger.error("Hopefully nobody breaks me!");
final List<String> messages = app.getMessages();
assertEquals("Incorrect number of messages.", 3, messages.size());
for (final String message : messages) {
assertEquals("Incorrect caller class name.", this.getClass().getName(), message);
}
}
代码示例来源:origin: org.apache.zookeeper/zookeeper
public static void setTextTraceLevel(long mask) {
traceMask = mask;
Logger LOG = LoggerFactory.getLogger(ZooTrace.class);
LOG.info("Set text trace mask to 0x" + Long.toHexString(mask));
}
代码示例来源:origin: com.zaxxer/HikariCP
/** {@inheritDoc} */
@Override
public void execute(Runnable command)
{
try {
command.run();
}
catch (Exception t) {
LoggerFactory.getLogger(PoolBase.class).debug("Failed to execute: {}", command, t);
}
}
}
代码示例来源:origin: apache/activemq
protected void logError(Object service, Throwable e) {
Logger log = LoggerFactory.getLogger(service.getClass());
log.error("Could not stop service: " + service + ". Reason: " + e, e);
}
代码示例来源:origin: JanusGraph/janusgraph
/**
* Create a {@link Slf4jReporter} attached to the JanusGraph Metrics registry.
* <p>
* If {@code loggerName} is null, or if it is non-null but
* {@link LoggerFactory#getLogger(Class loggerName)} returns null, then Metrics's
* default Slf4j logger name is used instead.
*
* @param reportInterval
* time to wait between writing metrics to the Slf4j
* logger
* @param loggerName
* the name of the Slf4j logger that receives metrics
*/
public synchronized void addSlf4jReporter(Duration reportInterval, String loggerName) {
if (null != slf4jReporter) {
log.debug("Metrics Slf4jReporter already active; not creating another");
return;
}
Slf4jReporter.Builder b = Slf4jReporter.forRegistry(getRegistry());
if (null != loggerName) {
Logger l = LoggerFactory.getLogger(loggerName);
if (null != l) {
b.outputTo(l);
} else {
log.error("Logger with name {} could not be obtained", loggerName);
}
}
slf4jReporter = b.build();
slf4jReporter.start(reportInterval.toMillis(), TimeUnit.MILLISECONDS);
}
代码示例来源:origin: SonarSource/sonarqube
/**
* Unregister a MBean from JMX server. Errors are ignored and logged as warnings.
*/
public static void unregister(String name) {
try {
ManagementFactory.getPlatformMBeanServer().unregisterMBean(new ObjectName(name));
} catch (Exception e) {
LoggerFactory.getLogger(Jmx.class).warn("Can not unregister MBean [{}]", name, e);
}
}
}
代码示例来源:origin: Netflix/servo
Logger logger = LoggerFactory.getLogger(Pollers.class);
for (int i = 0; i < periods.length; ++i) {
String period = periods[i];
result[i] = Long.parseLong(period);
if (result[i] <= 0) {
logger.error("Invalid polling interval: {} must be positive.", period);
errors = true;
logger.error("Cannot parse '{}' as a long: {}", period, e.getMessage());
errors = true;
logger.info("Using a default configuration for poller intervals: {}",
join(DEFAULT_PERIODS));
return DEFAULT_PERIODS;
代码示例来源:origin: elastic/elasticsearch-hadoop
private void initInnerTapIfNotSet(Object target, String hadoopTypeName) {
if (actualTap != null) {
return;
}
Class<?> clz = null;
try {
clz = Class.forName(hadoopTypeName, false, getClass().getClassLoader());
if (clz.isInstance(target)) {
runningInHadoop = true;
}
} catch (ClassNotFoundException e) {
runningInHadoop = false;
}
actualTap = (runningInHadoop ? new EsHadoopTap(host, port, resource, query, fields, props) : new EsLocalTap(host, port, resource, query, fields, props));
setScheme(actualTap.getScheme());
if (log.isDebugEnabled()) {
log.debug(String.format("Detected %s environment; initializing [%s]", (runningInHadoop ? "Hadoop" : "local"), actualTap.getClass().getSimpleName()));
}
// use SLF4J just like Cascading
if (!logVersion) {
logVersion = true;
Logger esTapLogger = LoggerFactory.getLogger(EsTap.class);
esTapLogger.info(String.format("Elasticsearch Hadoop %s initialized", Version.version()));
esTapLogger.warn("ES-Hadoop Cascading Integration is Deprecated as of 6.6.0 and will be removed in a later release.");
}
}
}
代码示例来源:origin: igniterealtime/Openfire
final Logger log = LoggerFactory.getLogger( Log.getName() + "[Acting as Originating Server: Authenticate domain: " + localDomain + " with RS: " + remoteDomain + " (id: " + id + ")]" );
log.debug( "Authenticating domain ..." );
log.debug( "Sending dialback key and wait for the validation response..." );
StringBuilder sb = new StringBuilder();
sb.append("<db:result");
Element doc = socketReader.getElement(RemoteServerManager.getSocketTimeout(), TimeUnit.MILLISECONDS);
if (doc == null) {
log.debug( "Failed to authenticate domain: Time out waiting for validation response." );
return false;
log.warn( "Ignoring unexpected answer while waiting for dialback validation: " + doc.asXML() );
代码示例来源:origin: igniterealtime/Openfire
final Logger log = LoggerFactory.getLogger( Log.getName() + "[Acting as Originating Server: Create Outgoing Session from: " + localDomain + " to RS at: " + remoteDomain + " (port: " + port+ ")]" );
log.debug( "Creating new outgoing session..." );
log.info( "Unable to create new outgoing session: Cannot create a plain socket connection with any applicable remote host." );
return null;
log.debug( "Send the stream header and wait for response..." );
StringBuilder stream = new StringBuilder();
stream.append("<stream:stream");
eventType = xpp.next();
log.debug( "Got a response. Check if the remote server supports dialback..." );
log.error( "An exception occurred while creating outgoing session to remote server:", e );
log.warn( "Unable to create a new outgoing session" );
return null;
代码示例来源:origin: javamelody/javamelody
/** {@inheritDoc} */
@Override
public void logHttpRequest(HttpServletRequest httpRequest, String requestName, long duration,
boolean systemError, int responseSize, String loggerName) {
final Logger logger = org.slf4j.LoggerFactory.getLogger(loggerName);
if (logger.isInfoEnabled()) {
logger.info(LOG.buildLogMessage(httpRequest, duration, systemError, responseSize));
}
}
}
内容来源于网络,如有侵权,请联系作者删除!