我已经解决了 mac 中 log4j.xml 的路径问题:
在 windows 中,我们在 web.xml 中配置 log4j,例如:
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>file:${LOG4J_HOME}/conf/log4j.xml</param-value>
<!-- Above path is that where we have stored log4j.xml file externally -->
</context-param>
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>6000</param-value>
</context-param>
其中 ${LOG4J_HOME} 是我们用来在窗口中设置的用户变量。喜欢
用户变量 = LOG4J_HOME
value = D:/LOG4J(在 d 驱动器中,我们创建了一个名为 Log4J 的文件夹,我们复制了该路径并作为值提供)
在 mac 中,我们可以通过 bash 命令设置环境变量,但它不再起作用了。
所以对于 mac,我们必须在任何地方创建一个文件夹,并且我们必须提供该文件夹的静态路径。
喜欢在 xml 中:
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>file:/Users/vardhaman/Desktop/LOG4J/conf/log4j.xml</param-value>
<!-- Above path is that where we have stored log4j.xml file externally to get this path go up to the log4j.xml file in external device and right click select get info, where we will get path, copy that path -->
</context-param>
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>6000</param-value>
</context-param>
我们必须在 log4j.xml 文件中做同样的事情
在窗口中我们用来做类似的事情:
<appender name="CLICK-SPRING" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${LOG4J_HOME}/logs/CLICK/CLICK-spring.log"/>
<param name="Append" value="true"/>
<param name="Threshold" value="DEBUG"/>
<param name="MaxFileSize" value="100MB"/>
<param name="MaxBackupIndex" value="10" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %p [%t] %C{1}.%M(%L) | %m%n"/>
</layout>
</appender>
在mac中:
我们必须将静态路径复制到文件夹 LOG4J 来代替 value,或者您可以创建任何文件夹。
<appender name="CLICK-SPRING" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="Users/vardhaman/Desktop/LOG4J/logs/CLICK/CLICK-spring.log"/>
<param name="Append" value="true"/>
<param name="Threshold" value="DEBUG"/>
<param name="MaxFileSize" value="100MB"/>
<param name="MaxBackupIndex" value="10" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %p [%t] %C{1}.%M(%L) | %m%n"/>
</layout>
</appender>