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