View | Details | Raw Unified | Return to bug 46252
Collapse All | Expand All

(-)java/org/apache/catalina/valves/AccessLogValve.java (-5 / +52 lines)
Lines 21-30 Link Here
21
21
22
import java.io.BufferedWriter;
22
import java.io.BufferedWriter;
23
import java.io.File;
23
import java.io.File;
24
import java.io.FileWriter;
24
import java.io.FileOutputStream;
25
import java.io.IOException;
25
import java.io.IOException;
26
import java.io.OutputStreamWriter;
26
import java.io.PrintWriter;
27
import java.io.PrintWriter;
28
import java.io.UnsupportedEncodingException;
27
import java.net.InetAddress;
29
import java.net.InetAddress;
30
import java.nio.charset.Charset;
28
import java.text.SimpleDateFormat;
31
import java.text.SimpleDateFormat;
29
import java.util.ArrayList;
32
import java.util.ArrayList;
30
import java.util.Date;
33
import java.util.Date;
Lines 47-52 Link Here
47
import org.apache.coyote.RequestInfo;
50
import org.apache.coyote.RequestInfo;
48
import org.apache.juli.logging.Log;
51
import org.apache.juli.logging.Log;
49
import org.apache.juli.logging.LogFactory;
52
import org.apache.juli.logging.LogFactory;
53
import org.apache.tomcat.util.buf.B2CConverter;
50
54
51
55
52
/**
56
/**
Lines 301-308 Link Here
301
     * Date format to place in log file name. Use at your own risk!
305
     * Date format to place in log file name. Use at your own risk!
302
     */
306
     */
303
    protected String fileDateFormat = null;
307
    protected String fileDateFormat = null;
304
    
308
305
    /**
309
    /**
310
     * Character set used by the log file. If it is <code>null</code>, the
311
     * system default character set will be used. An empty string will be
312
     * treated as <code>null</code> when this property is assigned.
313
     */
314
    protected String encoding = null;
315
316
    /**
306
     * Array of AccessLogElement, they will be used to make log message.
317
     * Array of AccessLogElement, they will be used to make log message.
307
     */
318
     */
308
    protected AccessLogElement[] logElements = null;
319
    protected AccessLogElement[] logElements = null;
Lines 522-527 Link Here
522
        this.fileDateFormat =  fileDateFormat;
533
        this.fileDateFormat =  fileDateFormat;
523
    }
534
    }
524
535
536
    /**
537
     * Return the character set name that is used to write the log file.
538
     *
539
     * @return Character set name, or <code>null</code> if the system default
540
     *  character set is used.
541
     */
542
    public String getEncoding() {
543
        return encoding;
544
    }
545
546
    /**
547
     * Set the character set that is used to write the log file.
548
     * 
549
     * @param encoding The name of the character set.
550
     */
551
    public void setEncoding(String encoding) {
552
        if (encoding != null && encoding.length() > 0) {
553
            this.encoding = encoding;
554
        } else {
555
            this.encoding = null;
556
        }
557
    }
558
525
    // --------------------------------------------------------- Public Methods
559
    // --------------------------------------------------------- Public Methods
526
560
527
    /**
561
    /**
Lines 730-738 Link Here
730
                pathname = dir.getAbsolutePath() + File.separator + prefix
764
                pathname = dir.getAbsolutePath() + File.separator + prefix
731
                        + suffix;
765
                        + suffix;
732
            }
766
            }
733
            writer = new PrintWriter(new BufferedWriter(new FileWriter(
767
            Charset charset = null;
734
                    pathname, true), 128000), false);
768
            if (encoding != null) {
735
            
769
                try {
770
                    charset = B2CConverter.getCharset(encoding);
771
                } catch (UnsupportedEncodingException ex) {
772
                    log.error(sm.getString(
773
                            "accessLogValve.unsupportedEncoding", encoding), ex);
774
                }
775
            }
776
            if (charset == null) {
777
                charset = Charset.defaultCharset();
778
            }
779
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
780
                    new FileOutputStream(pathname, true), charset), 128000),
781
                    false);
782
736
            currentLogFile = new File(pathname);
783
            currentLogFile = new File(pathname);
737
        } catch (IOException e) {
784
        } catch (IOException e) {
738
            writer = null;
785
            writer = null;
(-)java/org/apache/catalina/valves/LocalStrings.properties (+1 lines)
Lines 30-35 Link Here
30
# Access log valve
30
# Access log valve
31
accessLogValve.alreadyStarted=Access Logger has already been started
31
accessLogValve.alreadyStarted=Access Logger has already been started
32
accessLogValve.notStarted=Access Logger has not yet been started
32
accessLogValve.notStarted=Access Logger has not yet been started
33
accessLogValve.unsupportedEncoding=Failed to set encoding to [{0}], will use the system default character set.
33
34
34
# Error report valve
35
# Error report valve
35
errorReportValve.errorReport=Error report
36
errorReportValve.errorReport=Error report
(-)webapps/docs/config/valve.xml (+7 lines)
Lines 103-108 Link Here
103
        (relative to $CATALINA_BASE).</p>
103
        (relative to $CATALINA_BASE).</p>
104
      </attribute>
104
      </attribute>
105
105
106
      <attribute name="encoding" required="false">
107
        <p>Character set used to write the log file. An empty string means
108
        to use the system default character set. Default value: use the
109
        system default character set.
110
        </p>
111
      </attribute>
112
106
      <attribute name="pattern" required="false">
113
      <attribute name="pattern" required="false">
107
        <p>A formatting layout identifying the various information fields
114
        <p>A formatting layout identifying the various information fields
108
        from the request and response to be logged, or the word
115
        from the request and response to be logged, or the word

Return to bug 46252