Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Java in General and the fly likes how to append and limit the size of log file using java.util.logging Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "how to append and limit the size of log file using java.util.logging" Watch "how to append and limit the size of log file using java.util.logging" New topic
Author

how to append and limit the size of log file using java.util.logging

s ravi chandran
Ranch Hand

Joined: Dec 20, 2010
Posts: 126
hi
i have an issue with the logging file, I am using FileHandler for putting all the logs in to a file. I want to add timestamp to the log file name.. now, i have seen the FileHandler constructor which seems useful to me,



but in this, I am unable to create the pattern, if i add something randomly, the logger doesnt work, i.e. nothing is written to the logging file..
any ideas?
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1409

This may seem like the path of least resistance, but unless you have a really good reason to opt for JDK logging and implementing all this yourself, I'd suggest you go with something like Log4J instead.
It already has FileAppenders that work perfectly and it also supports lots of different and configurable output formats.
If you don't want to tie your code directly to the Log4J API you could use a wrapper solution like SLF4J or Apache Commons Logging.


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
s ravi chandran
Ranch Hand

Joined: Dec 20, 2010
Posts: 126
Jelle Klap wrote:This may seem like the path of least resistance, but unless you have a really good reason to opt for JDK logging and implementing all this yourself, I'd suggest you go with something like Log4J instead.
It already has FileAppenders that work perfectly and it also supports lots of different and configurable output formats.
If you don't want to tie your code directly to the Log4J API you could use a wrapper solution like SLF4J or Apache Commons Logging.


Thanks for replying. I am indeed using JDK logging to make the application independent of any library requirements. we are working in a secure environment, where we don't have internet and bringing a library jar or any other software is very difficult. So, I am aiming to do the logging task with the JDK logger itself, in case there are few things which might be required and is not available in built-in logging then only I would opt for third party jar library.

I have worked with log4j in the past though. its just that I wanted to see if JDK built-in logging can do the work for me or not.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: how to append and limit the size of log file using java.util.logging
 
Similar Threads
Q abt INFO Level in java.util.logging
Problem with java.util.logging - writing to multiple log files
How to make each log entry start on a new line?
Writing logs to a single file from Multiple Classes
Java util Logging : FileHandler