Yeah - Each RollingFile appender is only going to be created once for each type 
value so it will always use the value of path from the first request. To do 
what you want with the RoutingAppender you would have to add a second 
RoutingAppender inside each Route where your RollingFile Appender currently is 
and have that route based on the path. 

I should point out that the model you are using can become very expensive if 
the number of paths is large as you will have many open files that only close 
when the application stops. To combat this you might consider implementing a 
PurgePolicy to remove Appenders as their jobs complete. You could look at the 
IdlePurgePolicy to get any idea how to accomplish that.

Ralph




> On Mar 2, 2021, at 12:21 PM, Niranjan Rao <nhr...@gmail.com> wrote:
> 
> Greetings,
> 
> 
> We are using log4j 2.13.3 and a routing appender. This works correctly as 
> desired but we would like to split routing in two files per id. Following is 
> a snippet from my configuration file.
> 
> Essentially we are doing what can be called as a job. We want to separate out 
> the logs for main engine, and a job. Job logs need to be separated into 
> driver and job log and these logs need to go to a specific directory that is 
> specific to the job. In the following scenario, logs get split correctly 
> based on "type" set, but once route is created, it does not notice "ctx:path" 
> change and messages are directed to only one path.
> 
> 
> How do I configure it so that I can route based on path as well as type?
> 
> 
>      <Routing name="RoutingAppender">
>       <Routes pattern="$${ctx:type}">
>         <Route key="driver">
>           <RollingFile name="Driver logs" fileName="${ctx:path}/driver.log"
>                        filePattern="${ctx:path}/driver.%i.log">
>             <PatternLayout>...</PatternLayout>
>           </RollingFile>
>         </Route>
>         <Route key="job">
>           <RollingFile name="job logs" fileName="${ctx:path}/job.log"
>                        filePattern="${ctx:path}/job.%i.log">
>            <PatternLayout>...</PatternLayout>
>           </RollingFile>
>         </Route>
> 
>         <Route>
>           <RollingFile name="default" fileName="/tmp/mainlog.log"
> filePattern="/tmp/mainlogs/logs/${date:yyyy-MM}/cdp-%d{yyyy-MM-dd}-%i.log">
>           </RollingFile>
>         </Route>
>       </Routes>
>       <IdlePurgePolicy timeToLive="15" timeUnit="minutes"/>
>     </Routing>
> 
> Regards,
> 
> 
> Niranjan
> 
> 
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
> For additional commands, e-mail: log4j-user-h...@logging.apache.org
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org

Reply via email to