Fyi You need to create tomcat folder, bin/setenv.bat on windows or sh on
Linux
https://stackoverflow.com/questions/9480210/tomcat-7-setenv-sh-is-not-found

On Fri, 7 Jan, 2022, 04:28 Bruno Melloni, <x.lo...@melloni.com> wrote:

> Success!
>
> The issue turned out to be that placing the log4j2 jars and
> log4j2-tomcat.xml in the tomcat/lib folder no longer works.
>
> The solution:
>
>   * Followed the official instructions to the letter
>     (https://logging.apache.org/log4j/2.x/log4j-appserver/index.html)
>   * Used this canned log4j2-tomcat.xml file that replicates the original
>     tomcat files but using log4j
>     (https://gist.github.com/bmaupin/475a0cd6e8b374d876f5085846761fb6)
>   * Could not edit setenv.sh in Windows (does not exist), so instead I
>     added the following (knowingly ugly and inflexible code - for now)
>     to catalina.bat:
>
>       * set
>
> "CLASSPATH=%CLASSPATH%;%CATALINA_HOME%\log4j2\lib\log4j-api-2.17.1.jar"
>       * set
>
> "CLASSPATH=%CLASSPATH%;%CATALINA_HOME%\log4j2\lib\log4j-core-2.17.1.jar"
>       * set
>
> "CLASSPATH=%CLASSPATH%;%CATALINA_HOME%\log4j2\lib\log4j-appserver-2.17.1.jar"
>       * set "CLASSPATH=%CLASSPATH%;%CATALINA_HOME%\log4j2\conf"
>
> It now puts all of Tomcat's logging in the files, with virtually nothing
> in the console.
>
> I hope the solution (or an improved version of this) helps others.
>
> bruno
>
> On 1/6/2022 5:34 PM, Ralph Goers wrote:
> > I haven’t checked Tomcat 9, but the log4j-appserver module was created
> to hook into Tomcat 8.5 and up. I just not sure if Tomcat changed their
> logging mechanism yet again.
> >
> > Ralph
> >
> >> On Jan 6, 2022, at 2:43 PM, Bruno Melloni<x.lo...@melloni.com>  wrote:
> >>
> >> A correction, after doing more troubleshooting and using even the
> >> original log4j2.xml (on the previous install) it seems that the old
> >> version was logging nothing to the files from Tomcat itself, and was
> >> displaying everything on the console instead... in whatever mechanism it
> >> wanted, so only my own apps were logging to the log4j files, with the
> >> Tomcat output getting lost.
> >>
> >> So, the problem remains, it is not clear at all how you configure Tomcat
> >> 9 to use log4j2 after all, and none of the guides on the internet are
> >> complete enough to follow verbatim.
> >>
> >> On 1/6/2022 11:37 AM, Bruno Melloni wrote:
> >>> A couple months ago I had no problem configuring Tomcat 9 with java 16
> to use log4j2.
> >>>
> >>> That time I simply deleted tomcat/conf/*logging.properties*, added to
> *tomcat/lib* the following files and it worked.
> >>>
> >>>   * log4j-api-2.*.jar
> >>>   * log4j-core-2.*.jar
> >>>   * log4j-appserver-2.*.jar
> >>>   * log4j2.xml
> >>>
> >>> Now I am setting up a new tomcat 9.0.56 with java 17 and log4j 2.17.1,
> followed the same steps with one difference... I tweaked the log4j2.xml to
> try to make it cleaner and easier to maintain/adjust.
> >>>
> >>> Unfortunately my new setup is failing to log anything at all. The only
> place where I see something is on the console and it looks like it is not
> even log4j output as it does not match the pattern I expected.  I think I
> am misunderstanding something about the use of properties in a log4j2.xml
> file or I have some really dumb typo.
> >>>
> >>> I hope someone can give a glance at the following and tell me where I
> messed up:
> >>>
> >>> <?xml version="1.0" encoding="UTF-8"?>
> >>> <Configuration status="INFO"> <!-- used for internal log4j2 logging,
> not related to apps or server -->
> >>>    <Properties>
> >>>      <Property name="appslogdir">D:/work/app-j17t9-C/logs</Property>
> >>>      <Property
> name="appsarchivedir">D:/work/app-j17t9-C/logs/archive</Property>
> >>>      <Property
> name="serverlogdir">D:/work/app-j17t9-C/logs/server</Property>
> >>>      <Property
> name="serverarchivedir">D:/work/app-j17t9-C/logs/server/archive</Property>
> >>>      <Property name="layout">%d %-5p [%C] %m%n</Property>
> >>>      <Property name="rolloversize">10 MB</Property>
> >>>    </Properties>
> >>>    <Appenders>
> >>>      <Console name="CONSOLE" target="SYSTEM_OUT">
> >>>        <PatternLayout pattern="${layout}"/>
> >>>      </Console>
> >>>      <RollingFile name="FILE" fileName="${appslogdir}/apps.txt"
> filePattern="${appsarchivedir}/$${date:yyyy-MM}/apps-%d{MM-dd-yyyy}-%i.log.gz">
> >>>        <PatternLayout pattern="${layout}">
> >>>        <Policies>
> >>>         <TimeBasedTriggeringPolicy />
> >>>         <SizeBasedTriggeringPolicy size="${rolloversize}"/>
> >>>        </Policies>
> >>>        <DefaultRolloverStrategy max="24"/>
> >>>      </RollingFile>
> >>>      <RollingFile name="EMAIL" fileName="${appslogdir}/email.txt"
> filePattern="${appsarchivedir}/$${date:yyyy-MM}/email-%d{MM-dd-yyyy}-%i.log.gz">
> >>>        <PatternLayout pattern="${layout}">
> >>>        <Policies>
> >>>         <TimeBasedTriggeringPolicy />
> >>>         <SizeBasedTriggeringPolicy size="${rolloversize}"/>
> >>>        </Policies>
> >>>        <DefaultRolloverStrategy max="24"/>
> >>>      </RollingFile>
> >>>      <!-- TOMCAT server appenders -->
> >>>      <RollingFile name="CATALINA"
> fileName="${serverlogdir}/catalina.txt"
> filePattern="${serverarchivedir}/$${date:yyyy-MM}/catalina-%d{MM-dd-yyyy}-%i.log.gz">
> >>>        <PatternLayout pattern="${layout}"/>
> >>>        <Policies>
> >>>         <TimeBasedTriggeringPolicy />
> >>>         <SizeBasedTriggeringPolicy size="${rolloversize}"/>
> >>>        </Policies>
> >>>        <DefaultRolloverStrategy max="24"/>
> >>>      </RollingFile>
> >>>      <RollingFile name="LOCALHOST"
> fileName="${serverlogdir}/localhost.txt"
> filePattern="${serverarchivedir}/$${date:yyyy-MM}/localhost-%d{MM-dd-yyyy}-%i.log.gz">
> >>>        <PatternLayout pattern="${layout}"/>
> >>>        <Policies>
> >>>         <TimeBasedTriggeringPolicy />
> >>>         <SizeBasedTriggeringPolicy size="${rolloversize}"/>
> >>>        </Policies>
> >>>        <DefaultRolloverStrategy max="24"/>
> >>>      </RollingFile>
> >>>      <RollingFile name="MANAGER"
> fileName="${serverlogdir}/manager.txt"
> filePattern="${serverarchivedir}/$${date:yyyy-MM}/manager-%d{MM-dd-yyyy}-%i.log.gz">
> >>>        <PatternLayout pattern="${layout}"/>
> >>>        <Policies>
> >>>         <TimeBasedTriggeringPolicy />
> >>>         <SizeBasedTriggeringPolicy size="${rolloversize}"/>
> >>>        </Policies>
> >>>        <DefaultRolloverStrategy max="24"/>
> >>>      </RollingFile>
> >>>      <RollingFile name="HOSTMANAGER"
> fileName="${serverlogdir}/host-manager.txt"
> filePattern="${serverarchivedir}/$${date:yyyy-MM}/host-manager-%d{MM-dd-yyyy}-%i.log.gz">
> >>>        <PatternLayout pattern="${layout}"/>
> >>>        <Policies>
> >>>         <TimeBasedTriggeringPolicy />
> >>>         <SizeBasedTriggeringPolicy size="${rolloversize}"/>
> >>>        </Policies>
> >>>        <DefaultRolloverStrategy max="24"/>
> >>>      </RollingFile>
> >>>    </Appenders>
> >>>    <Loggers>
> >>>      <Root level="info">
> >>>      <!-- Root level="error" -->
> >>>        <AppenderRef ref="CONSOLE"/>
> >>>        <AppenderRef ref="FILE"/>
> >>>      </Root>
> >>>      <!-- avoid duplicated logs with additivity=false -->
> >>>      <Logger name="net.cndc" level="debug" additivity="false">
> >>>        <AppenderRef ref="CONSOLE"/>
> >>>        <AppenderRef ref="FILE"/>
> >>>      </Logger>
> >>>      <!-- OPEN SOURCE LIBRARY loggers -->
> >>>      <Logger name="org.springframework" level="warn"/>
> >>>      <!-- TOMCAT SERVER loggers -->
> >>>      <Logger
> name="org.apache.catalina.core.ContainerBase.[Catalina].[localhost]"
> level="info" additivity="false">
> >>>        <AppenderRef ref="LOCALHOST" />
> >>>      </Logger>
> >>>      <Logger
> name="org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager]"
> level="info" additivity="false">
> >>>        <AppenderRef ref="MANAGER" />
> >>>      </Logger>
> >>>      <Logger
> name="org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager]"
> level="info" additivity="false">
> >>>        <AppenderRef ref="HOSTMANAGER" />
> >>>      </Logger>
> >>>      <Logger name="org.apache.catalina" level="info"
> additivity="false"> <!-- Might need to tweak this, normally is Root -->
> >>>        <AppenderRef ref="CATALINA" />
> >>>      </Logger>
> >>>    </Loggers>
> >>> </Configuration>
> >>>
> >> ---------------------------------------------------------------------
> >> 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