[ 
https://issues.apache.org/jira/browse/LOG4J2-3457?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17515220#comment-17515220
 ] 

Piotr Karwasz commented on LOG4J2-3457:
---------------------------------------

[~PoojaTheCoder],

Remark, that acquiring a file lock for each log message is already implemented 
in Log4j2's {{FileAppender}} (cf. [locking 
parameter|https://logging.apache.org/log4j/2.x/manual/appenders.html#FileAppender]).
 The lack of the same option in the {{RollingFileAppender}} can be definitely 
addressed, since it is just a configuration problem. By a rudimentary 
benchmark, with this feature on your throughput is decreased 2x.

I don't understand what's the "*.roll" file purpose in your code, since it does 
not appear to be created anywhere. I believe you don't need this feature for 
time-based triggering policies (when you use these policies log files are never 
renamed). For size-based triggering policies you might reimplement your 
appender by creating a custom {{SizeBasedTriggeringPolicy}} that reads the real 
size of the file from time to time (Log4j2 never does that, it triggers 
rollovers based on the amount of bytes it wrote to the file) and does something 
to prevent multiple applications from rolling over at the same time. That will 
cost you even more performance.

Personally I wouldn't bother implementing such a complex feature and I would 
use a {{SyslogAppender}} (or {{FlumeAppender}}) and delegate the writing of the 
log files to those applications.

> Log4j 1.x 2.17.2 bridge - Does standard RollingFileAppender supports multiple 
> process writing to same log file at the same time??
> ---------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: LOG4J2-3457
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3457
>             Project: Log4j 2
>          Issue Type: Question
>          Components: Log4j 1.2 bridge
>    Affects Versions: 2.17.2
>            Reporter: Pooja Pandey
>            Assignee: Piotr Karwasz
>            Priority: Major
>         Attachments: 
> CitedText-RollingFileAppenderNoSupportForMultProcessWritingToSameFile.PNG, 
> CustomLogger.java, CustomLoggerFactory.java, 
> CustomMultiProcessRollingAppender.java, JavaLoggingMultiThTest.java, 
> customlog.properties
>
>
> In our application we require a rolling file appender which can be used 
> across multiple processes targeting the same file.
> I wanted to check if current log4j1.x 2.17.2 bridge version supports multi 
> process rolling file appender, if not then is there any plan to support this 
> feature in future releases??
> For reference, as per our application requirement, I am attaching sample java 
> class files for custom appender, custom multi process rolling appender, 
> sample test program with multiple threads for which we can run multiple 
> instances to test multi process rolling and log4j property 
> file.[^CustomLogger.java][^JavaLoggingMultiThTest.java][^customlog.properties]
>  
> In one of the mail chain to group Log4J Users List 
> <log4j-u...@logging.apache.org>,  [~ralphgoers] pointed out that 
> {color:#ff0000}_"FWIW the Log4j 2 RollingFileAppender does not support being 
> used across multiple processes targeting the same file either. I’d love to 
> know how you avoided having the file roll multiple times (once for each 
> process)"_{color}. 
> !CitedText-RollingFileAppenderNoSupportForMultProcessWritingToSameFile.PNG|width=756,height=434!



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to