Avatar billede fredand Forsker
25. januar 2010 - 20:56 Der er 1 kommentar

Is this possible with log4j?

Hello guys!

I had to rush from work today with out solving this issue.

I tried to configure my JBoss 5 in the jboss-log4j.xml to produce 2 separate log files.

1 for a ear (deployed in a separate, ear like company.ear)
1 for a war (deployed in a separate, war like company.war)

...running in the same JBoss.
Below is the snippets from jboss-log4j.xml.

The problem is that logging for the ear shall handle only all classes (from within the ear) that call the log with package starting with:
com.projectx

...and logging for the war shall handle only all classes (from within the war) that call the log with package starting with:
com.projectx.web

But what I end up with is one nice log file (web.log) with all logging from the war.
...AND a not so nice log file (server.log) with logging from both the ear and war.

I guess this is because of the package got the same starting.

I of course want them totally separated.
So if you got any solutions for this please let me know.
I hope I do not need to force the server to change the package-name.

Best regards
Fredrik

  <appender name="WEB-ROLLINGFILE" class="org.apache.log4j.RollingFileAppender">
        <param name="File" value="${jboss.server.log.dir}/web.log"/>
        <param name="Append" value="true"/>
        <param name="MaxFileSize" value="500KB"/>
        <param name="maxBackupIndex" value="10"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern"
              value="%d{ISO8601} %-5p %.25c{1}->%.25M - %m%n"/>
        </layout>
        <filter class="org.apache.log4j.varia.LevelRangeFilter">
            <param name="LevelMin" value="debug" />
            <param name="LevelMax" value="fatal" />
            <param name="AcceptOnMatch" value="true" />
        </filter>
        <filter class="org.apache.log4j.varia.DenyAllFilter"/>
  </appender>

 
  <appender name="SERVER-ROLLINGFILE" class="org.apache.log4j.RollingFileAppender">
        <param name="File" value="${jboss.server.log.dir}/server.log"/>
        <param name="Append" value="true"/>
        <param name="MaxFileSize" value="500KB"/>
        <param name="maxBackupIndex" value="10"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern"
              value="%d{ISO8601} %-5p %.25c{1}->%.25M - %m%n"/>
        </layout>
        <filter class="org.apache.log4j.varia.LevelRangeFilter">
            <param name="LevelMin" value="debug" />
            <param name="LevelMax" value="fatal" />
            <param name="AcceptOnMatch" value="true" />
        </filter>
        <filter class="org.apache.log4j.varia.DenyAllFilter"/>
  </appender>

  <category name="com.projectx.web">
        <level value="DEBUG" />
        <appender-ref ref="WEB-ROLLINGFILE"/>
  </category>
 
  <category name="com.projectx">
      <level value="DEBUG"/>
      <appender-ref ref="SERVER-ROLLINGFILE"/>
  </category>
Avatar billede arne_v Ekspert
25. januar 2010 - 21:04 #1
So to rephrase then you need either to filter on code location (war/ear) or alternative filter like allow all com.projectx except com.projectx.web ?
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester