• 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
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Logging ...

 
Ranch Hand
Posts: 664
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"It is important to note that the Logger returned by one of the getLogger factory methods may be garbage collected at any time if a strong reference to the Logger is not kept."

Sourced from here.


1. Can you confirm that the following code holds a strong reference to the Logger, and, point out any issues where the Garbage Collector Is it possible to tweak the code and use a WeakReference, or would it be an example of overdoing it?
might trip up?
2. I would also like to know whether I can control the size of the file before another file gets created within the rotation sequence of logs.
Within my environment (WinXP/JDK 1.6) the log files are written to c:\documents and settings\%windows user name%
3. How does the code snippet below automatically read the file name (line 121)? How does the parameter reading
mechanism work for say {0}, {1}, {2} etc.?
4. How can I create some code that controls when the logging is switched off and on in a similar fashion of C++ macros.
5. Why does the programmer pass the 2nd parameter (line 87) as "<init>", since this is not written to the log file?
6. Is it possible to update the code, using Reflection classes as parameters to Logger.logp() - see Related link (2) for basic syntax example?
...
logger.logp(Level.INFO, this.getClass().forName(), "ImageViewerFrame()", "test logger"); //this is dummy non-working code
...



Sourced from Core Java Vol.I (8th Ed) P. 584-588 Listing 11.2


Related links
1. E. Nicholas, Understanding weak references
2. Logger logp() example

Log file at C:\Documents and Settings\Jon\LoggingImageViewer.log.0
<?xml version="1.0" encoding="windows-1252" standalone="no"?>
<!DOCTYPE log SYSTEM "logger.dtd">
<log>
<record>
<date>2011-06-05T12:23:56</date>
<millis>1307269436593</millis>
<sequence>0</sequence>
<logger>com.horstmann.corejava</logger>
<level>FINER</level>
<class>ImageViewerFrame</class>
<method><init></method>
<thread>10</thread>
<message>ENTRY</message>
</record>
<record>
<date>2011-06-05T12:23:56</date>
<millis>1307269436625</millis>
<sequence>1</sequence>
<logger>com.horstmann.corejava</logger>
<level>FINER</level>
<class>ImageViewerFrame</class>
<method><init></method>
<thread>10</thread>
<message>RETURN</message>
</record>
<record>
<date>2011-06-05T12:23:56</date>
<millis>1307269436625</millis>
<sequence>2</sequence>
<logger>com.horstmann.corejava</logger>
<level>FINE</level>
<class>LoggingImageViewer$1</class>
<method>run</method>
<thread>10</thread>
<message>Showing frame</message>
</record>
<record>
<date>2011-06-05T12:31:19</date>
<millis>1307269879671</millis>
<sequence>3</sequence>
<logger>com.horstmann.corejava</logger>
<level>FINER</level>
<class>ImageViewerFrame.FileOpenListener</class>
<method>actionPerformed</method>
<thread>10</thread>
<message>ENTRY java.awt.event.ActionEvent[ACTION_PERFORMED,cmd=Open,when=1307269879671,modifiers=Button1] on javax.swing.JMenuItem[,1,3,51x21,invalid,alignmentX=0.0,alignmentY=0.0,border=javax.swing.plaf.metal.MetalBorders$MenuItemBorder@131f71a,flags=264,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,disabledSelectedIcon=,margin=javax.swing.plaf.InsetsUIResource[top=2,left=2,bottom=2,right=2],paintBorder=true,paintFocus=false,pressedIcon=,rolloverEnabled=false,rolloverIcon=,rolloverSelectedIcon=,selectedIcon=,text=Open]</message>
</record>
<record>
<date>2011-06-05T12:31:40</date>
<millis>1307269900437</millis>
<sequence>4</sequence>
<logger>com.horstmann.corejava</logger>
<level>FINE</level>
<class>ImageViewerFrame$FileOpenListener</class>
<method>actionPerformed</method>
<thread>10</thread>
<message>Reading file C:\Documents and Settings\Jon\My Documents\My Archives\My Pictures\chat\rita26-3.jpg</message>
</record>
<record>
<date>2011-06-05T12:31:40</date>
<millis>1307269900515</millis>
<sequence>5</sequence>
<logger>com.horstmann.corejava</logger>
<level>FINER</level>
<class>ImageViewerFrame.FileOpenListener</class>
<method>actionPerformed</method>
<thread>10</thread>
<message>RETURN</message>
</record>
<record>
<date>2011-06-05T12:31:43</date>
<millis>1307269903390</millis>
<sequence>6</sequence>
<logger>com.horstmann.corejava</logger>
<level>FINER</level>
<class>ImageViewerFrame.FileOpenListener</class>
<method>actionPerformed</method>
<thread>10</thread>
<message>ENTRY java.awt.event.ActionEvent[ACTION_PERFORMED,cmd=Open,when=1307269903390,modifiers=Button1] on javax.swing.JMenuItem[,1,3,51x21,invalid,alignmentX=0.0,alignmentY=0.0,border=javax.swing.plaf.metal.MetalBorders$MenuItemBorder@131f71a,flags=264,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,disabledSelectedIcon=,margin=javax.swing.plaf.InsetsUIResource[top=2,left=2,bottom=2,right=2],paintBorder=true,paintFocus=false,pressedIcon=,rolloverEnabled=false,rolloverIcon=,rolloverSelectedIcon=,selectedIcon=,text=Open]</message>
</record>
<record>
<date>2011-06-05T12:32:04</date>
<millis>1307269924000</millis>
<sequence>7</sequence>
<logger>com.horstmann.corejava</logger>
<level>FINE</level>
<class>ImageViewerFrame$FileOpenListener</class>
<method>actionPerformed</method>
<thread>10</thread>
<message>Reading file C:\Documents and Settings\Jon\My Documents\My Archives\New car (july 2010)\uktomalta.com - Mazda 3 1.6D TS Hatchback (2008) - 21.07.2010.pdf</message>
</record>
<record>
<date>2011-06-05T12:32:04</date>
<millis>1307269924109</millis>
<sequence>8</sequence>
<logger>com.horstmann.corejava</logger>
<level>FINER</level>
<class>ImageViewerFrame.FileOpenListener</class>
<method>actionPerformed</method>
<thread>10</thread>
<message>RETURN</message>
</record>
<record>
<date>2011-06-05T12:32:07</date>
<millis>1307269927187</millis>
<sequence>9</sequence>
<logger>com.horstmann.corejava</logger>
<level>FINE</level>
<class>ImageViewerFrame$1</class>
<method>actionPerformed</method>
<thread>10</thread>
<message>Exiting.</message>
</record>
</log>








 
The overall mission is to change the world. When you've done that, then you can read this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!