View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements. See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache license, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License. You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the license for the specific language governing permissions and
15   * limitations under the license.
16   */
17  package org.apache.logging.log4j.core.jmx;
18  
19  /**
20   * The MBean interface for monitoring and managing a {@code LoggerConfig}.
21   */
22  public interface LoggerConfigAdminMBean {
23      /**
24       * ObjectName pattern ({@value}) for LoggerConfigAdmin MBeans.
25       * This pattern contains two variables, where the first is the name of the
26       * context, the second is the name of the instrumented logger config.
27       * <p>
28       * You can find all registered LoggerConfigAdmin MBeans like this:
29       * </p>
30       * <pre>
31       * MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
32       * String pattern = String.format(LoggerConfigAdminMBean.PATTERN, &quot;*&quot;, &quot;*&quot;);
33       * Set&lt;ObjectName&gt; loggerConfigNames = mbs.queryNames(new ObjectName(pattern), null);
34       * </pre>
35       * <p>
36       * Some characters are not allowed in ObjectNames. The logger context name
37       * and logger config name may be quoted. When LoggerConfigAdmin MBeans are
38       * registered, their ObjectNames are created using this pattern as follows:
39       * </p>
40       * <pre>
41       * String ctxName = Server.escape(loggerContext.getName());
42       * String loggerConfigName = Server.escape(loggerConfig.getName());
43       * String name = String.format(PATTERN, ctxName, loggerConfigName);
44       * ObjectName objectName = new ObjectName(name);
45       * </pre>
46       * @see Server#escape(String)
47       */
48      String PATTERN = Server.DOMAIN + ":type=%s,component=Loggers,name=%s";
49  
50      /**
51       * Returns the name of the instrumented {@code LoggerConfig}.
52       *
53       * @return the name of the LoggerConfig
54       */
55      String getName();
56  
57      /**
58       * Returns the {@code LoggerConfig} level as a String.
59       *
60       * @return the {@code LoggerConfig} level.
61       */
62      String getLevel();
63  
64      /**
65       * Sets the {@code LoggerConfig} level to the specified value.
66       *
67       * @param level the new {@code LoggerConfig} level.
68       * @throws IllegalArgumentException if the specified level is not one of
69       *             "OFF", "FATAL", "ERROR", "WARN", "INFO", "DEBUG", "TRACE",
70       *             "ALL"
71       */
72      void setLevel(String level);
73  
74      /**
75       * Returns whether the instrumented {@code LoggerConfig} is additive.
76       *
77       * @return {@code true} if the LoggerConfig is additive, {@code false}
78       *         otherwise
79       */
80      boolean isAdditive();
81  
82      /**
83       * Sets whether the instrumented {@code LoggerConfig} should be additive.
84       *
85       * @param additive {@code true} if the instrumented LoggerConfig should be
86       *            additive, {@code false} otherwise
87       */
88      void setAdditive(boolean additive);
89  
90      /**
91       * Returns whether the instrumented {@code LoggerConfig} is configured to
92       * include location.
93       *
94       * @return whether location should be passed downstream
95       */
96      boolean isIncludeLocation();
97  
98      /**
99       * Returns a string description of all filters configured for the
100      * instrumented {@code LoggerConfig}.
101      *
102      * @return a string description of all configured filters for this
103      *         LoggerConfig
104      */
105     String getFilter();
106 
107     /**
108      * Returns a String array with the appender refs configured for the
109      * instrumented {@code LoggerConfig}.
110      *
111      * @return the appender refs for the instrumented {@code LoggerConfig}.
112      */
113     String[] getAppenderRefs();
114 
115 }