Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-1231

Log files are under lock, not able to view them until JVM stop.

    XMLWordPrintableJSON

    Details

    • Type: Question
    • Status: Closed
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: 2.5
    • Fix Version/s: 2.6
    • Component/s: Appenders
    • Labels:
    • Environment:

      window, jre 1.7, IBM Integration Bus

    • Flags:
      Important

      Description

      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>
      

        Attachments

        1. log4j.zip
          4 kB
          Yogesh Bhardwaj

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              yogi189 Yogesh Bhardwaj
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 504h
                504h
                Remaining:
                Remaining Estimate - 504h
                504h
                Logged:
                Time Spent - Not Specified
                Not Specified