By
using the name given to your logger, you can make a hierarchy.
For
Example:
import java.util.logging.*; public class LogHierarchy { public static void main(String args[]){ Logger lev1 = Logger.getLogger("Level1"); Logger lev2 = Logger.getLogger("Level1.Level2"); Logger lev3 = Logger.getLogger("Level1.Level2.Level3"); System.out.println(lev3.getParent().getName()); System.out.println(lev3.getParent().getParent().getName()); System.out.println(lev3.getParent().getParent().getParent().getName()); } }
Output
Level1.Level2 Level1
Logger.getLogger("Level1.Level2.Level3")
Each
'.' in the name marks a level in the hierarchy.
getParent()
return the parent for this Logger. Parent loggers should be created in
the hierarchy, other wise getParent return empty string.
Example
import java.util.logging.*; public class LogHierarchy { public static void main(String args[]){ Logger lev3 = Logger.getLogger("Level1.Level2.Level3"); System.out.println(lev3.getParent().getName()); } }
In
the above program, loggers with name 'Level1' and 'Level1.Level2' are
not created. So getParent() returns empty string.
No comments:
Post a Comment