This week's book giveaway is in the General Computing forum.
We're giving away four copies of Emmy in the Key of Code and have Aimee Lucido on-line!
See this thread for details.
Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Cannot stop log from going to console

 
Ranch Hand
Posts: 58
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Eclipse on a MacBook Pro running OS X Yosemite and Java.  I have 2 logging problems:
1) The log file is going both to the console and to a log file.  I only want it to go to the file, not also to the console.  It is going to both.
2) I would like the log file to go in the folder username/workspace and not username/workspace/project name.
I can live with the second, but really want to have number 1 above, only to the file, not also to the console.
Note 1:  i have tried to remove the handler for the console, but it doesn't work.
Note 2:  I am satisfied with the format of the logging.

The following is where the log is created (supposedly) - in the init.

The following should make the log object:

NOTE: the above println (in logger) does NOT occur in the run.
ANOTHER NOTE:  i believe I need to put the filename I want () in but do not know how to do it.

Last message is from endItAll:

OUTPUT IS THE FOLLOWING TO the log file logFileA in the folder of the project name, not the one I wanted which is  username/Documents:
Feb 01, 2017 2:41:52 PM PaniniIndexing.views.FirstWbGuiPaniniIndexing main
INFO: message 1
Feb 01, 2017 2:41:52 PM PaniniIndexing.views.FirstWbGuiPaniniIndexing main
SEVERE: message 2
Feb 01, 2017 2:42:05 PM PaniniIndexing.views.Finale endItAll
INFO: message at Finale

OUTPUT TO CONSOLE:
logFileA is /Users/davidellisrogers/Documents/workspace/logFile.txt
point 1
point 2
point 3
Feb 01, 2017 2:41:52 PM PaniniIndexing.views.FirstWbGuiPaniniIndexing main
INFO: message 1
point 4
Feb 01, 2017 2:41:52 PM PaniniIndexing.views.FirstWbGuiPaniniIndexing main
SEVERE: message 2
point 5


OUTPUT TO CONSOLE, At end of program
Feb 01, 2017 2:42:05 PM PaniniIndexing.views.Finale endItAll
INFO: message at Finale
Am finishing at Finale

Thanks for any and all help.
 
Ranch Hand
Posts: 146
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you make a small, complete program that compiles, executes and shows the problem?
 
Bartender
Posts: 9586
13
Mac OS X Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume you are using the java.util.logging classes?  

ANOTHER NOTE:  i believe I need to put the filename I want () in



True.  Pass in the file name (or path and file name), not the name of a File object, which is what you are currently doing.

To remove the console handler, one needs to do the following (taken from this post):

 
David Ellis Rogers
Ranch Hand
Posts: 58
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a small program.  It is in 2 files (had to be).


The second part:


The output on console:
logFileA is /Users/davidellisrogers/Documents/workspace/logFile.txt
point 1
point 2
Feb 02, 2017 8:49:43 AM main main
INFO: message 1
point 4
Feb 02, 2017 8:49:43 AM main main
SEVERE: message 2

The output in file documents/workspace/ShowingLoggingProblem/logFileA:
Feb 02, 2017 8:49:43 AM main main
INFO: message 1
Feb 02, 2017 8:49:43 AM main main
SEVERE: message 2

I do not want the output to go to the console.  This is my main concern.
Secondarily, I want the output log file to go to the directory documents/workspace.
 
David Ellis Rogers
Ranch Hand
Posts: 58
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I am using the java.util.logging classes:


Following change does not stop output to console:
 
David Ellis Rogers
Ranch Hand
Posts: 58
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Solved.
The following 2 files are required.  The first must be in its own file.
As desired, 1) the logging output does not go to the console and
2) it goes to the desired directory, not to the one that is the project directory.

The calls are from this class:

 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for posting the solution.
 
Joe Ess
Bartender
Posts: 9586
13
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

David Ellis Rogers wrote:Solved.
The following 2 files are required.  The first must be in its own file.



I don't think that's a requirement of the java.util.logging library.  It probably has something to do with your loggers being declared as "static final".  The following code works fine for me:



The output to the console:


The output to the file:

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!