-
1. Re: JBoss7 Logging Rotating Feature
jamezp Apr 13, 2012 3:00 PM (in response to tcwang88)We just did change the way the rollover by date works. We now first look at the file's last modification date to determine when to rollover, but that does you know good now :-) For testing though on the periodic rotating file you could change the suffix to mm which would be minutes.
There is no handler for rotating on subsequent start-ups. You could easily write one and use a custom handler though. It would be simple enough to extend either java.util.logging.FileHandler or org.jboss.logmanager.handlers.FileHandler and on the setFile() method just check if the file exists. If it exists rename it to a new file name.
Something like this might work.
import java.io.File; import java.io.FileNotFoundException; import org.jboss.logmanager.handlers.FileHandler; /** * @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a> */ public class BootRotatingFileHandler extends FileHandler { private int maxBackupIndex = 1; public BootRotatingFileHandler() { super(); } public BootRotatingFileHandler(final File file) throws FileNotFoundException { super(file); } public BootRotatingFileHandler(final String fileName) throws FileNotFoundException { super(fileName); } public BootRotatingFileHandler(final File file, final int maxBackupIndex) throws FileNotFoundException { this.maxBackupIndex = maxBackupIndex; setFile(file); } public BootRotatingFileHandler(final String fileName, final int maxBackupIndex) throws FileNotFoundException { this.maxBackupIndex = maxBackupIndex; setFileName(fileName); } @Override public void setFile(final File file) throws FileNotFoundException { if (file != null) { synchronized (outputLock) { rotateFile(file); } } super.setFile(file); } /** * Set the maximum backup index (the number of log files to keep around). * * @param maxBackupIndex the maximum backup index */ public void setMaxBackupIndex(final int maxBackupIndex) { checkAccess(this); synchronized (outputLock) { this.maxBackupIndex = maxBackupIndex; } } private void rotateFile(final File file) { final int maxBackupIndex = this.maxBackupIndex; if (maxBackupIndex > 0) { if (file == null) { return; } new File(file.getAbsolutePath() + "." + maxBackupIndex).delete(); for (int i = maxBackupIndex - 1; i >= 1; i--) { new File(file.getAbsolutePath() + "." + i).renameTo(new File(file.getAbsolutePath() + "." + (i + 1))); } file.renameTo(new File(file.getAbsolutePath() + ".1")); } } }
-
2. Re: JBoss7 Logging Rotating Feature
tcwang88 Apr 13, 2012 9:21 PM (in response to jamezp)Hi James,
Thanks for the information you provided. The custom-handler works well and that is what I expect.
Sincerely,
Tzu-Chi
-
3. Re: JBoss7 Logging Rotating Feature
tcwang88 Apr 16, 2012 6:06 PM (in response to jamezp)Hi James,
To extend from
org.jboss.logmanager.handlers.FileHandler
works fine for me right now; however, I tried to extend from java.util.logging.FileHandler, and I faced some issues.First, there is no setFile API in FileHandler, and the way to set fileName is from constructor.
Second, although I passed the fileName to FileHandler constructor, I can see the logs were written into that log file. However, there was another file came with it called "server.log.lck" which was generated by FileHandler.openFiles(), and should be cleanup at close(). How can I invoke the close method when the server is shutting down?
Thanks,
Tzu-Chi
-
4. Re: JBoss7 Logging Rotating Feature
jamezp Apr 16, 2012 8:30 PM (in response to tcwang88)Yeah, it's definitely easier to extend JBoss Logging as it's FileHandler is much better IMO. I can understand not wanting the outside dependency, but FWIW it's got some nice built in i18n capabilities. To you use those there is an additional build-time only dependency. Weŕe working on getting some info on JBoss Logging up, but here is some information on the i18n stuff if you are interested https://community.jboss.org/wiki/JBossLoggingTooling.
Good catch on the shutdown not closing the handlers. There should probably be a shutdown handler that does that, but currently there is not. I went ahead and created a JIRA for that https://issues.jboss.org/browse/AS7-4528.
-
5. Re: JBoss7 Logging Rotating Feature
guinotphil Sep 12, 2012 6:36 AM (in response to jamezp)Hi,
I think there is another bug:
Here is my handler:
<periodic-rotating-file-handler name="FILE_ERROR">
<level name="INFO"/>
<formatter>
<pattern-formatter pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
</formatter>
<file relative-to="jboss.server.log.dir" path="server.log"/>
<suffix value=".yyyy-MM-dd-a"/>
<append value="true"/>
</periodic-rotating-file-handler>
And before startup, last modification time of server.log:
Wed Sep 12 10:27:46 CEST 2012
=> calculated next roll over time :
Wed Sep 12 22:00:00 CEST 2012
It should be Wed Sep 12 12:00:00 CEST 2012
Actually the line
calendar.clear(Calendar.HOUR);
does not affect the hour.
it should be
calendar.set(Calendar.HOUR, 0);
Thanks for reading
-
6. Re: JBoss7 Logging Rotating Feature
dmlloyd Sep 12, 2012 3:14 PM (in response to guinotphil)Would it be possible to try out this patch:
http://github.com/dmlloyd/jboss-logmanager/commit/46b4a26dd0e
It should fix this issue and maybe one or two more similar ones...
-
7. Re: JBoss7 Logging Rotating Feature
guinotphil Sep 13, 2012 4:31 AM (in response to dmlloyd)Thank you very much for the quick fix.
I'm gonna try it now.
-
8. Re: JBoss7 Logging Rotating Feature
rohanemmanuel Feb 19, 2013 11:45 AM (in response to dmlloyd)hi ,
i have the following logging.properties, if i dont use append then every minute the file is overwritten. but if i have append as true the file will be appended but the file never gets rotated in any of the case. im using the jboss logging in an standalone application. can you please point out whats missing or something wrong in the configuration.?
# Root logger level
logger.level=DEBUG
# Root logger handlers
logger.handlers=FILE
# Console handler configuration
#handler.CONSOLE=org.jboss.logmanager.handlers.ConsoleHandler
#handler.CONSOLE.properties=autoFlush
#handler.CONSOLE.level=DEBUG
#handler.CONSOLE.autoFlush=true
#handler.CONSOLE.formatter=PATTERN
handler.FILE=org.jboss.logmanager.handlers.PeriodicRotatingFileHandler
handler.FILE.level=DEBUG
handler.FILE.properties=autoFlush,append,fileName,suffix
handler.FILE.autoFlush=true
handler.FILE.append=true
handler.FILE.fileName=C:/jbosslogging.log
handler.FILE.suffix=.yyyy-MM-dd-HH-mm
handler.FILE.formatter=PATTERN
# Formatter pattern configuration
formatter.PATTERN=org.jboss.logmanager.formatters.PatternFormatter
formatter.PATTERN.properties=pattern
#formatter.PATTERN.pattern=%d{HH:mm:ss,SSS} %-5p [%c] %s%E%n
formatter.PATTERN.pattern=%d{HH:mm:ss,SSS} %C.%M:%L (%t) %5p %c{1}:%L - %m%n
Regards ,
Rohan Emmanuel
-
9. Re: JBoss7 Logging Rotating Feature
jamezp Feb 19, 2013 12:33 PM (in response to rohanemmanuel)I just tested and it seems to be rotating fine for me. What version of the log manager are you using? The newest is 1.4.0.Final.
--
James R. Perkins
-
10. Re: JBoss7 Logging Rotating Feature
rohanemmanuel Feb 19, 2013 12:40 PM (in response to jamezp)Hi James ,
thanks for the quick response,
im using 1.3.1 version of log manager.....i just checked , if i have one standalone app then the file is rotating fine....when i have more than one (tried with two as of now)standalone apps logging into the same file(they are using same logging.properties file) then the file is not rotating.please advice
--
Rohan Emmanuel
-
11. Re: JBoss7 Logging Rotating Feature
jamezp Feb 19, 2013 12:50 PM (in response to rohanemmanuel)I definitely wouldn't have two different applications writing to the same log files. There is no guarantee what will happen. You could lose log messages or experience what you're seeing. The handlers are thread-safe, but writing from two different JVM's could result in the unexplained behavior you're seeing.
--
James R. Perkins
-
12. Re: JBoss7 Logging Rotating Feature
rohanemmanuel Feb 20, 2013 12:35 PM (in response to jamezp)ya...thats explains it...thanks...
any suggestions on this, if i want two or more applications to log into same file...can it be done ?
---
Rohan Emmanuel
-
13. Re: JBoss7 Logging Rotating Feature
jamezp Feb 21, 2013 12:19 PM (in response to rohanemmanuel)Only way I can think of would be some kind of log server that would handle writing the log statements.
--
James R. Perkins