In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces what is the role of LogbackContainer in dubbo, the content is very detailed, interested friends can refer to, hope to be helpful to you.
LogbackContainer
Dubbo-2.7.2/dubbo-container/dubbo-container-logback/src/main/java/org/apache/dubbo/container/logback/LogbackContainer.java
Public class LogbackContainer implements Container {public static final String LOGBACK_FILE = "dubbo.logback.file"; public static final String LOGBACK_LEVEL = "dubbo.logback.level"; public static final String LOGBACK_MAX_HISTORY = "dubbo.logback.maxhistory"; public static final String DEFAULT_LOGBACK_LEVEL = "ERROR"; @ Override public void start () {String file = ConfigUtils.getProperty (LOGBACK_FILE) If (file! = null & & file.length () > 0) {String level = ConfigUtils.getProperty (LOGBACK_LEVEL); if (StringUtils.isEmpty (level)) {level = DEFAULT_LOGBACK_LEVEL;} / / maxHistory=0 Infinite history int maxHistory= StringUtils.parseInteger (ConfigUtils.getProperty (LOGBACK_MAX_HISTORY)); doInitializer (file, level, maxHistory) } @ Override public void stop () {} / * Initializer logback * * @ param file * @ 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 fileAppender = new RollingFileAppender (); fileAppender.setContext (loggerContext); fileAppender.setName ("application"); fileAppender.setFile (file); fileAppender.setAppend (true); / / policy TimeBasedRollingPolicy policy = new TimeBasedRollingPolicy (); 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);}}
LogbackContainer implements the Container interface, and its start method determines whether there is a specified dubbo.logback.file. If so, it further gets the dubbo.logback.level. If it is empty, it defaults to the ERROR level, and then gets the dubbo.logback.maxhistory. Finally, it calls the doInitializer;doInitializer method to get the rootLogger, then executes the detachAndStopAllAppenders, then configures the RollingFileAppender, specifies policy as TimeBasedRollingPolicy, sets PatternLayoutEncoder, then starts fileAppender, and adds it to the rootLogger.
Example
Dubbo-2.7.2/dubbo-container/dubbo-container-logback/src/test/java/org/apache/dubbo/container/logback/LogbackContainerTest.java
Public class LogbackContainerTest {private static final Logger logger = LoggerFactory.getLogger (LogbackContainerTest.class); @ Test public void testContainer () {LogbackContainer container = (LogbackContainer) ExtensionLoader.getExtensionLoader (Container.class) .getExtension ("logback"); container.start (); logger.debug ("Test debug:" + this.getClass (). GetName ()); logger.warn ("Test warn:" + this.getClass (). GetName ()) Logger.info ("Test info:" + this.getClass (). GetName ()); logger.error ("Test error:" + this.getClass (). GetName ()); container.stop ();}}
This is verified by starting the container of logback and then using the logger output
Summary
LogbackContainer implements the Container interface, and its start method determines whether there is a specified dubbo.logback.file. If so, it further gets the dubbo.logback.level. If it is empty, it defaults to the ERROR level, and then gets the dubbo.logback.maxhistory. Finally, it calls the doInitializer;doInitializer method to get the rootLogger, then executes the detachAndStopAllAppenders, then configures the RollingFileAppender, specifies policy as TimeBasedRollingPolicy, sets PatternLayoutEncoder, then starts fileAppender, and adds it to the rootLogger.
About what the role of LogbackContainer in dubbo is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.