{"id":293353,"date":"2019-08-14T09:00:18","date_gmt":"2019-08-14T09:00:18","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=293353"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=293353","title":{"rendered":"\u0420\u0430\u0437\u0434\u0435\u043b\u044c\u043d\u043e\u0435 \u043b\u043e\u0433\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0432 Java\/logback"},"content":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/yo\/jt\/7_\/yojt7_vw5yer5hnszjbyhljpijq.jpeg\" alt=\"Bart writing some logs\"><\/p>\n<p>  <\/p>\n<h2 id=\"zadacha\">\u0417\u0430\u0434\u0430\u0447\u0430<\/h2>\n<p>  <\/p>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043d\u0430\u043c \u0437\u0430\u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u043b\u043e\u0433\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043d\u0435\u043a\u043e\u0433\u043e Java-\u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u043e \u0440\u0430\u0437\u043d\u043e\u043c\u0443:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0441\u0432\u043e\u0439 \u043b\u043e\u0433-\u0444\u0430\u0439\u043b,<\/li>\n<li>\u2026 \u0441\u0432\u043e\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u043b\u043e\u0433\u0430,<\/li>\n<li>\u2026 \u0441\u0432\u043e\u0439 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043b\u043e\u0433\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f,<\/li>\n<li>\u0444\u043e\u0440\u043c\u0430\u0442 \u043b\u043e\u0433\u0430 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u043c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c\u0438 <code>%\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438<\/code>,<\/li>\n<li>\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u044d\u0442\u0443 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u043d\u0430 \u043b\u0435\u0442\u0443.<\/li>\n<\/ul>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u0430\u043a \u044d\u0442\u0438 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c. \u0412 \u0446\u0435\u043b\u044f\u0445 \u0441\u043e\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0435\u043c \u043b\u043e\u0433\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e \u043c\u0435\u0442\u043e\u0434\u0430\u043c; \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u0445\u043e\u0442\u0435\u0442\u044c\u0441\u044f \u0438\u043c\u0435\u0442\u044c \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0443\u0442\u043e\u0447\u043d\u043d\u044f\u044e\u0449\u0438\u0439 \u043a\u043e\u043d\u0444\u0438\u0433, \u0432\u0440\u043e\u0434\u0435 <code>\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435<\/code> \u2192 <code>\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442<\/code> \u2192 <code>\u0421\u0435\u0440\u0432\u0438\u0441<\/code> \u2192 <code>\u041c\u0435\u0442\u043e\u0434<\/code>\u2026 \u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043f\u043e\u043b\u043d\u044b\u0439 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0432\u043d\u0438\u0437\u0443.<\/p>\n<p>  <\/p>\n<h2 id=\"klientskiy-kod\">\u041a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u0439 \u043a\u043e\u0434<\/h2>\n<p>  <\/p>\n<pre><code class=\"java\">    class ThingService {         log = LoggerFactory.getLogger();         getThing() {             log.debug(\"getThing...\"); \/\/ =&gt; one.log         }         listThings() {             log.debug(\"listThings...\"); \/\/ =&gt; another.log         }     }<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"logback\">Logback<\/h2>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u044b\u0431\u0440\u0430\u043d\u0430 \u0434\u043e\u0431\u0440\u043e\u0442\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043b\u043e\u0433\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f &#171;logback&#187;, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0430\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0430\u0446\u0438\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">ch.qos.logback:logback-classic:1.2.3<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0438\u0437 XML-\u043a\u043e\u043d\u0444\u0438\u0433\u0430, \u0442\u0430\u043a \u0438 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0438\u0437 \u0414\u0436\u0430\u0432\u044b, \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u043c\u043e\u0436\u043d\u043e \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">    public void configureLogback() throws JoranException {         LoggerContext lc = LoggerFactory.getILoggerFactory();         lc.reset(); \/\/  reset prev config         JoranConfigurator configurator = new JoranConfigurator();         configurator.setContext(lc);         configurator.doConfigure(\"config.xml\"); \/\/ any data source         StatusPrinter.printInCaseOfErrorsOrWarnings(lc);          \/\/ \u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044f:         Logger root = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);         root.setLevel(Level.INFO); \/\/ \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435     }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u043a\u0440\u0430\u0442\u0446\u0435, \u043e \u043b\u043e\u0433\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442 \u0434\u0435\u0440\u0433\u0430\u0435\u0442 <em>\u043b\u043e\u0433\u0433\u0435\u0440<\/em>,<\/li>\n<li>\u041b\u043e\u0433\u0433\u0435\u0440 \u0434\u0435\u0440\u0433\u0430\u0435\u0442 \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u044b\u0435 \u0435\u043c\u0443 <em>\u0430\u043f\u043f\u0435\u043d\u0434\u0435\u0440\u044b<\/em>,<\/li>\n<li>\u0410\u043f\u043f\u0435\u043d\u0434\u0435\u0440 \u0434\u0443\u043c\u0430\u0435\u0442 \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 <em>\u044d\u043d\u043a\u043e\u0434\u0435\u0440<\/em>,<\/li>\n<li>\u042d\u043d\u043a\u043e\u0434\u0435\u0440 \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u0443\u0435\u0442 \u0440\u043e\u0432\u043d\u043e \u043e\u0434\u043d\u0443 \u0441\u0442\u0440\u043e\u043a\u0443 \u043b\u043e\u0433\u0430,<\/li>\n<li>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043e\u043d \u0434\u0451\u0440\u0433\u0430\u0435\u0442 \u0446\u0435\u043f\u043e\u0447\u043a\u0443 <em>\u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440\u043e\u0432<\/em>, \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0440\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0441\u0432\u043e\u044e <code>%\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e<\/code>,<\/li>\n<li>\u0423\u0441\u043f\u0435\u0445.<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0431\u044b\u043b\u0430 \u0432\u044b\u0431\u0440\u0430\u043d\u0430 \u0447\u0438\u0441\u0442\u0430\u044f \u0434\u0436\u0430\u0432\u0438\u043d\u0430\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f. \u0422\u0443\u0442 \u0432\u0441\u0451 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e \u0435\u0441\u043b\u0438 \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0434 \u0433\u043b\u0430\u0437\u0430\u043c\u0438 XML-\u043a\u043e\u043d\u0444\u0438\u0433. \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u2014 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0432\u043e\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 appender\/encoder \u0438 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u2014 \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043b\u043e\u0433\u0431\u044d\u043a\u043e\u043c \u0438\u0437 \u0441\u0432\u043e\u0438\u0445 \u043d\u0435\u0434\u0440. \u041f\u043e\u0447\u0442\u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u043d\u0443\u0436\u043d\u043e \u043d\u0435 \u0437\u0430\u0431\u044b\u0442\u044c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u043e\u043c <code>start()<\/code>. \u0410\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">    Logger rootLogger = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);     LoggerContext lc = rootLogger.getLoggerContext();     lc.reset(); \/\/  reset prev config      var encoder = new PatternLayoutEncoder();     encoder.setContext(lc);     encoder.setPattern(\"%-5level %message%n\");     encoder.start();      var appender = new ConsoleAppender&lt;ILoggingEvent&gt;();     appender.setContext(lc);     appender.setEncoder(encoder);     appender.start();      rootLogger.setLevel(Level.DEBUG);     rootLogger.addAppender(appender);<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"otdelyaem-loggiruemye-metody-drug-ot-druga\">\u041e\u0442\u0434\u0435\u043b\u044f\u0435\u043c \u043b\u043e\u0433\u0433\u0438\u0440\u0443\u0435\u043c\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u0440\u0443\u0433 \u043e\u0442 \u0434\u0440\u0443\u0433\u0430<\/h2>\n<p>  <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043b\u043e\u0433\u0431\u044d\u043a \u043c\u043e\u0433 \u043e\u0442\u043b\u0438\u0447\u0438\u0442\u044c \u043e\u0434\u0438\u043d \u043c\u0435\u0442\u043e\u0434 \u043e\u0442 \u0434\u0440\u0443\u0433\u043e\u0433\u043e, \u043f\u0435\u0440\u0435\u0434 \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0435\u0433\u043e \u0438\u043c\u044f \u0432 <code>ThreadLocal<\/code> Mapped Diagnostic Context. \u0414\u0430\u043b\u0435\u0435, \u043f\u0440\u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0435, \u044d\u0442\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0438\u0437 \u043a\u043b\u0430\u0441\u0441\u0430 <code>MDC<\/code> \u043d\u0435 \u0434\u043e\u0441\u0442\u0430\u0451\u043c, \u0442\u0430\u043a \u043a\u0430\u043a \u043b\u043e\u0433\u0433\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0443\u0436\u0435 \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435 \u0438 \u044d\u0442\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u0430\u043c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u2014 \u0434\u043e\u0441\u0442\u0430\u0451\u043c \u0438\u0445 \u0447\u0435\u0440\u0435\u0437 <code>ILoggingEvent.getMDCPropertyMap()<\/code>. <\/p>\n<p>  <\/p>\n<pre><code class=\"java\">    try {         MDC.put(MDC_KEY_METHOD, methodName);         \/\/ \u0412\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430         \/\/ \u0412 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0442\u044c \u043b\u0443\u0447\u0448\u0435 \u0447\u0435\u0440\u0435\u0437 AOP, \u043a\u043e\u043d\u0435\u0447\u043d\u043e.     } finally {         MDC.put(remove);     }<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"svoy-log-fayl-na-kazhdyy-metod\">\u0421\u0432\u043e\u0439 \u043b\u043e\u0433-\u0444\u0430\u0439\u043b \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u043c\u0435\u0442\u043e\u0434<\/h2>\n<p>  <\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0438 \u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u0435\u043c \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0430\u043f\u043f\u0435\u043d\u0434\u0435\u0440:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">    class MultiAppender extends AppenderBase&lt;ILoggingEvent&gt; {         @Override         protected void append(ILoggingEvent event) {             method = event.getMDCPropertyMap().get(MDC_KEY_METHOD);             Appender appender = getOrCreateAppender(method);             appender.doAppend(event);         }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0410\u043f\u043f\u0435\u043d\u0434\u0435\u0440 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043b\u0438\u043f\u043e\u0432\u044b\u0439, \u0442\u0430\u043a \u043a\u0430\u043a \u0441\u0430\u043c \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442, \u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u0443\u0435\u0442 \u043b\u043e\u0433\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0430\u0447\u043a\u0435 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0445 \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0445 \u0430\u043f\u043f\u0435\u043d\u0434\u0435\u0440\u043e\u0432, \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u043c\u0435\u0442\u043e\u0434. \u0414\u0435\u043b\u0435\u0433\u0438\u0440\u0443\u0435\u0442 \u043e\u0434\u043d\u043e\u043c\u0443, \u0441\u0430\u043c\u043e\u043c\u0443 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0435\u043c\u0443. \u0421\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0430\u043f\u043f\u0435\u043d\u0434\u0435\u0440\u044b \u043f\u043e \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044e, \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">    fileAppender = new FileAppender&lt;ILoggingEvent&gt;();     fileAppender.setContext(lc);     fileAppender.setAppend(false);     fileAppender.setEncoder(getOrCreateEncoderByMethod(lc, method));     fileAppender.setFile(logFileByMethod.get(method));     fileAppender.start();<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"svoy-format-na-kazhdyy-metod\">\u0421\u0432\u043e\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u043c\u0435\u0442\u043e\u0434<\/h2>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u0435\u0440\u0436\u0438\u043c \u043a\u044d\u0448 \u0430\u0432\u0442\u043e-\u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0442\u0438\u043f\u0430 <code>Encoder<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">    Map&lt;String, String&gt; patternByMethod = new HashMap&lt;&gt;();      \/\/ \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u044b\u0448\u0435; \u0443\u043f\u0440\u043e\u0449\u0451\u043d\u043e     Encoder getOrCreateEncoderByMethod(LoggerContext lc, String method) {         String pattern = patternByMethod.get(method);         encoder = new PatternLayoutEncoder();         encoder.setContext(lc);         encoder.setPattern(pattern);         encoder.start();         return encoder;     }<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"kazhdomu-metodu-svoy-uroven-loggirovaniya\">\u041a\u0430\u0436\u0434\u043e\u043c\u0443 \u043c\u0435\u0442\u043e\u0434\u0443 \u0441\u0432\u043e\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043b\u043e\u0433\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/h2>\n<p>  <\/p>\n<p>\u0412 \u043a\u043b\u0430\u0441\u0441 <code>MultiAppender<\/code> \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443: \u0435\u0441\u043b\u0438 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043f\u0440\u0435\u043e\u0434\u043e\u043b\u0435\u0432\u0430\u0435\u0442 \u043f\u043e\u0440\u043e\u0433 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0439 \u0434\u043b\u044f \u043c\u0435\u0442\u043e\u0434\u0430, \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0433\u0434\u0430 \u043b\u043e\u0433\u0433\u0438\u0440\u0443\u0435\u043c \u0435\u0433\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">    Map&lt;String, Level&gt; levelByMethod = new HashMap&lt;&gt;();      protected void append(ILoggingEvent event) {         Level minLevel = levelByMethod.get(methodName);         if (event.getLevel().levelInt &gt;= minLevel.levelInt) {             appender.doAppend(event);         }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u044d\u0442\u0443 \u043b\u043e\u0433\u0438\u043a\u0443 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0432 \u0444\u0438\u043b\u044c\u0442\u0440.<\/p>\n<p>  <\/p>\n<h2 id=\"rasshirenie-formata-svoimi-peremennymi\">\u0420\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u0444\u043e\u0440\u043c\u0430\u0442\u0430 \u0441\u0432\u043e\u0438\u043c\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438<\/h2>\n<p>  <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u0433\u043e\u0440\u043e\u0434\u0438\u0442\u044c \u0441\u0432\u043e\u0439 \u043e\u0433\u043e\u0440\u043e\u0434, \u0430 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u0435\u043d\u043d\u043e\u0439 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439 \u043b\u043e\u0433\u0431\u044d\u043a\u0430, \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u0432\u043e\u0439 \u043a\u043b\u0430\u0441\u0441 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440\u0430, \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 \u0447\u0442\u043e\u0431\u044b \u0435\u0433\u043e \u043c\u043e\u0433\u043b\u0438 \u0438\u043d\u0441\u0442\u0430\u043d\u0446\u0438\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0437\u0432\u043d\u0435. \u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u0435\u043d <code>MDC<\/code>, \u0431\u0435\u0440\u0451\u043c \u0435\u0433\u043e \u0438\u0437 \u044d\u0432\u0435\u043d\u0442\u0430. \u0417\u0434\u0435\u0441\u044c \u0437\u0430\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <code>%custom<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">    public class CustomConverter extends ClassicConverter {         public String convert(ILoggingEvent event) {             \/\/ mdc = event.getMDCPropertyMap();             return \"variable-expanded\";         }     }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u043e \u0432\u0440\u0435\u043c\u044f \u043e\u0431\u0449\u0435\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">    void configurePatterns(LoggerContext lc) {         Map&lt;String, String&gt; rules                 = lc.getObject(CoreConstants.PATTERN_RULE_REGISTRY);         if (rules == null) {             rules = new HashMap&lt;String, String&gt;();             lc.putObject(CoreConstants.PATTERN_RULE_REGISTRY, rules);         }         rules.put(\"custom\", CustomConverter.class.getName());     }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u044d\u043d\u043a\u043e\u0434\u0435\u0440\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>PatternLayoutEncoder<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0430\u043c \u0432\u0441\u0451 \u043f\u043e\u0434\u0445\u0432\u0430\u0442\u0438\u0442. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <code>%custom<\/code> \u0440\u0430\u0441\u043a\u0440\u043e\u0435\u0442\u0441\u044f \u0432 \u0441\u0442\u0440\u043e\u043a\u0443 <code>\"variable-expanded\"<\/code>.<\/p>\n<p>  <\/p>\n<h2 id=\"obnovlenie-konfiga-na-letu\">\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0430 \u043d\u0430 \u043b\u0435\u0442\u0443<\/h2>\n<p>  <\/p>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0442\u0430\u043a\u0430\u044f \u0435\u0441\u0442\u044c \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438: \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e-\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0442\u043e\u0440 \u0435\u0449\u0451 \u0440\u0430\u0437, \u043d\u0435 \u0437\u0430\u0431\u044b\u0432 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043c <code>LoggerContext::reset()<\/code> \u0438 \u043e\u0447\u0438\u0441\u0442\u043a\u0443 \u043d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043a\u044d\u0448\u0430.<\/p>\n<p>  <\/p>\n<h2 id=\"mnogopotochnost\">\u041c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c<\/h2>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0437\u0430\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430\u043c\u0438 \u043c\u0435\u0442\u043e\u0434 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043a \u0436\u0438\u0437\u043d\u0438 \u043d\u043e\u0432\u044b\u0435 \u043f\u043e\u0442\u043e\u043a\u0438, \u0442\u043e \u043d\u0430 \u043d\u0438\u0445, \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u043b\u043e\u0433\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u044f\u0442\u044c\u0441\u044f \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u2014 \u0432 \u043d\u043e\u0432\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435 thread local&#8217;\u044b \u0441\u0430\u043c\u0438 \u0441\u043e\u0431\u043e\u0439 \u043d\u0435 \u043f\u043e\u044f\u0432\u044f\u0442\u0441\u044f. \u0422\u0430\u043a \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 \u043a \u043d\u043e\u0432\u043e\u043c\u0443 \u043f\u043e\u0442\u043e\u043a\u0443, \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0443\u0434\u0430 <code>MDC<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">    Map&lt;String, String&gt; mdcOrig = MDC.getCopyOfContextMap();     ExecutorService es = Executors.newFixedThreadPool(1);     es.submit(() -&gt; threadWorker(mdcOrig));      void threadWorker(Map&lt;String, String&gt; parentMdc) {         MDC.setContextMap(parentMdc);         log.error(\"expected to appear in method2*.log\");     }<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"primer-celikom\">\u041f\u0440\u0438\u043c\u0435\u0440 \u0446\u0435\u043b\u0438\u043a\u043e\u043c<\/h2>\n<p>  <\/p>\n<p><a href=\"https:\/\/github.com\/zencd\/logback-setup\">https:\/\/github.com\/zencd\/logback-setup<\/a><\/p>\n<p>  <\/p>\n<h2 id=\"literatura\">\u041b\u0438\u0442\u0435\u0440\u0430\u0442\u0443\u0440\u0430<\/h2>\n<p>  <\/p>\n<p><a href=\"https:\/\/logback.qos.ch\/manual\/index_ja.html\">\u041e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0430\u043d\u0443\u0430\u043b logback<\/a><\/p>\n<\/div>\n<p>               <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d()}}}t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>     <br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/463601\/\"> https:\/\/habr.com\/ru\/post\/463601\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/yo\/jt\/7_\/yojt7_vw5yer5hnszjbyhljpijq.jpeg\" alt=\"Bart writing some logs\"><\/p>\n<p>  <\/p>\n<h2 id=\"zadacha\">\u0417\u0430\u0434\u0430\u0447\u0430<\/h2>\n<p>  <\/p>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043d\u0430\u043c \u0437\u0430\u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u043b\u043e\u0433\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043d\u0435\u043a\u043e\u0433\u043e Java-\u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u043e \u0440\u0430\u0437\u043d\u043e\u043c\u0443:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0441\u0432\u043e\u0439 \u043b\u043e\u0433-\u0444\u0430\u0439\u043b,<\/li>\n<li>\u2026 \u0441\u0432\u043e\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u043b\u043e\u0433\u0430,<\/li>\n<li>\u2026 \u0441\u0432\u043e\u0439 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043b\u043e\u0433\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f,<\/li>\n<li>\u0444\u043e\u0440\u043c\u0430\u0442 \u043b\u043e\u0433\u0430 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u043c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c\u0438 <code>%\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438<\/code>,<\/li>\n<li>\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u044d\u0442\u0443 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u043d\u0430 \u043b\u0435\u0442\u0443.<\/li>\n<\/ul>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-293353","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/293353","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=293353"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/293353\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=293353"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=293353"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=293353"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}