asafm commented on PR #22327:
URL: https://github.com/apache/pulsar/pull/22327#issuecomment-2024934741

   Ok guys, there was a lot of information thrown around here, and for me most 
of it was new.
   I'll try to summarize it all here:
   
   1. Log4j2 supports plugins. allowing you to extend Log4j. In our example, it 
allows anyone to add a new type of Appender.
   2. Prometheus Simple client has a dependency which we included in Pulsar:
   ```
      <dependency>
         <groupId>io.prometheus</groupId>
         <artifactId>simpleclient_log4j2</artifactId>
       </dependency>
   ```
      The dependency includes a Log4j2 plugin, which adds a new `Prometheus` 
type Appender. As @lhotari noted it is:
   ```
   @Plugin(name = "Prometheus", category = "Core", elementType = "appender")
   public final class InstrumentedAppender extends AbstractAppender {
   ```
   
      This Appender receives the logs (log events) and exposes metrics about 
them - how many logs per type, etc. In effect, it instruments Log4j2.
   
   3. The `Prometheus` type appender is used as you noted in the log4j2.yaml 
under Appenders
   ```
       Prometheus:
         name: Prometheus
   ```
   and then referenced to "forward" the logs to that appender so they can be 
counted.
   ```
       # Default root logger configuration
       Root:
         level: "${sys:pulsar.log.root.level}"
         additivity: true
         AppenderRef:
           - ref: "${sys:pulsar.log.appender}"
             level: "${sys:pulsar.log.level}"
           - ref: Prometheus
             level: info
   ```
   
   4. Log4j previously allowed to configure which packages to scan for 
existence of the classes you need to extend if you wish to add a plugin. As you 
@nodece noted in the link you provided, you don't really need it. You just need 
the plugin to have the `@Plugin` annotation, which it does. This mean we can 
safely remove the `packages` line from log4j2.yaml.
   
   You do need to verify the Prometheus log4j metrics are still exposed as 
double check.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to