001    /**
002     *  Licensed to the Apache Software Foundation (ASF) under one or more
003     *  contributor license agreements.  See the NOTICE file distributed with
004     *  this work for additional information regarding copyright ownership.
005     *  The ASF licenses this file to You under the Apache License, Version 2.0
006     *  (the "License"); you may not use this file except in compliance with
007     *  the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    package org.apache.geronimo.samples.daytrader.util;
018    
019    import java.util.Collection;
020    import java.util.Iterator;
021    import org.apache.commons.logging.*;
022    import org.apache.geronimo.samples.daytrader.*;
023    
024    public class Log {
025            private final static org.apache.commons.logging.Log log = LogFactory.getLog(Log.class);
026    //A general purpose, high performance logging, tracing, statistic service
027    
028            public static void log(String message)
029            {
030            log.debug("DayTrader Log:" + new java.util.Date() + "------\n\t ");
031                    log.debug(message);
032            }
033            public static void log(String msg1, String msg2)
034            {
035                    log(msg1+msg2);
036            }
037            public static void log(String msg1, String msg2, String msg3)
038            {
039                    log(msg1+msg2+msg3);
040            }
041            
042            public static void error(String message)
043            {
044                    message = "Error: " + message;
045                    log.error(message);
046            }
047            public static void error(String message, Throwable e)
048            {
049                    error(message+"\n\t"+e.toString());
050                    e.printStackTrace(System.out);
051            }
052            public static void error(String msg1, String msg2, Throwable e)
053            {
054                    error(msg1+"\n"+msg2+"\n\t", e);
055            }
056            public static void error(String msg1, String msg2, String msg3, Throwable e)
057            {
058                    error(msg1+"\n"+msg2+"\n"+msg3+"\n\t", e);
059            }
060            public static void error(Throwable e, String message)
061            {
062                    error(message+"\n\t",e);
063                    e.printStackTrace(System.out);
064            }
065            public static void error(Throwable e, String msg1, String msg2)
066            {
067                    error(msg1+"\n"+msg2+"\n\t",e);
068            }
069            public static void error(Throwable e, String msg1, String msg2, String msg3)
070            {
071                    error(msg1+"\n"+msg2+"\n"+msg3+"\n\t", e);
072            }
073            
074            
075            public static void trace(String message)
076            {
077                    log.trace(message + " threadID="+ Thread.currentThread());
078            }
079    
080            public static void trace(String message, Object parm1)
081            {
082                    trace(message+"("+parm1+")");
083            }
084    
085            public static void trace(String message, Object parm1, Object parm2)
086            {
087                    trace(message+"("+parm1+", "+parm2+")");
088            }
089    
090            public static void trace(String message, Object parm1, Object parm2, Object parm3)
091            {
092                    trace(message+"("+parm1+", "+parm2+", "+parm3+")");
093            }
094            public static void trace(String message, Object parm1, Object parm2, Object parm3, Object parm4)
095            {
096                    trace(message+"("+parm1+", "+parm2+", "+parm3+")"+", "+parm4);
097            }
098            public static void trace(String message, Object parm1, Object parm2, Object parm3, Object parm4, Object parm5)
099            {
100                    trace(message+"("+parm1+", "+parm2+", "+parm3+")"+", "+parm4+", "+parm5);
101            }
102            public static void trace(String message, Object parm1, Object parm2, Object parm3, Object parm4, 
103                                                                    Object parm5, Object parm6)
104            {
105                    trace(message+"("+parm1+", "+parm2+", "+parm3+")"+", "+parm4+", "+parm5+", "+parm6);
106            }
107            public static void trace(String message, Object parm1, Object parm2, Object parm3, Object parm4, 
108                                                            Object parm5, Object parm6, Object parm7)
109            {
110                    trace(message+"("+parm1+", "+parm2+", "+parm3+")"+", "+parm4+", "+parm5+", "+parm6+", "+parm7);
111            }
112            public static void traceEnter(String message)
113            {
114                    log.trace("Method enter --" + message);
115            }
116            public static void traceExit(String message)
117            {
118                    log.trace("Method exit  --" + message);
119            }
120            
121            
122            public static void stat(String message)
123            {
124                    log(message);
125            }
126    
127            public static void debug(String message)
128            {
129                    log.debug(message);
130            }
131    
132            public static void print(String message)
133            {
134                    log(message);
135            }
136            
137            public static void printObject(Object o)
138            {
139                    log("\t"+o.toString());
140            }
141                    
142            public static void printCollection(Collection c)
143            {
144                    log("\t---Log.printCollection -- collection size=" + c.size());
145                    Iterator it = c.iterator();
146                    while ( it.hasNext() )
147                    {
148                            log("\t\t"+it.next().toString());
149                    }
150                    log("\t---Log.printCollection -- complete");            
151            }
152            
153            public static void printCollection(String message, Collection c)
154            {
155                    log(message);
156                    printCollection(c);
157            }
158            
159            public static boolean doActionTrace()
160            {
161                    return getTrace() || getActionTrace();
162            }
163    
164            public static boolean doTrace()
165            {
166                    return getTrace();
167            }
168            
169            public static boolean doDebug()
170            {
171                    return true;
172            }
173            
174            public static boolean doStat()
175            {
176                    return true;
177            }               
178            
179            /**
180             * Gets the trace
181             * @return Returns a boolean
182             */
183            public static boolean getTrace() {
184                    return TradeConfig.getTrace();
185            }
186            /**
187             * Gets the trace value for Trade actions only
188             * @return Returns a boolean
189             */
190            public static boolean getActionTrace() {
191                    return TradeConfig.getActionTrace();
192            }
193                    
194            /**
195             * Sets the trace
196             * @param trace The trace to set
197             */
198            public static void setTrace(boolean traceValue)
199            {
200                    TradeConfig.setTrace(traceValue);
201            }
202            /**
203             * Sets the trace value for Trade actions only
204             * @param trace The trace to set
205             */
206            public static void setActionTrace(boolean traceValue)
207            {
208                    TradeConfig.setActionTrace(traceValue);
209            }
210    }
211