vy commented on issue #3442:
URL: 
https://github.com/apache/logging-log4j2/issues/3442#issuecomment-2676323382

   @lu-xiaoshuang, in #3482, I see you randomly choose hosts to write to. Can't 
you simply define multiple socket appenders and choose them using [scripted 
routes](https://logging.apache.org/log4j/2.x/manual/appenders/delegating.html#RoutingAppender-example-script):
   
   ```xml
   <Configuration xmlns="https://logging.apache.org/xml/ns";
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
                  xsi:schemaLocation="
                      https://logging.apache.org/xml/ns
                      https://logging.apache.org/xml/ns/log4j-config-2.xsd";>
     <Appenders>
       <Routing name="ROUTING">
         <Script language="groovy">
           staticVariables.hosts = [
               'h1.example.com',
               'h2.example.com',
               'h3.example.com'
           ];
           staticVariables.random = new Random();
         </Script>
         <Routes>
           <Script language="groovy">
             int hostIndex = 
staticVariables.random.nextInt(staticVariables.hosts.length);
             String host = staticVariables.hosts[hostIndex];
             return configuration.properties['host'] = host;
           </Script>
           <Route>
             <Socket name="${host}"
                     protocol="TCP"
                     host="${host}"
                     port="500">
               <JsonTemplateLayout/>
             </Socket>
           </Route>
         </Routes>
       </Routing>
     </Appenders>
     <Loggers>
       <Root level="INFO">
         <AppenderRef ref="ROUTING"/>
       </Root>
     </Loggers>
   </Configuration>
   ```


-- 
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: notifications-unsubscr...@logging.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to