KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > log > LogUtil


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.services.log;
6
7 import org.apache.commons.logging.Log;
8 import org.exoplatform.container.RootContainer;
9
10 /**
11  * Jun 28, 2004
12  * @author: Tuan Nguyen
13  * @email: tuan08@users.sourceforge.net
14  * @version: $Id: LogUtil.java,v 1.4 2004/07/24 16:20:09 tuan08 Exp $
15  */

16 public class LogUtil {
17     static private Log defaultInstance_ = null ;
18     
19     public static Log getLog(String JavaDoc category) {
20         RootContainer manager = RootContainer.getInstance();
21         LogService service = (LogService) manager.getComponentInstanceOfType(LogService.class) ;
22         Log log = service.getLog(category) ;
23         return log ;
24     }
25     
26   public static Log getLog(Class JavaDoc clazz) {
27     RootContainer manager = RootContainer.getInstance();
28     LogService service = (LogService) manager.getComponentInstanceOfType(LogService.class) ;
29     Log log = service.getLog(clazz) ;
30     return log ;
31   }
32   
33     public static void setLevel(String JavaDoc category, int level, boolean recursive) throws Exception JavaDoc {
34         RootContainer manager = RootContainer.getInstance();
35         LogService service = (LogService) manager.getComponentInstanceOfType(LogService.class) ;
36         service.setLogLevel(category, level, recursive) ;
37     }
38     
39     static public void debug(String JavaDoc msg) { getDefault().debug(msg) ; }
40     static public void debug(String JavaDoc msg, Throwable JavaDoc t) { getDefault().debug(msg, t) ; }
41     
42     static public void info(String JavaDoc msg) { getDefault().info(msg) ; }
43     static public void info(String JavaDoc msg, Throwable JavaDoc t) { getDefault().info(msg, t) ; }
44     
45     static public void warn(String JavaDoc msg) { getDefault().warn(msg) ; }
46     static public void warn(String JavaDoc msg, Throwable JavaDoc t) { getDefault().warn(msg, t) ; }
47     
48     static public void error(String JavaDoc msg) { getDefault().error(msg) ; }
49     static public void error(String JavaDoc msg, Throwable JavaDoc t) { getDefault().error(msg, t) ; }
50     
51     final static public Log getDefault() {
52         if(defaultInstance_ == null) {
53             defaultInstance_ = getLog("default") ;
54         }
55         return defaultInstance_ ;
56     }
57 }
Popular Tags