Java Code Examples for org.slf4j.LoggerFactory#getLogger()
The following examples show how to use
org.slf4j.LoggerFactory#getLogger() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Minister.java From GOAi with GNU Affero General Public License v3.0 | 6 votes |
/** * 初始化日志 */ private Logger initLog(Integer id) { // 实例化log,每个实例存放地方不一致 ch.qos.logback.classic.Logger logger = ((ch.qos.logback.classic.Logger) LoggerFactory.getLogger(this.secretary.strategyName + "-" + id)); LoggerContext context = logger.getLoggerContext(); TimeBasedRollingPolicy<ILoggingEvent> policy = new TimeBasedRollingPolicy<>(); policy.setFileNamePattern(OptionHelper.substVars( "logs/past/" + id + "/%d{yyyy-MM-dd}.log.gz", context)); policy.setMaxHistory(31); policy.setContext(context); PatternLayoutEncoder encoder = new PatternLayoutEncoder(); encoder.setContext(context); encoder.setPattern("%d{yyyy-MM-dd HH:mm:ss.SSS} %5level - [%thread] %logger : %msg%n"); RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<>(); appender.setContext(context); appender.setName(this.secretary.strategyName + "-" + id); appender.setFile(OptionHelper.substVars("logs/" + id + "/log.log", context)); appender.setAppend(true); // 同一文件多输入完整检查 appender.setPrudent(false); appender.setRollingPolicy(policy); appender.setEncoder(encoder); policy.setParent(appender); policy.start(); encoder.start(); appender.start(); logger.setLevel(Level.INFO); // 终端输出 logger.setAdditive(true); logger.addAppender(appender); return logger; }
Example 2
Source File: ConsumerActions.java From apicurio-registry with Apache License 2.0 | 6 votes |
/** * Dynamically remove given topic partition from the set of assigned topic partitions. * * @param tp topic partition to remove */ default CompletableFuture<Void> removeTopicParition(TopicPartition tp) { Objects.requireNonNull(tp); Logger log = LoggerFactory.getLogger(DynamicAssignment.class); log.info("Removing topic-partition: {}", tp); return submit(consumer -> { Set<TopicPartition> oldTps = consumer.assignment(); Set<TopicPartition> newTps = new HashSet<>(oldTps); newTps.remove(tp); if (!oldTps.equals(newTps)) { log.info("Reassigning topic-partition(s): {} -> {}", oldTps, newTps); consumer.assign(newTps); } return null; }); }
Example 3
Source File: CachingSubsystemRegistry.java From arcusplatform with Apache License 2.0 | 6 votes |
private PlaceContext loadPlaceContext(UUID placeId, String population, UUID accountId) { Collection<Model> models = modelDao.loadModelsByPlace(placeId, TRACKED_TYPES); PlatformSubsystemModelStore store = new PlatformSubsystemModelStore(); store.setTrackedTypes(TRACKED_TYPES); store.addModels( models .stream() .filter((m) -> m != null) // replace non-subsystems with SimpleModel so that we don't // un-necessarilly track changes on those .map((m) -> SubsystemCapability.NAMESPACE.equals(m.getAttribute(Capability.ATTR_TYPE)) ? m : new SimpleModel(m)) .collect(Collectors.toList()) ); return new SimplePlaceContext(placeId, population, accountId, LoggerFactory.getLogger("subsystem." + placeId), store); }
Example 4
Source File: LogUtils.java From konduit-serving with Apache License 2.0 | 5 votes |
/** * Sets the appenders for command line. */ public static void setAppendersForCommandLine() { Logger rootLogger = (Logger) LoggerFactory.getLogger(ROOT_LOGGER); LoggerContext context = (LoggerContext) org.slf4j.LoggerFactory.getILoggerFactory(); rootLogger.detachAndStopAllAppenders(); ConsoleAppender<ILoggingEvent> consoleAppender = new ConsoleAppender<>(); PatternLayoutEncoder consolePatternLayoutEncoder = new PatternLayoutEncoder(); consolePatternLayoutEncoder.setPattern("%msg%n"); consolePatternLayoutEncoder.setContext(context); consolePatternLayoutEncoder.start(); consoleAppender.setEncoder(consolePatternLayoutEncoder); consoleAppender.start(); rootLogger.addAppender(consoleAppender); ((Logger) LoggerFactory.getLogger("uk.org.lidalia")).setLevel(Level.ERROR); ((Logger) LoggerFactory.getLogger("org.nd4j")).setLevel(Level.ERROR); ((Logger) LoggerFactory.getLogger("org")).setLevel(Level.ERROR); ((Logger) LoggerFactory.getLogger("io")).setLevel(Level.ERROR); ((Logger) LoggerFactory.getLogger("ai")).setLevel(Level.INFO); }
Example 5
Source File: DiagnosticLogging.java From hivemq-community-edition with Apache License 2.0 | 5 votes |
/** * Sets the trace log to the root logger. Also adds filter, to make sure that * the appender which are already defined for HiveMQ are not affected by this logging * level change. * <p> * <b>This will significantly slow down HiveMQ, since the root level loggers Level is changed * to the finest logging level!</b> * * @param filePath the file path */ static void setTraceLog(final String filePath) { log.info("Creating trace log {}", filePath); final Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); final Level originalLoggingLevel = logger.getLevel(); final Iterator<Appender<ILoggingEvent>> appenderIterator = logger.iteratorForAppenders(); while (appenderIterator.hasNext()) { final Appender<ILoggingEvent> next = appenderIterator.next(); next.addFilter(new PreserveOriginalLoggingLevelFilter(originalLoggingLevel)); } final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); final PatternLayoutEncoder ple = new PatternLayoutEncoder(); ple.setPattern("%date %level [%thread] %logger{10} [%file:%line] %msg%n"); ple.setContext(lc); ple.start(); final FileAppender<ILoggingEvent> fileAppender = new FileAppender<>(); fileAppender.setFile(filePath); fileAppender.setEncoder(ple); fileAppender.setContext(lc); fileAppender.start(); logger.addAppender(fileAppender); logger.setLevel(Level.ALL); logger.setAdditive(false); }
Example 6
Source File: SimpleContextLoader.java From arcusplatform with Apache License 2.0 | 5 votes |
@Override public RuleContext load(UUID placeId) { Collection<Model> models = modelDao.loadModelsByPlace(placeId, RuleModelStore.TRACKED_TYPES); SimpleContext context = new SimpleContext(placeId, Address.platformService("rule"), LoggerFactory.getLogger("rules." + placeId)); models.stream() .filter(Objects::nonNull) .forEach((m) -> { try{ context.putModel(m); }catch(IllegalArgumentException e) { logger.warn("Error putting model in RuleContext for place [{}], model [{}:{}]", placeId, m!=null?m.getType():"<null>", m!=null?m.getId():"<null>", e); } }); return context; }
Example 7
Source File: WorkItemTest.java From kogito-runtimes with Apache License 2.0 | 4 votes |
public void addLogger() { logger = LoggerFactory.getLogger(this.getClass()); }
Example 8
Source File: NodeInnerClassesTest.java From kogito-runtimes with Apache License 2.0 | 4 votes |
@Override public void addLogger() { logger = LoggerFactory.getLogger(this.getClass()); }
Example 9
Source File: EconomistHotProcessorTest.java From hot-crawler with MIT License | 4 votes |
public EconomistHotProcessorTest(){ this.log = LoggerFactory.getLogger(getClass()); }
Example 10
Source File: ProcessNodeInstanceFactoryTest.java From kogito-runtimes with Apache License 2.0 | 4 votes |
public void addLogger() { logger = LoggerFactory.getLogger(this.getClass()); }
Example 11
Source File: TestLogActionTemplate.java From arcusplatform with Apache License 2.0 | 4 votes |
@Before public void init(){ this.source = Address.platformService(UUID.randomUUID(), "rule"); this.context = new SimpleContext(UUID.randomUUID(), this.source, LoggerFactory.getLogger(TestLogActionTemplate.class)); }
Example 12
Source File: SecurityConfigurationServiceImplTest.java From hivemq-community-edition with Apache License 2.0 | 4 votes |
@Before public void setup() { initMocks(this); final Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); logCapture = LogbackCapturingAppender.Factory.weaveInto(logger); }
Example 13
Source File: SdsLoggerFactory.java From sds with Apache License 2.0 | 4 votes |
/** * 返回心跳日志 */ public static Logger getHeartbeatLogger() { return LoggerFactory.getLogger(SdsLoggerConstants.HEARTBEAT_LOGGER_NAME); }
Example 14
Source File: TestTimeOfDayFilter.java From arcusplatform with Apache License 2.0 | 4 votes |
@Before public void setUp() { context = new SimpleContext(UUID.randomUUID(), Address.platformService(UUID.randomUUID(), "rule"), LoggerFactory.getLogger(TestTimeOfDayFilter.class)); }
Example 15
Source File: DzoneHotProcessorTest.java From hot-crawler with MIT License | 4 votes |
public DzoneHotProcessorTest(){ this.log = LoggerFactory.getLogger(getClass()); }
Example 16
Source File: GeekParkHotProcessorTest.java From hot-crawler with MIT License | 4 votes |
public GeekParkHotProcessorTest(){ this.log = LoggerFactory.getLogger(getClass()); }
Example 17
Source File: ClassMaker.java From servicecomb-toolkit with Apache License 2.0 | 4 votes |
public ExecReader(InputStream is, String readerName) { this.is = is; this.readerName = readerName; LOGGER = LoggerFactory.getLogger(ExecReader.class.getName() + "-" + readerName); }
Example 18
Source File: CLI.java From sqlhelper with GNU Lesser General Public License v3.0 | 4 votes |
public static void main(String[] args) { // run mode boolean devMode = Boolean.parseBoolean(System.getProperty("dev", "false")); System.clearProperty("dev"); String runMode = devMode ? "dev" : "production"; System.setProperty(RUN_MODE_KEY, runMode); // homeDir String applicationDefaultConfigPath = Reflects.getCodeLocation(CLI.class).getPath(); String homeDirDefault = "./.."; if (devMode) { homeDirDefault = new File(applicationDefaultConfigPath).getPath(); } String homeDir = System.getProperty(HOME_DIR_KEY, homeDirDefault); homeDir = new File(homeDir).getAbsolutePath(); System.setProperty(HOME_DIR_KEY, homeDir); // pid recordPid(homeDir); Files.makeDirs(homeDir + File.separator + "logs"); // custom logback.xml if (hasCustomLogbackXml(homeDir + File.separator + "config")) { System.setProperty(ContextInitializer.CONFIG_FILE_PROPERTY, new File(homeDir + File.separator + "config/logback.xml").getAbsolutePath()); } else if (hasCustomLogbackXml(homeDir)) { System.setProperty(ContextInitializer.CONFIG_FILE_PROPERTY, new File(homeDir + File.separator + "logback.xml").getAbsolutePath()); } logger = LoggerFactory.getLogger(CLI.class); // spring.profiles.active, spring.config.location String customConfigDir = FileResource.PREFIX + new File(homeDir).getPath() + "/config/"; String configDirInJar = ClassPathResource.PREFIX + "./"; configLocations.add(customConfigDir); configLocations.add(configDirInJar); final List<String> activeProfiles = Collects.emptyArrayList(); activeProfiles.add("sqlhelper-cli"); if (devMode) { activeProfiles.add("dev"); } String specifiedProfiles = System.getProperty("spring.profiles.active"); if (specifiedProfiles != null) { Pipeline.of(Strings.split(specifiedProfiles, ",")).forEach(new Consumer<String>() { @Override public void accept(String s) { if (Strings.isNotBlank(s)) { activeProfiles.add(s.trim()); } } }); } System.setProperty("spring.profiles.active", Strings.join(",", activeProfiles)); System.setProperty("spring.config.location", Strings.join(",", configLocations)); // startup ... final SpringApplication app = new SpringApplication(CLI.class); app.setBanner(new ProjectBanner()); app.setBannerMode(Banner.Mode.LOG); final ApplicationContext context = app.run(args); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { SpringApplication.exit(context); } }); }
Example 19
Source File: HistoryServerStaticFileServerHandlerTest.java From flink with Apache License 2.0 | 4 votes |
@Test public void testRespondWithFile() throws Exception { File webDir = tmp.newFolder("webDir"); Router router = new Router() .addGet("/:*", new HistoryServerStaticFileServerHandler(webDir)); WebFrontendBootstrap webUI = new WebFrontendBootstrap( router, LoggerFactory.getLogger(HistoryServerStaticFileServerHandlerTest.class), tmp.newFolder("uploadDir"), null, "localhost", 0, new Configuration()); int port = webUI.getServerPort(); try { // verify that 404 message is returned when requesting a non-existent file String notFound404 = HistoryServerTest.getFromHTTP("http://localhost:" + port + "/hello"); Assert.assertThat(notFound404, containsString("not found")); // verify that a) a file can be loaded using the ClassLoader and b) that the HistoryServer // index_hs.html is injected String index = HistoryServerTest.getFromHTTP("http://localhost:" + port + "/index.html"); Assert.assertTrue(index.contains("Apache Flink Web Dashboard")); // verify that index.html is appended if the request path ends on '/' String index2 = HistoryServerTest.getFromHTTP("http://localhost:" + port + "/"); Assert.assertEquals(index, index2); // verify that a 404 message is returned when requesting a directory File dir = new File(webDir, "dir.json"); dir.mkdirs(); String dirNotFound404 = HistoryServerTest.getFromHTTP("http://localhost:" + port + "/dir"); Assert.assertTrue(dirNotFound404.contains("not found")); // verify that a 404 message is returned when requesting a file outside the webDir tmp.newFile("secret"); String x = HistoryServerTest.getFromHTTP("http://localhost:" + port + "/../secret"); Assert.assertTrue(x.contains("not found")); } finally { webUI.shutdown(); } }
Example 20
Source File: LoggerUtil.java From springboot-link-admin with Apache License 2.0 | 3 votes |
/** * * * <p> * TODO(方法详细描述说明、方法参数的具体涵义)debug * </p> * * @author 252956 * @date 2017年8月30日上午10:16:27 * @param message * @param t * */ public static void debug(final String message, Throwable t) { StackTraceElement caller = getStackTraceElement(Thread.currentThread() .getStackTrace()); if (null == caller) return; Logger log = LoggerFactory .getLogger(caller.getClassName() + "." + caller.getMethodName() + "() Line: " + caller.getLineNumber()); log.debug(message, t); }