View Javadoc

1   /*
2    * $Id: MuleLogger.java 7976 2007-08-21 14:26:13Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.util;
12  
13  import java.util.Arrays;
14  import java.util.List;
15  
16  import org.apache.commons.logging.Log;
17  
18  /**
19   * A {@link Log} wrapper that supports boilerplate logging for high impact messages
20   */
21  // @Immutable
22  public class MuleLogger implements Log
23  {
24      private final Log logger;
25  
26      public MuleLogger(Log logger)
27      {
28          if (logger == null)
29          {
30              throw new IllegalArgumentException("logger may not be null");
31          }
32  
33          this.logger = logger;
34      }
35  
36      public boolean isDebugEnabled()
37      {
38          return logger.isDebugEnabled();
39      }
40  
41      public boolean isErrorEnabled()
42      {
43          return logger.isErrorEnabled();
44      }
45  
46      public boolean isFatalEnabled()
47      {
48          return logger.isFatalEnabled();
49      }
50  
51      public boolean isInfoEnabled()
52      {
53          return logger.isInfoEnabled();
54      }
55  
56      public boolean isTraceEnabled()
57      {
58          return logger.isTraceEnabled();
59      }
60  
61      public boolean isWarnEnabled()
62      {
63          return logger.isWarnEnabled();
64      }
65  
66      public void trace(Object o)
67      {
68          logger.trace(o);
69      }
70  
71      public void trace(Object o, Throwable throwable)
72      {
73          logger.trace(o, throwable);
74      }
75  
76      public void debug(Object o)
77      {
78          logger.debug(o);
79      }
80  
81      public void debug(Object o, Throwable throwable)
82      {
83          logger.debug(o, throwable);
84      }
85  
86      public void info(Object o)
87      {
88          logger.info(o);
89      }
90  
91      public void info(Object o, Throwable throwable)
92      {
93          logger.info(o, throwable);
94      }
95  
96      public void warn(Object o)
97      {
98          logger.warn(o);
99      }
100 
101     public void warn(Object o, Throwable throwable)
102     {
103         logger.warn(o, throwable);
104     }
105 
106     public void error(Object o)
107     {
108         logger.error(o);
109     }
110 
111     public void error(Object o, Throwable throwable)
112     {
113         logger.error(o, throwable);
114     }
115 
116     public void fatal(Object o)
117     {
118         logger.fatal(o);
119     }
120 
121     public void fatal(Object o, Throwable throwable)
122     {
123         logger.fatal(o, throwable);
124     }
125 
126     public void boilerPlate(String message)
127     {
128         boilerPlate(message, '*', StringMessageUtils.DEFAULT_MESSAGE_WIDTH);
129     }
130 
131     public void logBoilerPlate(List messages)
132     {
133         boilerPlate(messages, '*', StringMessageUtils.DEFAULT_MESSAGE_WIDTH);
134     }
135 
136     public void logBoilerPlate(String[] messages)
137     {
138         boilerPlate(Arrays.asList(messages), '*', StringMessageUtils.DEFAULT_MESSAGE_WIDTH);
139     }
140 
141     public void boilerPlate(String message, char c, int maxlength)
142     {
143         if (logger.isInfoEnabled())
144         {
145             logger.info("\n" + StringMessageUtils.getBoilerPlate(message, c, maxlength));
146         }
147     }
148 
149     public void boilerPlate(List messages, char c, int maxlength)
150     {
151         if (logger.isInfoEnabled())
152         {
153             logger.info("\n" + StringMessageUtils.getBoilerPlate(messages, c, maxlength));
154         }
155     }
156 
157     public void boilerPlate(String[] messages, char c, int maxlength)
158     {
159         boilerPlate(Arrays.asList(messages), c, maxlength);
160     }
161 
162 }