ceki 01/03/21 15:17:06 Modified: src/java/org/apache/log4j ConsoleAppender.java FileAppender.java WriterAppender.java src/java/org/apache/log4j/net SMTPAppender.java Log: Still restoring backwards compatibility. Revision Changes Path 1.5 +56 -4 jakarta-log4j/src/java/org/apache/log4j/ConsoleAppender.java Index: ConsoleAppender.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/ConsoleAppender.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ConsoleAppender.java 2001/03/19 12:38:18 1.4 +++ ConsoleAppender.java 2001/03/21 23:16:57 1.5 @@ -13,7 +13,8 @@ /** ConsoleAppender appends log events to <code>System.err</code> or - <code>System.out</code> using a layout specified by the user. + <code>System.out</code> using a layout specified by the + user. The default target is <code>System.out</code>. @author Ceki Gülcü @since 1.1 */ @@ -22,7 +23,12 @@ public static final String SYSTEM_OUT = "System.out"; public static final String SYSTEM_ERR = "System.err"; - protected String target = SYSTEM_ERR; + /** + @deprecated We now use JavaBeans introspection to configure + components. Options strings are no longer needed. */ + public static final String TARGET_OPTION = "Target"; + + protected String target = SYSTEM_OUT; /** The default constructor does nothing. @@ -31,7 +37,7 @@ } public ConsoleAppender(Layout layout) { - this(layout, SYSTEM_ERR); + this(layout, SYSTEM_OUT); } public ConsoleAppender(Layout layout, String target) { @@ -73,7 +79,7 @@ void targetWarn(String val) { LogLog.warn("["+val+"] should be one of System.out or System.err."); - LogLog.warn("Reverting to System.err."); + LogLog.warn("Reverting to System.out."); } public @@ -92,4 +98,50 @@ final void closeWriter() { } + + + /** + Retuns the option names for this component, namely the string + array {{@link #TARGET_OPTION} and the options of its super class + {@link WriterAppender}. + + <b>See</b> Options of the super classes {@link WriterAppender} and + {@link AppenderSkeleton}. In particular the <b>Threshold</b> + option. + + @deprecated We now use JavaBeans introspection to configure + components. Options strings are no longer needed. + */ + public + String[] getOptionStrings() { + return OptionConverter.concatanateArrays(super.getOptionStrings(), + new String[] {TARGET_OPTION}); + } + + /** + Set ConsoleAppender specific options. + + The <b>Target</b> option is recognized on top of options + for the super class {@link WriterAppender}. + + @deprecated Use the setter method for the option directly instead + of the generic <code>setOption</code> method. + */ + public + void setOption(String key, String value) { + if(value == null) return; + super.setOption(key, value); + + if (key.equalsIgnoreCase(TARGET_OPTION)) { + String v = value.trim(); + if(SYSTEM_OUT.equalsIgnoreCase(v)) { + target = SYSTEM_OUT; + } else { + if(!SYSTEM_ERR.equalsIgnoreCase(v)) { + targetWarn(value); + } + } + } + } + } 1.19 +77 -5 jakarta-log4j/src/java/org/apache/log4j/FileAppender.java Index: FileAppender.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/FileAppender.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- FileAppender.java 2001/03/21 22:03:36 1.18 +++ FileAppender.java 2001/03/21 23:16:58 1.19 @@ -35,6 +35,32 @@ @author Ceki Gülcü */ public class FileAppender extends WriterAppender { + /** + A string constant used in naming the option for setting the + output file. Current value of this string constant is + <b>File</b>. + + <p>Note that all option keys are case sensitive. + + @deprecated We now use JavaBeans introspection to configure + components. Options strings are no longer needed. + */ + public static final String FILE_OPTION = "File"; + + + /** + A string constant used in naming the option that determines whether + the output file will be truncated or appended to. Current value + of this string constant is <b>Append</b>. + + <p>Note that all option keys are case sensitive. + + @deprecated We now use JavaBeans introspection to configure + components. Options strings are no longer needed. + */ + public static final String APPEND_OPTION = "Append"; + + /** Append to or truncate the file? The default value for this variable is <code>true</code>, meaning that by default a <code>FileAppender</code> will append to an existing file and @@ -152,6 +178,15 @@ fileName = val; } } + + /** + Returns the value of the <b>Append</b> option. + */ + public + boolean getAppend() { + return fileAppend; + } + /** Returns the value of the <b>File</b> option. */ public @@ -160,6 +195,22 @@ } /** + Returns the option names for this component, namely the string + array {@link #FILE_OPTION}, {@link #APPEND_OPTION}} in addition + to the options of its super class {@link WriterAppender}. + + @deprecated We now use JavaBeans introspection to configure + components. Options strings are no longer needed. + + */ + public + String[] getOptionStrings() { + return OptionConverter.concatanateArrays(super.getOptionStrings(), + new String[] {FILE_OPTION, APPEND_OPTION}); + } + + + /** <The <b>Append</b> option takes a boolean value. It is set to <code>true</code> by default. If true, then <code>File</code> will be opened in append mode by {@link #setFile setFile} (see @@ -174,11 +225,6 @@ fileAppend = flag; } - /** Returns the value of the <b>Append</b> option. */ - public - boolean getAppend() { - return fileAppend; - } /** If the value of {@link #FILE_OPTION} is not <code>null</code>, then {@link @@ -241,6 +287,32 @@ this.fileAppend = append; this.qwIsOurs = true; writeHeader(); + } + + + /** + @deprecated Use the setter method for the option directly instead + of the generic <code>setOption</code> method. */ + public + void setOption(String key, String value) { + if(value == null) return; + super.setOption(key, value); + + if(key.equalsIgnoreCase(FILE_OPTION)) { + // Trim spaces from both ends. The users probably does not want + // trailing spaces in file names. + String val = value.trim(); + if(val.equalsIgnoreCase("System.out")) { + setWriter(new OutputStreamWriter(System.out)); + } else if(val.equalsIgnoreCase("System.err")) { + setWriter(new OutputStreamWriter(System.err)); + } else { + fileName = val; + } + } + else if (key.equalsIgnoreCase(APPEND_OPTION)) { + fileAppend = OptionConverter.toBoolean(value, fileAppend); + } } /** 1.10 +28 -1 jakarta-log4j/src/java/org/apache/log4j/WriterAppender.java Index: WriterAppender.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/WriterAppender.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- WriterAppender.java 2001/03/21 22:03:36 1.9 +++ WriterAppender.java 2001/03/21 23:16:59 1.10 @@ -223,6 +223,20 @@ } } } + + + /** + Retuns the option names for this component. + + @deprecated We now use JavaBeans introspection to configure + components. Options strings are no longer needed. + */ + public + String[] getOptionStrings() { + return OptionConverter.concatanateArrays(super.getOptionStrings(), + new String[] {IMMEDIATE_FLUSH_OPTION}); + } + /** Set the {@link ErrorHandler} for this FileAppender and also the @@ -239,7 +253,20 @@ } } } - + + /** + @deprecated Use the setter method for the option directly instead + of the generic <code>setOption</code> method. + */ + public + void setOption(String key, String value) { + if(value == null) return; + super.setOption(key, value); + + if (key.equalsIgnoreCase(IMMEDIATE_FLUSH_OPTION)) { + immediateFlush = OptionConverter.toBoolean(value, immediateFlush); + } + } /** <p>Sets the Writer where the log output will go. The 1.20 +35 -27 jakarta-log4j/src/java/org/apache/log4j/net/SMTPAppender.java Index: SMTPAppender.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/net/SMTPAppender.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- SMTPAppender.java 2001/03/21 22:03:38 1.19 +++ SMTPAppender.java 2001/03/21 23:17:04 1.20 @@ -329,13 +329,14 @@ } } + + /** - The <b>From</b> option takes a string value which should be a - e-mail address of the sender. + Returns value of the <b>EvaluatorClass</b> option. */ public - void setFrom(String from) { - this.from = from; + String getEvaluatorClass() { + return evaluator == null ? null : evaluator.getClass().getName(); } /** @@ -346,7 +347,15 @@ return from; } + /** + Returns value of the <b>Subject</b> option. + */ + public + String getSubject() { + return subject; + } + /** @deprecated Use the setter method for the option directly, instead of the generic <code>setOption</code> method. */ @@ -375,15 +384,17 @@ locationInfo = OptionConverter.toBoolean(value, locationInfo); } + /** - The <b>To</b> option takes a string value which should be a - comma separated list of e-mail address of the recipients. + The <b>From</b> option takes a string value which should be a + e-mail address of the sender. */ public - void setTo(String to) { - this.to = to; + void setFrom(String from) { + this.from = from; } + /** The <b>Subject</b> option takes a string value which should be a @@ -394,12 +405,18 @@ this.subject = subject; } + /** - Returns value of the <b>Subject</b> option. + The <b>BufferSize</b>option takes a positive integer + representing the maximum number of logging events to collect in a + cyclic buffer. When the <code>BufferSize</code> is reached, + oldest events are deleted as new events are added to the + buffer. By default the size of the cyclic buffer is 512 events. */ public - String getSubject() { - return subject; + void setBufferSize(int bufferSize) { + this.bufferSize = bufferSize; + cb.resize(bufferSize); } /** @@ -418,20 +435,18 @@ String getSMTPHost() { return smtpHost; } - + /** - The <b>BufferSize</b>option takes a positive integer - representing the maximum number of logging events to collect in a - cyclic buffer. When the <code>BufferSize</code> is reached, - oldest events are deleted as new events are added to the - buffer. By default the size of the cyclic buffer is 512 events. + The <b>To</b> option takes a string value which should be a + comma separated list of e-mail address of the recipients. */ public - void setBufferSize(int bufferSize) { - this.bufferSize = bufferSize; - cb.resize(bufferSize); + void setTo(String to) { + this.to = to; } + + /** Returns value of the <b>BufferSize</b> option. */ @@ -455,13 +470,6 @@ evaluator); } - /** - Returns value of the <b>EvaluatorClass</b> option. - */ - public - String getEvaluatorClass() { - return evaluator == null ? null : evaluator.getClass().getName(); - } /** The <b>LocationInfo</b> option takes a boolean value. By --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]