本文整理汇总了Java中org.slf4j.LoggerFactory.getLogger方法的典型用法代码示例。如果您正苦于以下问题:Java LoggerFactory.getLogger方法的具体用法?Java LoggerFactory.getLogger怎么用?Java LoggerFactory.getLogger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.slf4j.LoggerFactory
的用法示例。
在下文中一共展示了LoggerFactory.getLogger方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: outputFile
import org.slf4j.LoggerFactory; //导入方法依赖的package包/类
private static void outputFile(List<Resource> resList,
Properties properties) throws IOException, URISyntaxException {
//不可以作为class的变量初始化,因为在outputFile前一句log机制才初始化完成的
//must create org.slf4j.impl.Log4jLoggerAdapter by LoggerExtFactory
//in order to redefine Log4jLoggerAdapter before other class load Log4jLoggerAdapter
Logger log = LoggerFactory.getLogger(Log4jUtils.class);
String content = genFileContext(resList, properties);
//不打印配置信息,有密钥等敏感信息
//log.info("Merged log4j:\n{}", content);
Resource res = resList.get(resList.size() - 1);
// 不能直接使用res.getFile,因为jar里面的资源,getFile会抛异常
File file = new File(res.getURL().getPath());
if (!file.getParentFile().canWrite()) {
log.error("Can not output {},because can not write to directory of file {}",
MERGED_FILE,
res.getURL().getPath());
return;
}
File mergedfile = new File(res.getFile().getParentFile(), MERGED_FILE);
FileUtils.writeStringToFile(mergedfile, content);
log.info("Write merged log4j config file to {}", mergedfile.getAbsolutePath());
}
示例2: main
import org.slf4j.LoggerFactory; //导入方法依赖的package包/类
public static void main(String[] args) {
/**
* 1.测试{@linkplain cn.xishan.oftenporter.porter.core.annotation.Mixin},自己混入自己
*/
final Logger logger = LoggerFactory.getLogger(MainMixinLoop4.class);
LocalMain localMain = new LocalMain(true, new PName("P1"), "utf-8");
// 进行配置
PorterConf conf = localMain.newPorterConf();
conf.setContextName("MainMixinLoop4");
conf.getSeekPackages().addClassPorter(Root4Porter.class);
localMain.startOne(conf);
logger.debug("****************************************************");
logger.debug("****************************************************");
localMain.destroyAll();
}
示例3: ping
import org.slf4j.LoggerFactory; //导入方法依赖的package包/类
public static boolean ping(int port, final String expectedMsg) {
boolean beaconExists = false;
try {
Socket socket = new Socket("localhost", port);
final BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
final OutputStream output = socket.getOutputStream();
output.write("ping\n".getBytes());
String response = reader.readLine();
beaconExists = response.equals(expectedMsg);
socket.close();
}
catch (Exception e) {
Logger log = LoggerFactory.getLogger(ActiveAppPinger.class);
if (log.isDebugEnabled()) {
log.debug("Failed to connect to port " + port, e);
}
}
return beaconExists;
}
示例4: onCreate
import org.slf4j.LoggerFactory; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
StaticLoggerBinder.init(this);
log = LoggerFactory.getLogger(DbSyncApplication.class);
log.info("onCreate");
db1OpenHelper = new Db1OpenHelper(this);
db1OpenHelper.getReadableDatabase();
db2OpenHelper = new Db2OpenHelper(this);
db2OpenHelper.getReadableDatabase();
db3OpenHelper = new Db3OpenHelper(this);
db3OpenHelper.getReadableDatabase();
db4OpenHelper = new Db4OpenHelper(this);
db4OpenHelper.getReadableDatabase();
db5OpenHelper = new Db5OpenHelper(this);
db5OpenHelper.getReadableDatabase();
}
示例5: testWriteXxxxxResult
import org.slf4j.LoggerFactory; //导入方法依赖的package包/类
@Test
public void testWriteXxxxxResult() throws TechnicalException {
final OutputConsoleDataProvider outputConsoleDataProvider = new OutputConsoleDataProvider();
outputConsoleDataProvider.prepare("hello");
Assert.assertTrue(true);
Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
final TestAppender<ILoggingEvent> appender = new TestAppender<>();
appender.start();
logger.addAppender(appender);
outputConsoleDataProvider.writeFailedResult(1, "UT Failed Message");
List<ILoggingEvent> log = appender.getLog();
Assert.assertEquals(Level.ERROR, log.get(0).getLevel());
Assert.assertTrue(log.get(0).getMessage().toString().endsWith(String.format(Messages.getMessage("OUTPUT_CONSOLE_DATA_PROVIDER_FAILED_AT_LINE"), 1, "UT Failed Message")));
outputConsoleDataProvider.writeSuccessResult(2);
log = appender.getLog();
Assert.assertEquals(Level.INFO, log.get(1).getLevel());
Assert.assertTrue(log.get(1).getMessage().toString().endsWith(String.format(Messages.getMessage("OUTPUT_CONSOLE_DATA_PROVIDER_SUCCESS_AT_LINE"), 2)));
outputConsoleDataProvider.writeWarningResult(3, "UT Warning Message");
log = appender.getLog();
Assert.assertEquals(Level.WARN, log.get(2).getLevel());
Assert.assertTrue(log.get(2).getMessage().toString().endsWith(String.format(Messages.getMessage("OUTPUT_CONSOLE_DATA_PROVIDER_WARNING_AT_LINE"), 3, "UT Warning Message")));
outputConsoleDataProvider.writeDataResult("title", 4, "UT title");
log = appender.getLog();
Assert.assertEquals(Level.INFO, log.get(3).getLevel());
Assert.assertTrue(log.get(3).getMessage().toString().endsWith(String.format(Messages.getMessage("OUTPUT_CONSOLE_DATA_PROVIDER_RESULT_AT_LINE"), 4, "title", "UT title")));
}
示例6: springLogging
import org.slf4j.LoggerFactory; //导入方法依赖的package包/类
@Bean
@ConditionalOnClass(Logger.class)
public CommonsRequestLoggingFilter springLogging() {
Logger logger = (Logger) LoggerFactory.getLogger(CommonsRequestLoggingFilter.class);
logger.setLevel(Level.DEBUG);
log.info("Http logging enabled {}.", properties);
return requestLoggingFilter();
}
示例7: toStringTestTest
import org.slf4j.LoggerFactory; //导入方法依赖的package包/类
@Test
public void toStringTestTest() throws Exception {
Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
LoggerVM vm = new LoggerVM(logger);
assertTrue(vm.toString().startsWith(LoggerVM.class.getSimpleName()));
String json = vm.toString().replace(LoggerVM.class.getSimpleName(), "");
assertTrue(TestUtils.isValid(json));
}
示例8: TextAreaLogAppender
import org.slf4j.LoggerFactory; //导入方法依赖的package包/类
public TextAreaLogAppender(TextArea textArea) {
this.textArea = textArea;
logger = (Logger) LoggerFactory.getLogger("com.intuit.karate");
setName("karate-ui");
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
setContext(lc);
encoder = new PatternLayoutEncoder();
encoder.setPattern("%d{HH:mm:ss.SSS} %-5level - %msg%n");
encoder.setContext(context);
encoder.start();
start();
logger.addAppender(this);
logger.setLevel(Level.DEBUG);
}
示例9: parsed
import org.slf4j.LoggerFactory; //导入方法依赖的package包/类
@Override
public Ethernet parsed() {
checkPermission(PACKET_READ);
try {
return Ethernet.deserializer().deserialize(pktin.getData(), 0, pktin.getData().length);
} catch (BufferUnderflowException | NullPointerException |
DeserializationException e) {
Logger log = LoggerFactory.getLogger(getClass());
log.error("packet deserialization problem : {}", e.getMessage());
return null;
}
}
示例10: reInitLogConfig
import org.slf4j.LoggerFactory; //导入方法依赖的package包/类
/**
* 根据配置文件路径初始化日志配置
* @param logConfigpath
*/
public static void reInitLogConfig(String logConfigpath)
{
try {
LoggerContext context =(LoggerContext)LogManager.getContext(false);
context.setConfigLocation(new File(logConfigpath).toURI());
context.reconfigure(); //重新初始化Log4j2的配置上下文
Logger log=LoggerFactory.getLogger(Log4jUtil.class);
log.info("日志配置重新初始化完成:"+logConfigpath);
} catch (Exception e) {
e.printStackTrace();
}
}
示例11: changeMode
import org.slf4j.LoggerFactory; //导入方法依赖的package包/类
public String changeMode(String changingMode) throws IOException, ConsoleException {
Logger log = LoggerFactory.getLogger(getClass());
log.debug("mode-change: " + this.currentMode + " to " + changingMode);
if (MODE_ENABLE.equals(currentMode) && changingMode.startsWith(MODE_CONFIG)) {
sendln("config");
currentMode = changingMode;
return translate(receiveToPrompt());
} else if (currentMode.startsWith(MODE_CONFIG) && changingMode.startsWith(MODE_ENABLE)) {
sendln("exit");
currentMode = changingMode;
return translate(receiveToPrompt());
} else {
return "";
}
}
示例12: getLevelTest
import org.slf4j.LoggerFactory; //导入方法依赖的package包/类
@Test
public void getLevelTest() throws Exception {
LoggerVM vm = new LoggerVM();
assertNull(vm.getLevel());
Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
vm = new LoggerVM(logger);
assertEquals(Level.ERROR.toString(), vm.getLevel());
}
示例13: ProductServiceImpl
import org.slf4j.LoggerFactory; //导入方法依赖的package包/类
@Autowired
public ProductServiceImpl(ProductRepository productRepository, SupplierRepository supplierRepository) {
this.logger = LoggerFactory.getLogger(this.getClass());
this.productRepository = productRepository;
this.supplierRepository = supplierRepository;
}
示例14: setupLogging
import org.slf4j.LoggerFactory; //导入方法依赖的package包/类
protected void setupLogging() {
addSampleLogger(loggerName);
logger = LoggerFactory.getLogger(loggerName);
}
示例15: log
import org.slf4j.LoggerFactory; //导入方法依赖的package包/类
private static Logger log() {
if (logger == null) {
logger = LoggerFactory.getLogger(Util.class);
}
return logger;
}