Yogesh Bhardwaj created LOG4J2-1231:
---------------------------------------

             Summary: Log files are under lock, not able to view them until JVM 
stop.
                 Key: LOG4J2-1231
                 URL: https://issues.apache.org/jira/browse/LOG4J2-1231
             Project: Log4j 2
          Issue Type: Question
          Components: Appenders
    Affects Versions: 2.5
         Environment:  window, jre 1.7, IBM Integration Bus
            Reporter: Yogesh Bhardwaj
            Priority: Blocker
             Fix For: 2.5.1


Hi Team,
The problem is when I use file appender with below configuration.

In each application thread I am calling "initLog4j" followed by other function 
mentioned in below class, JVM at server level not application level which is 
configured to load log4j specific jar files. The log files are getting created 
as per my configuration but being a Admin when I try to open them I am getting 
messages " document "..........." is under use by some other application and 
can't be accessed." I can see one thread is still running although my 
application thread is ended.

As per my understanding if admin can't see the logs even when application is 
running, no use of such logging , Could you please confirm is this expected 
behavior, is their any alternative for this.....?

Daemon Thread :
Daemon Thread [MemoryPoolMXBean notification dispatcher] (Running)      




My class
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class log4j {
        public log4j() {
        }

        public static void initLog4j(String logPath1, String filename1) {
                String env = System.getenv("MQSI_WORKPATH");
                String fs = System.getProperty("file.separator");
                String filePath = logPath1;
                System.setProperty("logPath", filePath);
                System.setProperty("fileName", filename1);

                String configFilePath = (new StringBuilder(String.valueOf(env)))
                                .append(fs).append("shared-classes").append(fs)
                                .append("log4j2.xml").toString();
                System.setProperty("log4j.configurationFile", configFilePath);
        }

        public static void logDebug(String logText) {
                String loggerName = logText.substring(logText.indexOf('[') + 1,
                                logText.indexOf(']'));
                Logger logger = LogManager.getLogger(loggerName);
                logger.debug(logText);
        }

        public static void logInfo(String logText) {
                String loggerName = logText.substring(logText.indexOf('[') + 1,
                                logText.indexOf(']'));
                Logger logger = LogManager.getLogger(loggerName);
                logger.info(logText);
        }

        public static void logWarn(String logText) {
                String loggerName = logText.substring(logText.indexOf('[') + 1,
                                logText.indexOf(']'));
                Logger logger = LogManager.getLogger(loggerName);
                logger.warn(logText);
        }
        
        public static void logTrace(String logText) {
                String loggerName = logText.substring(logText.indexOf('[') + 1,
                                logText.indexOf(']'));
                Logger logger = LogManager.getLogger(loggerName);
                logger.trace(logText);
        }

        public static void logError(String logText) {
                String loggerName = logText.substring(logText.indexOf('[') + 1,
                                logText.indexOf(']'));
                Logger logger = LogManager.getLogger(loggerName);
                logger.error(logText);
        }
}




log4j.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
        <Appenders>
                <File name="info-log" 
fileName="${sys:logPath}/${sys:fileName}_info.log" immediateFlush="true">
                        <PatternLayout
                                pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} 
[%t] %c{1} - %msg%n" />
                </File>
                <File name="trace-log" 
fileName="${sys:logPath}/${sys:fileName}_trace.log" immediateFlush="true">
                        <PatternLayout
                                pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} 
[%t] %c{1} - %msg%n" />
                </File>
                <File name="error-log" 
fileName="${sys:logPath}/${sys:fileName}_error.log" immediateFlush="true">
                        <PatternLayout
                                pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} 
[%t] %c{1} - %msg%n" />
                </File>
                <File name="debug-log" 
fileName="${sys:logPath}/${sys:fileName}_debug.log" immediateFlush="true">
                        <PatternLayout
                                pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} 
[%t] %c{1} - %msg%n" />
                </File>
                <File name="warn-log" 
fileName="${sys:logPath}/${sys:fileName}_warn.log" immediateFlush="true">
                        <PatternLayout
                                pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} 
[%t] %c{1} - %msg%n" />
                </File>
        </Appenders>
        <Loggers>
                <Root level="trace">
                        <AppenderRef ref="trace-log" level="TRACE" />
                        <AppenderRef ref="info-log" level="INFO" />
                        <AppenderRef ref="warn-log" level="WARN" />
                        <AppenderRef ref="debug-log" level="DEBUG" />
                        <AppenderRef ref="error-log" level="ERROR" />
                </Root>
        </Loggers>
</Configuration>



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

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

Reply via email to