burtonator wrote:
> I think the properties should be more like:
> 
> turbine.logs=default
> turbine.logs=error
> turbine.logs=jetspeed
> 
> turbine.log.default=/tmp/turbine.log
> turbine.log.error=/tmp/turbine-error.log
> turbine.log.jetspeed=/tmp/jetspeed.log
> 
> The Log.java looked OK.  Can you please just post a diff though?  This
> makes it a lot easier for us.
> 

I made the changes to the Log class so that now the properties file
should look like this:

<snip>

logfile=/turbine/logs/turbine.log

turbine.logs=database
turbine.logs=security
 
turbine.log.database=/turbine/logs/turbine-db.log
turbine.log.security=/turbine/logs/turbine-sec.log   

</snip>

Using the above example of the TurbineResurces.properties file you can
then write to a log file like this:

// creates an entry in /turbine/logs/turbine-sec.log 
Log.warn("security","user x has logged into the system");

// creates an entry in /turbine/logs/turbine-db.log
Log.note("database","table z has been updated with the following
info:");

// creates an entry in /turbine/logs/turbine.log
Log.note("application initiated");

If these changes are approved/applied then I will create patches for the
documentation and the default TurbineResources.properties file. Here is
the diff as requested :-)

******************        BEGIN PATCH          ****************
Index: src/java/org/apache/turbine/util/Log.java
===================================================================
RCS file:
/products/cvs/turbine/turbine/src/java/org/apache/turbine/util/Log.java,v
retrieving revision 1.8
diff -r1.8 Log.java
59c59
< // Java Core Classes 
---
> // Java Core Classes
60a61
> import java.util.Vector;
66,68c67,69
<  * This is a utility class that is used for logging events.  Entries
are 
<  * allowed in 3 levels - Notice, Warning, Error.  
<  * Methods are also available to log exceptions, which are always
logged 
---
>  * This is a utility class that is used for logging events.  Entries are
>  * allowed in 3 levels - Notice, Warning, Error.
>  * Methods are also available to log exceptions, which are always logged
71,73c72,74
<  * The path to a writable file must be given in
TurbineResources.properties 
<  * for the log to be written. If the file does not already exist, then
the 
<  * file will be created. If the path is invalid, then the file will
not be 
---
>  * The path to a writable file must be given in TurbineResources.properties
>  * for the log to be written. If the file does not already exist, then the
>  * file will be created. If the path is invalid, then the file will not be
86,87c87,88
< public class Log 
< {     
---
> public class Log
> {
89c90
<     
---
> 
92c93
<       // filename for log file        
---
>       // filename for log file
94c95,96
<         
---
>     // array to hold multiple FileWriter objects
>     private static Object logfiles[][];
104c106
<     
---
> 
106,107c108,110
<        * points Log file at the given path/filename.
<        */                                     
---
>        * checks to see if log variables are set up properly and
>      * the initializes the log(s)
>        */
113c116,118
<             if (logFileString == null)
---
>             Vector turbineLogs = TurbineResources.getVector("turbine.logs");
> 
>             if (logFileString == null && turbineLogs.isEmpty())
116,122c121,157
<             "The logfile= property in the TurbineResources.properties
file is null or could not be found.\n" +
<             "Please make sure that you have properly defined the path
to the TurbineResources.properties file\n" + 
<             "and you have called
\"TurbineResourceService.setPropertiesFileName(\"/path/to/TurbineResources.properties\");\"
in your code.\n" + 
<             "If you are using this class with the Turbine Servlet,
this should have been called for you already.\n" +
<             "If you are getting this error using the Turbine Servlet,
the path to the properties file or\n" + 
<             "the path to the logfile was not defined correctly. Please
refer to the INSTALL \n" +
<             "document for instructions on how to do this.\n");
---
>                 "The logfile= property and the turbine.logs= property in the 
>TurbineResources.properties file are null \n" +
>                 "or could not be found.  At least one of these properties must be 
>defined in the TurbineResources.properties file. \n" +
>                 "Please make sure that you have properly defined the path to the 
>TurbineResources.properties file\n" +
>                 "and you have called 
>\"TurbineResourceService.setPropertiesFileName(\"/path/to/TurbineResources.properties\");\"
> in your code.\n" +
>                 "If you are using this class with the Turbine Servlet, this should 
>have been called for you already.\n" +
>                 "If you are getting this error using the Turbine Servlet, the path 
>to the properties file or\n" +
>                 "the path to the logfile or the logcount was not defined correctly. 
>Please refer to the INSTALL \n" +
>                 "document for instructions on how to do this.\n");
>             }
> 
>             if (logFileString != null)
>             {
>                 logfile = new FileWriter( logFileString, true );
>             }
> 
>             // if there are turbine.logs defined then set up an array of FileWriters
>             // for use in the method Log.note(logname,text) etc
>             if (!turbineLogs.isEmpty())
>             {
>                 logfiles= new Object[turbineLogs.size()][2];
>                 for (int i=0;i<turbineLogs.size();i++)
>                 {
>                     if (TurbineResources.getString("turbine.log." + 
>(String)turbineLogs.elementAt(i),null) == null)
>                     {
>                         throw new Exception(
>                         "There is an error in the TurbineResources.properties file. 
>\n" +
>                         "The turbine.log." + (String)turbineLogs.get(i) + "= entry 
>could not be found for the \n" +
>                         "corresponding turbine.logs=" + (String)turbineLogs.get(i) + 
>" entry. \n" +
>                         "Be sure that each turbine.logs= entry has a corresponding 
>turbine.log.[logname]= \n" +
>                         "in the TurbineResources.properties file. \n" +
>                         "Please refer to the comments in the 
>TurbineResources.properties file \n" +
>                         "or the user documentation for more information on how to 
>properly \n" +
>                         "implement logging in a Turbine application. \n");
>                     }
>                     logfiles[i][0]= (String)turbineLogs.get(i);
>                     logfiles[i][1]= (FileWriter) new 
>FileWriter(TurbineResources.getString("turbine.log." + 
>(String)turbineLogs.get(i),null),true);
>                 }
124d158
<             logfile = new FileWriter( logFileString, true );
136c170
<     
---
> 
141,143c175,177
<      */                       
<       public static boolean note(String description) 
<       {       
---
>      */
>       public static boolean note(String description)
>       {
146a181,190
>      * Specifies the log to print to and
>      * makes a log entry at the NOTICE level
>      *
>      * @returns true if entry was entered, false otherwise
>      */
>       public static boolean note(String logname, String description)
>       {
>               return log(NOTICE, logname, description, null);
>       }
>     /*
150,152c194,196
<      */    
<       public static boolean warn(String description) 
<       {       
---
>      */
>       public static boolean warn(String description)
>       {
155a200,209
>      * Specifies the log to print to and
>      * makes a log entry at the WARNING level
>      *
>      * @returns true if entry was entered, false otherwise
>      */
>       public static boolean warn(String logname, String description)
>       {
>               return log(WARNING, logname, description, null);
>       }
>     /*
159,161c213,216
<      */    
<       public static boolean error(String description) 
<       {       
---
>      */
>       public static boolean error(String description)
>       {
>    System.out.print("Error=" + description + "\n");
163c218,229
<       }                                       
---
> 
>       }
>     /*
>      * Specifies the log to print to and
>      * makes a log entry at the ERROR level
>      *
>      * @returns true if entry was entered, false otherwise
>      */
>       public static boolean error(String logname, String description)
>       {
>               return log(ERROR, logname, description, null);
>       }
168,169c234,235
<      */    
<       public static boolean error(String description, Throwable t)  
---
>      */
>       public static boolean error(String description, Throwable t)
172c238,248
<       }       
---
>       }
>     /*
>      * Specifies the log to print to and
>      * makes a log entry at the ERROR level
>      *
>      * @returns true if entry was entered, false otherwise
>      */
>       public static boolean error(String logname, String description, Throwable t)
>       {
>               return log(ERROR, logname, description, t);
>       }
177,178c253,254
<      */    
<       public static boolean error(Throwable t) 
---
>      */
>       public static boolean error(Throwable t)
181c257,258
<       } 
---
>       }
> 
185a263
> 
189c267
<         {    
---
>         {
193c271
<             logEntry.append ( date.toString() ); 
---
>             logEntry.append ( date.toString() );
225c303
<             return true;      
---
>             return true;
227c305
<               return false;   
---
>               return false;
229c307,365
<     
---
> 
>      /**
>      * Creates a log entry in the log passed in as logname
>      */
>       private static boolean log(String level, String logname, String description, 
>Throwable t)
>       {
>         boolean foundLog = false;
>         int i = 0;
>         int activeLogNumber = 0;
>         for (i=0;i<logfiles.length;i++)
>         {
>             if (logfiles[i][0].equals(logname))
>             {
>                 activeLogNumber = i;
>                 foundLog=true;
>                 break;
>             }
>         }
>         if (foundLog)
>         {
>             Date date = new Date();
>             StringBuffer logEntry = new StringBuffer();
>             logEntry.append ( "[" );
>             logEntry.append ( date.toString() );
>             logEntry.append ( "] -- " );
>             logEntry.append ( level );
>             logEntry.append ( " -- " );
>             logEntry.append ( description );
>             logEntry.append ( lf );
>             if (t != null)
>             {
>                 ByteArrayOutputStream ostr = new ByteArrayOutputStream();
>                 PrintWriter out = new PrintWriter(ostr,true);
>                 out.write(logEntry.toString());
>                 out.write("\tException:  ");
>                 out.write(t.toString());
>                 out.write(lf+"\tStack Trace follows:"+lf+"\t");
>                 t.printStackTrace(out);
>                 logEntry = new StringBuffer( ostr.toString() );
>             }
>             synchronized( (FileWriter)logfiles[activeLogNumber][1]  )
>             {
>                 try
>                 {
>                     ((FileWriter)logfiles[activeLogNumber][1]).write( 
>logEntry.toString(), 0, logEntry.length());
>                     ((FileWriter)logfiles[activeLogNumber][1]).flush();
>                 }
>                 catch(IOException ioe)
>                 {
>                     // ignore, skip log, should not occur since we have checked file
>                     // but catching the exception allows Log to be used elsewhere in
>                     // catch blocks.
>                     return false;
>                 }
>             }
>             return true;
>         }
>               return false;
>     }
231c367
<         Attempt to close the log file when the class is GC'd
---
>         Attempt to close the log files when the class is GC'd
237c373,386
<             logfile.close();
---
>             if (logfile != null)
>             {
>                 logfile.close();
>             }
>             if (logfiles.length>0)
>             {
>                 for (int i=0;i<logfiles.length;i++)
>                 {
>                     if(logfiles[i][1] != null)
>                     {
>                         ((FileWriter)logfiles[i][1]).close();
>                     }
>                 }
>             }
******************        END PATCH          ****************

John
-- 
********************************
** John Thorhauer
** [EMAIL PROTECTED]
********************************


------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?:           [EMAIL PROTECTED]

Reply via email to