• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Logging

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey all,

I provide a Logger for each package.
So at the moment various GUI, Controller and Data messages appear on the console during running.

Now I'm thinking about logging to a file.
My first foray into this yielded the code below.

private static FileHandler fh = new FileHandler("mylog.txt");
fh.setFormatter(new SimpleFormatter());
log.addHandler(fh);
log.setLevel(Level.ALL);

A typical record in the log.txt file is as follows:

[EXTRACT]
06-Dec-2005 09:11:29 suncertify.db.Data isValidRecord
INFO: Record is valid
06-Dec-2005 09:11:29 suncertify.db.Data find
INFO: find() was completed successfully
[EXTRACT]


So far so good.
My questions are as follows:

1. Do I actually need to log to a file ?

2. One file for all packages or one for each package ?

3. Should I allow configuration - as in only see db log messages that are at least severe etc ?

4. Is it sufficient to use a SimpleFormatter ?


I want to avoid overkill but at the same time I don't want to miss anything.

Thanks.
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

My questions are as follows:

1. Do I actually need to log to a file ?

2. One file for all packages or one for each package ?

3. Should I allow configuration - as in only see db log messages that are at least severe etc ?



1) Without a log file how will you get the exception thrown by application. Okay u might say, it will come in the console. Consider an Application accessed by 100 users at the same time. Now when an exception occurs, u might not know what trace corresponding to what error. Its better to keep a Log file but limiting to some 200K or 300K is good.

2) U can keep one or two file at the most for the entire application.
3) Yes u should allow Configuration. IO is a very costly process. In a real time application u might not keep a log level of all. U might not want to keep "PANIC" mode or "SEVERE" mode, which otherwise, will put your application users to sleep.
 
Alan Morgan
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sri Ram:


1) Without a log file how will you get the exception thrown by application. Okay u might say, it will come in the console. Consider an Application accessed by 100 users at the same time. Now when an exception occurs, u might not know what trace corresponding to what error. Its better to keep a Log file but limiting to some 200K or 300K is good.

2) U can keep one or two file at the most for the entire application.
3) Yes u should allow Configuration. IO is a very costly process. In a real time application u might not keep a log level of all. U might not want to keep "PANIC" mode or "SEVERE" mode, which otherwise, will put your application users to sleep.




1) Good point
How do I limit it to a given size ?

2)If I keep one per package it will be four (gui, controller, db, remote)

3) So how do I go about allowing configuration ?
Put a menu on the UI ? Doesn't sound like it fits really.
Add it to the connection screen at the start where I allow setting of database and ip address ?

Thanks
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm more of a log4j guy, so perhaps someone can answer this for me.

Are you configuring the Java logging API programmatically? Or is there a viable file-based alternative for the assignment?

From what I've read, the other alternative is to store logging.properties in JAVA_HOME. Since most exam versions I'm aware of don't allow/require graders to plunk files out on the file system, that's a no-go (presumably also why we can't do security manager stuff).

Thanks in advance for your help.
[ December 06, 2005: Message edited by: Steve Baranski ]
 
Sri Ram
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Alan Morgan:



1) Good point
How do I limit it to a given size ?

2)If I keep one per package it will be four (gui, controller, db, remote)

3) So how do I go about allowing configuration ?
Put a menu on the UI ? Doesn't sound like it fits really.
Add it to the connection screen at the start where I allow setting of database and ip address ?

Thanks



For a small project use a text file for giving config info. Or u can give a seperate UI apart from the Application for congif only. Keep two text box for Log Level and one for Log file size. Write this to a text file.
when ur application is loggin, read from the property file.

Now The size, when u do logging, check the size of the file, If its greater clear the log.

Four logs become cumbersome when on a real time application, since the SYstem Admin in many client places might not want to see many logs for getting a since exception.
 
Alan Morgan
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sri Ram:


For a small project use a text file for giving config info. Or u can give a seperate UI apart from the Application for congif only. Keep two text box for Log Level and one for Log file size. Write this to a text file.
when ur application is loggin, read from the property file.



Ok but how do you open this seperate UI ?
1. Have it run as a seperate application altogether or
2. Launch it from within the main application itself or
3. Launch from the connection window

Problem with 1 is that the instructions are explicit on how we should start the app etc and I;m not sure how the assesors would look on needing to start another one.

2 doesn't make sense as if running in server mode then the main appplciation never comes up.

3 would work I guess but will every user care about logging levels etc ?

Any thouhgts ?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic