本文整理汇总了Java中ch.qos.logback.classic.LoggerContext.getLogger方法的典型用法代码示例。如果您正苦于以下问题:Java LoggerContext.getLogger方法的具体用法?Java LoggerContext.getLogger怎么用?Java LoggerContext.getLogger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ch.qos.logback.classic.LoggerContext
的用法示例。
在下文中一共展示了LoggerContext.getLogger方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testUdpSender
import ch.qos.logback.classic.LoggerContext; //导入方法依赖的package包/类
@Test
public void testUdpSender() throws JoranException, InterruptedException {
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(context);
context.reset();
configurator.doConfigure(this.getClass().getClassLoader().getResourceAsStream("logback-syslog-udp.xml"));
Logger logger = context.getLogger("test-udp");
logger.info("test message over udp");
context.stop();
Thread.sleep(100);
final String serverData = serverStream.toString();
assertTrue("Server received: " + serverData, serverData.contains("test message over udp"));
}
示例2: testTcpSender
import ch.qos.logback.classic.LoggerContext; //导入方法依赖的package包/类
@Test
public void testTcpSender() throws JoranException, InterruptedException {
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(context);
context.reset();
configurator.doConfigure(this.getClass().getClassLoader().getResourceAsStream("logback-syslog-tcp.xml"));
Logger logger = context.getLogger("test-tcp");
logger.info("test message over tcp");
context.stop();
Thread.sleep(100);
final String serverData = serverStream.toString();
assertTrue("Server received: " + serverData, serverData.contains("test message over tcp"));
}
示例3: testTlsSender
import ch.qos.logback.classic.LoggerContext; //导入方法依赖的package包/类
@Test
public void testTlsSender() throws JoranException, InterruptedException {
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(context);
context.reset();
configurator.doConfigure(this.getClass().getClassLoader().getResourceAsStream("logback-syslog-tls.xml"));
Logger logger = context.getLogger("test-tls");
logger.info("test message over tls");
context.stop();
Thread.sleep(100);
final String serverData = serverStream.toString();
assertTrue("Server received: " + serverData, serverData.contains("test message over tls"));
}
示例4: setUp
import ch.qos.logback.classic.LoggerContext; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
registry = RegistryService.getMetricRegistry();
TagEncodedMetricName rootName = APPENDS_BASE_NAME;
TagEncodedMetricName throwablesBaseName = THROWABLES_BASE_NAME;
meters = new HashMap<>();
meters.put("total", getMeter(rootName.submetric("total")));
meters.put("trace", getMeter(rootName.withTags("level", "trace")));
meters.put("debug", getMeter(rootName.withTags("level", "debug")));
meters.put("info", getMeter(rootName.withTags("level", "info")));
meters.put("warn", getMeter(rootName.withTags("level", "warn")));
meters.put("error", getMeter(rootName.withTags("level", "error")));
meters.put("throwCount", getMeter(throwablesBaseName.submetric("total")));
meters.put("throw[RuntimeException]",
getMeter(throwablesBaseName.withTags("class", RuntimeException.class.getName())
));
LoggerContext context = new LoggerContext();
logger = context.getLogger(LogbackInstrumentationTest.class);
origLevel = logger.getLevel();
logger.setLevel(Level.ALL);
}
示例5: configure
import ch.qos.logback.classic.LoggerContext; //导入方法依赖的package包/类
@Override
public void configure(final LoggerContext lc) {
final ConsoleAppender<ILoggingEvent> ca = new ConsoleAppender<>();
ca.setContext(lc);
ca.setName("console");
final LayoutWrappingEncoder<ILoggingEvent> encoder = new LayoutWrappingEncoder<>();
encoder.setContext(lc);
final TTLLLayout layout = new TTLLLayout();
layout.setContext(lc);
layout.start();
encoder.setLayout(layout);
ca.setEncoder(encoder);
ca.start();
final Logger rootLogger = lc.getLogger("ROOT");
rootLogger.setLevel(Level.WARN);
rootLogger.addAppender(ca);
}
示例6: init
import ch.qos.logback.classic.LoggerContext; //导入方法依赖的package包/类
@Before
public void init()
{
LoggerContext ctx = (LoggerContext) LoggerFactory.getILoggerFactory();
ctx.reset();
this.layoutProducer = new LayoutProducer();
ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<>();
appender.setLayout(layoutProducer);
appender.setContext(ctx);
appender.start();
Logger basicLogger = ctx.getLogger(LogFmtTest.class);
basicLogger.addAppender(appender);
this.logger = LogFmt.from(basicLogger);
ctx.start();
}
示例7: init
import ch.qos.logback.classic.LoggerContext; //导入方法依赖的package包/类
@BeforeClass
@SuppressWarnings("unchecked")
public static void init() {
loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
appender = new CdpAppender();
appender.setContext(loggerContext);
appender.start();
appender.setName(CdpAppender.class.getName());
Logger logger = loggerContext.getLogger("cdp4j.flow");
logger.addAppender((Appender<ILoggingEvent>) appender);
factory = new Launcher().launch();
session = factory.create();
session.enableConsoleLog();
URL url = TestAll.class.getResource("/session-test.html");
session.navigate(url.toString());
}
示例8: configure
import ch.qos.logback.classic.LoggerContext; //导入方法依赖的package包/类
@Override
public void configure(LoggerContext lc) {
addInfo("Setting up robot logging configuration.");
ConsoleAppender<ILoggingEvent> ca = new ConsoleAppender<>();
ca.setContext(lc);
ca.setName("console");
LayoutWrappingEncoder<ILoggingEvent> encoder = new LayoutWrappingEncoder<>();
encoder.setContext(lc);
PatternLayout layout = new PatternLayout();
layout.setPattern("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n");
layout.setContext(lc);
layout.start();
encoder.setLayout(layout);
ca.setEncoder(encoder);
ca.start();
Logger rootLogger = lc.getLogger(Logger.ROOT_LOGGER_NAME);
rootLogger.addAppender(ca);
rootLogger.setLevel(Level.DEBUG);
}
示例9: configure
import ch.qos.logback.classic.LoggerContext; //导入方法依赖的package包/类
@Override
public void configure(LoggerContext loggerContext) {
addInfo("Setting up default configuration.");
NonMetricsConsoleAppender nonMetricsConsoleAppender = new NonMetricsConsoleAppender();
nonMetricsConsoleAppender.setContext(loggerContext);
nonMetricsConsoleAppender.setName("CONSOLE");
nonMetricsConsoleAppender.start();
MetricsConsoleAppender metricsConsoleAppender = new MetricsConsoleAppender();
metricsConsoleAppender.setContext(loggerContext);
metricsConsoleAppender.setName("METRICS");
metricsConsoleAppender.start();
Logger rootLogger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
rootLogger.setLevel(Level.INFO);
rootLogger.addAppender(nonMetricsConsoleAppender);
rootLogger.addAppender(metricsConsoleAppender);
}
示例10: doInitializer
import ch.qos.logback.classic.LoggerContext; //导入方法依赖的package包/类
/**
* Initializer logback
*
* @param file
* @param level
* @param maxHistory
*/
private void doInitializer(String file, String level, int maxHistory) {
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
Logger rootLogger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
rootLogger.detachAndStopAllAppenders();
// appender
RollingFileAppender<ILoggingEvent> fileAppender = new RollingFileAppender<ILoggingEvent>();
fileAppender.setContext(loggerContext);
fileAppender.setName("application");
fileAppender.setFile(file);
fileAppender.setAppend(true);
// policy
TimeBasedRollingPolicy<ILoggingEvent> policy = new TimeBasedRollingPolicy<ILoggingEvent>();
policy.setContext(loggerContext);
policy.setMaxHistory(maxHistory);
policy.setFileNamePattern(file + ".%d{yyyy-MM-dd}");
policy.setParent(fileAppender);
policy.start();
fileAppender.setRollingPolicy(policy);
// encoder
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setContext(loggerContext);
encoder.setPattern("%date [%thread] %-5level %logger (%file:%line\\) - %msg%n");
encoder.start();
fileAppender.setEncoder(encoder);
fileAppender.start();
rootLogger.addAppender(fileAppender);
rootLogger.setLevel(Level.toLevel(level));
rootLogger.setAdditive(false);
}
示例11: Graylog2Impl
import ch.qos.logback.classic.LoggerContext; //导入方法依赖的package包/类
@Inject
public Graylog2Impl(Configuration config) {
String canonicalHostName;
try {
canonicalHostName = config.getString(
"graylog2.appender.sourcehost",
InetAddress.getLocalHost().getCanonicalHostName()
);
} catch (UnknownHostException e) {
canonicalHostName = "unknown";
}
accessLogEnabled = config.getBoolean("graylog2.appender.access-log", false);
final GelfConfiguration gelfConfiguration = getGelfConfiguration(config);
GelfTransport transport = GelfTransports.create(gelfConfiguration);
final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
final Logger rootLogger = lc.getLogger(Logger.ROOT_LOGGER_NAME);
gelfClientAppender = new GelfClientAppender(transport, canonicalHostName);
gelfClientAppender.setContext(lc);
gelfClientAppender.start();
rootLogger.addAppender(gelfClientAppender);
}
示例12: getNewLogger
import ch.qos.logback.classic.LoggerContext; //导入方法依赖的package包/类
private Logger getNewLogger(String jobID,String fileLogLocation) {
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
FileAppender<ILoggingEvent> fileAppender = new FileAppender<>();
fileAppender.setContext(loggerContext);
fileAppender.setFile(fileLogLocation);
/*SizeBasedTriggeringPolicy<ILoggingEvent> triggeringPolicy = new SizeBasedTriggeringPolicy<ILoggingEvent>();
triggeringPolicy.setMaxFileSize("10MB");
triggeringPolicy.start();*/
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setContext(loggerContext);
encoder.setPattern("%msg%n");
encoder.start();
fileAppender.setEncoder(encoder);
fileAppender.start();
// attach the rolling file appender to the logger of your choice
Logger logbackLogger = loggerContext.getLogger(jobID);
((ch.qos.logback.classic.Logger) logbackLogger).addAppender(fileAppender);
executionTrackingLoggers.put(jobID, logbackLogger);
return logbackLogger;
}
示例13: MongoSender
import ch.qos.logback.classic.LoggerContext; //导入方法依赖的package包/类
public MongoSender(MongoCollection<Document> collection){
this.collection=collection;
lis=new LinkedList<Document>();
semaphore = new Semaphore(1);
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
logger= loggerContext.getLogger("framework.MongoSender");
}
示例14: connect
import ch.qos.logback.classic.LoggerContext; //导入方法依赖的package包/类
private static void connect(String URI){
//Change MongoDB's logger settings
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
rootLogger = loggerContext.getLogger("org.mongodb.driver");
rootLogger.setLevel(Level.INFO);
//Setup Connection
MongoClientURI connectionString = new MongoClientURI(URI);
MongoClient mongoClient = new MongoClient(connectionString);
MongoDatabase database = mongoClient.getDatabase("media_information_service_db");
collection = database.getCollection("messages");
}
示例15: setup
import ch.qos.logback.classic.LoggerContext; //导入方法依赖的package包/类
public static void setup(AvaIre avaire) {
if (isSetup) {
throw new IllegalStateException("The metrics has already been setup!");
}
Metrics.avaire = avaire;
final LoggerContext factory = (LoggerContext) LoggerFactory.getILoggerFactory();
final ch.qos.logback.classic.Logger root = factory.getLogger(Logger.ROOT_LOGGER_NAME);
final InstrumentedAppender prometheusAppender = new InstrumentedAppender();
prometheusAppender.setContext(root.getLoggerContext());
prometheusAppender.start();
root.addAppender(prometheusAppender);
// JVM (hotspot) metrics
DefaultExports.initialize();
Metrics.initializeEventMetrics();
if (!avaire.getConfig().getBoolean("metrics.enabled", true)) {
LOGGER.info("Metrics web API is disabled, skipping igniting Spark API");
Metrics.isSetup = true;
return;
}
PORT = avaire.getConfig().getInt("metrics.port", 1256);
LOGGER.info("Igniting Spark API on port: " + PORT);
Spark.port(PORT);
Spark.before(new HttpFilter());
Spark.exception(Exception.class, new SparkExceptionHandler());
Spark.get("/metrics", new GetMetrics(MetricsHolder.METRICS));
Spark.get("/stats", new GetStats(MetricsHolder.METRICS));
Metrics.isSetup = true;
}