Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

java logging - method logged

Posted on 2007-08-08
22
Medium Priority
?
617 Views
Last Modified: 2013-11-05
The logger is noting the entrance into methods like so:

Aug 8, 2007 8:30:47 AM myPkg.MyClass myMethod.

How do I turn this off?

// Create a file handler that writes log record to a file
FileHandler handler = new FileHandler( "mylog.log" );
handler.setFormatter( new SimpleFormatter() ); // set file format to plain text,                                                             // not xml
logger = Logger.getLogger( "mypkg.MyClass" );
logger.addHandler( handler );
logger.setLevel( Level.WARNING );
0
Comment
Question by:allelopath
  • 10
  • 5
  • 4
  • +2
22 Comments
 
LVL 4

Expert Comment

by:NHBFighter
ID: 19654485
Can you set the level to off, so change
logger.setLevel( Level.WARNING );
to
logger.setLevel( Level.OFF);
0
 
LVL 1

Author Comment

by:allelopath
ID: 19654500
I could but then I wouldn't get any messages, i think.
I have some logger.warning() messages that I need.
0
 
LVL 12

Expert Comment

by:marklorenz
ID: 19654517
you should set the logging level to SEVERE:

logger.setLevel( Level.SEVERE)

I assume you want to know when a real problem occurs.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 23

Accepted Solution

by:
Ajay-Singh earned 1200 total points
ID: 19654558
0
 
LVL 1

Author Comment

by:allelopath
ID: 19654677
>>you should set the logging level to SEVERE:
this does not affect the noting of entrance to a method
0
 
LVL 4

Expert Comment

by:NHBFighter
ID: 19654727
So what exactly do you want to turn off?  It seems like you want it to still log warning messages, [logger.warning()], what don't you want it to log, the entrance into methods? If so can you show us the code that logs the entrance, is it logger.debug() or something?

Dave
0
 
LVL 1

Author Comment

by:allelopath
ID: 19654813
>>you want it to still log warning messages, [logger.warning()], what don't you want it to log, the entrance >>into methods

yes

>>can you show us the code that logs the entrance, is it logger.debug() or something

My code is not doing it (explicitly).
0
 
LVL 4

Expert Comment

by:NHBFighter
ID: 19654966
Ok so how are the entrance to methods being logged?
0
 
LVL 1

Author Comment

by:allelopath
ID: 19654991
I don't know. That's the question.
0
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 19655098
> Ok so how are the entrance to methods being logged?
 
They are logged as headers of the standard log formatter.
0
 
LVL 4

Assisted Solution

by:NHBFighter
NHBFighter earned 400 total points
ID: 19655645
Mabey I'm not understanding, are you saying that each time a method is being called a logging statement is written to your log file?  Is that what you mean by 'The logger is noting the entrance into methods'?

If so one way logging the entrance into methods is done is that the first line of each method has something like:
    logger.debug("some code to use to log that the method was called");
But if you don't see code like this at the beginning of the methods its possible that who ever designed the system used AOP to weave this logging into the code. There are several different AOP solutions that could have been employed to do this.

Dave
0
 
LVL 1

Author Comment

by:allelopath
ID: 19655814
There is not anything at the beggining of the methods.
I have written all the code, no AOP is being used.

Ajay-Singh:
Can you tell me more info. I guess i need to have my own logging.properties file.
Can you tell what value(s) to use to remove the headers yet still have my warnings?
0
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 19655972
By default, java logging would add that in the first line. If you don't want that you need to write your own Formatter and set it the Handler.

Formatter javadoc: http://java.sun.com/j2se/1.5.0/docs/api/java/util/logging/Formatter.html
By default SimpleFormatter is used.
0
 
LVL 1

Author Comment

by:allelopath
ID: 19658459
I do not consider this a solution. My original post asked "How do I turn this off?" not "Where do I find documention about this?"
0
 
LVL 4

Assisted Solution

by:doraemon-nolife
doraemon-nolife earned 400 total points
ID: 19659234
if your myMethod is a public method, it would be shown in logging info.

if your myMethod is only called from other public method, change it to private. Then the logging info of this method name should be gone.

Log4j retrieve the method name through java reflection, it cant access a private method.

:)
0
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 19659398
> My original post asked "How do I turn this off?" not "Where do I find documention about this?"

My answer addresses that.
0
 
LVL 1

Author Comment

by:allelopath
ID: 19663455
>>Log4j retrieve the method name through java reflection, it cant access a private method.
I am using java.util.logging, not  Log4j
0
 
LVL 1

Author Comment

by:allelopath
ID: 19663461
>>My answer addresses that.
No it doesn't
0
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 19663546
> No it doesn't
Did you even look at the javadoc for Fomatter and tried writing your formatter?
0
 
LVL 4

Expert Comment

by:doraemon-nolife
ID: 19667224
Try using log4j, it provide a simpler way
http://www.jajakarta.org/log4j/jakarta-log4j-1.1.3/docs/download.html

Have you try my suggestion? I think primitive logger and log4j are both using reflection.

:)
0
 
LVL 1

Author Comment

by:allelopath
ID: 20022742
0
 
LVL 1

Author Comment

by:allelopath
ID: 20022748
doreamon-nolife:
I cannot use log4j, as much as I would like to.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses
Course of the Month21 days, 2 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question