-
1. Re: JBoss 7 Logging
jamezp Feb 12, 2012 1:39 PM (in response to foutjo)Joseph,
No custom logger is needed in this case at all. It sounds like what you want to use is a periodic-rotating-file-handler. The easiest way to configure this would be through one of the management consoles.
In the CLI console you would do the following.
Create the first handler:
/subsystem=logging/periodic-rotating-file-handler=log1:add(file={"relative-to"=>"jboss.server.log.dir","path"=>"log1.log"},suffix=".yyyy-MM-dd",level=ALL,append=true,autoflush=true)
Create the second handler:
/subsystem=logging/periodic-rotating-file-handler=log2:add(file={"relative-to"=>"jboss.server.log.dir","path"=>"log2.log"},suffix=".yyyy-MM-dd",level=WARN,append=true,autoflush=true)
Create a logger and attach the handlers:
/subsystem=logging/logger=com.myApp:add(level=ALL,handlers=["log1","log2"])
You could also use the web console to achieve the same results.
The XML in would look something like this:
<subsystem xmlns="urn:jboss:domain:logging:1.1"> ... <periodic-rotating-file-handler name="log1" autoflush="true"> <level name="ALL"/> <file relative-to="jboss.server.log.dir" path="log1.log"/> <suffix value=".yyyy-MM-dd"/> <append value="true"/> </periodic-rotating-file-handler> <periodic-rotating-file-handler name="log2" autoflush="true"> <level name="WARN"/> <file relative-to="jboss.server.log.dir" path="log2.log"/> <suffix value=".yyyy-MM-dd"/> <append value="true"/> </periodic-rotating-file-handler> <logger category="com.myApp"> <level name="ALL"/> <handlers> <handler name="log1"/> <handler name="log2"/> </handlers> </logger> ... </subsystem>
--
James R. Perkins
-
2. Re: JBoss 7 Logging
foutjo Feb 13, 2012 2:15 PM (in response to jamezp)Thanks James I was able to get my sample to work with jboss logging.
When I setup the loggers I edited the standalone.xml directly. Is this not a good thing or should I be using the console or the web browser?
Thanks.
-
3. Re: JBoss 7 Logging
jamezp Feb 13, 2012 2:18 PM (in response to foutjo)Joseph,
Editing the XML is not a problem at all. I tend to use the consoles because it shows all the options and I don't have to remember the options for each type of handler.
--
James R. Perkins
-
4. Re: JBoss 7 Logging
leamenli Apr 9, 2012 6:13 AM (in response to jamezp)Hi James,
I wander how can I create daily log in JBoss 7 ?
I used log4j before, it can create a new log file each day (the old logs not been removed), besides, it can create new log file when file size larger than a given max size.
Does JBoss 7 logging support such feature? How should I config the standalone.xml if I want the same effect?
Thank you.
-
5. Re: JBoss 7 Logging
traian20 Apr 9, 2012 6:46 AM (in response to leamenli)Jboss logging subsystem supports
periodic-rotating-file-handler and size-rotating-file-handler.
<size-rotating-file-handler name="FILE">
<formatter>
<pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
</formatter>
<file relative-to="jboss.server.log.dir" path="server.log"/>
<rotate-size value="5000k"/>
<max-backup-index value="10"/>
<append value="true"/>
</size-rotating-file-handler>
-
6. Re: JBoss 7 Logging
jamezp Apr 9, 2012 11:31 AM (in response to leamenli)In the latest upstream latest upstream of the JBoss Log Manager there is a new handler that will roll on date and/or size. I'm not sure when that will get pushed to JBoss AS7 though.
Currently you will only be able to roll a log by size or date, but not both. Though if you wanted you could write your own handler, add as a module and configure it through a custom-handler.
-
7. Re: JBoss 7 Logging
ohmygod Jul 22, 2012 11:20 PM (in response to jamezp)I defined a handler log1 to output category com.cate1 messages to log file1.
<logger category="com.cate1"> <level name="INFO"/> <handlers> <handler name="log1"/> </handlers> </logger>
But I found all this category's messages are also output to CONSOLE. How to disable this output to CONSOLE. I want them to only go to log file1.
-
8. Re: JBoss 7 Logging
jamezp Jul 23, 2012 11:22 AM (in response to ohmygod)On your logger you need to add the use-parent-handler attribute and set it to false. That will only process loggers defined as com.cate1 to only process through the log1 handler.
<logger category="com.cate1" use-parent-handlers="false"> <level name="INFO"/> <handlers> <handler name="log1"/> </handlers> </logger>
--
James R. Perkins
-
9. Re: JBoss 7 Logging
ohmygod Jul 23, 2012 12:29 PM (in response to jamezp)Thanks James, is there any documentation about the optional attributes?
-
-
11. Re: JBoss 7 Logging
ohmygod Jul 24, 2012 2:26 AM (in response to jamezp)Thanks James. Sorry that I have another question. I have my root logger including ouput to CONSOLE and logfile. The question is why the log.info() in my code all output to CONSOLE. I can confirm in old version JBoss log.info() in my code only output to logfile handler.
<root-logger> <level name="INFO"/> <handlers> <handler name="CONSOLE"/> <handler name="logfile"/> </handlers> </root-logger>
Another question: why cannot using following settings get demo.log.yyyyMMdd format for a daily log output? (Still one demo.log fle after another day) And how long is the period rotation?
<periodic-rotating-file-handler name="demo" autoflush="true"> <formatter> <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/> </formatter> <file relative-to="jboss.server.log.dir" path="../../../../logs/demo.log"/> <suffix value=".yyyyMMdd"/> <append value="true"/> </periodic-rotating-file-handler>
-
12. Re: JBoss 7 Logging
jamezp Jul 24, 2012 11:20 AM (in response to ohmygod)Thanks James. Sorry that I have another question. I have my root logger including ouput to CONSOLE and logfile. The question is why the log.info() in my code all output to CONSOLE. I can confirm in old version JBoss log.info() in my code only output to logfile handler.
<root-logger> <level name="INFO"/> <handlers> <handler name="CONSOLE"/> <handler name="logfile"/> </handlers> </root-logger>
It's because you have the CONSOLE handler defined on the root logger I would assume. Could you paste your entire logging subsystem configuration?
Another question: why cannot using following settings get demo.log.yyyyMMdd format for a daily log output? (Still one demo.log fle after another day) And how long is the period rotation?
<periodic-rotating-file-handler name="demo" autoflush="true"> <formatter> <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/> </formatter> <file relative-to="jboss.server.log.dir" path="../../../../logs/demo.log"/> <suffix value=".yyyyMMdd"/> <append value="true"/> </periodic-rotating-file-handler>
This was a bug that was fixed in JBoss Log Manager. If you were to leave the sever up for more than 24 hours it would roll. The change is upstream, just not in any community releases at this point.
--
James R. Perkins
-
13. Re: JBoss 7 Logging
ohmygod Jul 24, 2012 11:26 AM (in response to jamezp)Thanks, James. Here is my entire subsystem for the logging.
<console-handler name="CONSOLE" autoflush="true"> <level name="INFO"/> <formatter> <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/> </formatter> </console-handler> <periodic-rotating-file-handler name="demo" autoflush="true"> <formatter> <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/> </formatter> <file relative-to="jboss.server.log.dir" path="../../../../logs/demo.log"/> <suffix value=".yyyyMMdd"/> <append value="true"/> </periodic-rotating-file-handler> <logger category="com.arjuna"> <level name="WARN"/> </logger> <logger category="org.apache.tomcat.util.modeler"> <level name="WARN"/> </logger> <logger category="sun.rmi"> <level name="WARN"/> </logger> <logger category="jacorb"> <level name="WARN"/> </logger> <logger category="jacorb.config"> <level name="ERROR"/> </logger> <root-logger> <level name="INFO"/> <handlers> <handler name="CONSOLE"/> <handler name="demo"/> </handlers> </root-logger>
-
14. Re: JBoss 7 Logging
jamezp Jul 24, 2012 11:47 AM (in response to ohmygod)What you would need to do is define a logger with the category of your logger. Assign the demo handler to that logger and set the use-parent-handler to false. If you also want system log messages to go into the file, then you'll need to keep the demo handler on the root-logger too.
Should probably look something like this:
<console-handler name="CONSOLE" autoflush="true"> <level name="INFO"/> <formatter> <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/> </formatter> </console-handler> <periodic-rotating-file-handler name="demo" autoflush="true"> <formatter> <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/> </formatter> <file relative-to="jboss.server.log.dir" path="../../../../logs/demo.log"/> <suffix value=".yyyyMMdd"/> <append value="true"/> </periodic-rotating-file-handler> <!-- Only log to the demo handler --> <logger category="demo.category" use-parent-handlers="false"> <level name="INFO"/> <handlers> <handler name="demo"/> </handlers> </logger> <logger category="com.arjuna"> <level name="WARN"/> </logger> <logger category="org.apache.tomcat.util.modeler"> <level name="WARN"/> </logger> <logger category="sun.rmi"> <level name="WARN"/> </logger> <logger category="jacorb"> <level name="WARN"/> </logger> <logger category="jacorb.config"> <level name="ERROR"/> </logger> <root-logger> <level name="INFO"/> <handlers> <handler name="CONSOLE"/> <!-- Logs all messages to the demo handler --> <handler name="demo"/> </handlers> </root-logger>
--
James R. Perkins