01: /*
02:
03: Derby - Class org.apache.derby.impl.services.stream.BasicGetLogHeader
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to you under the Apache License, Version 2.0
09: (the "License"); you may not use this file except in compliance with
10: the License. You may obtain a copy of the License at
11:
12: http://www.apache.org/licenses/LICENSE-2.0
13:
14: Unless required by applicable law or agreed to in writing, software
15: distributed under the License is distributed on an "AS IS" BASIS,
16: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: See the License for the specific language governing permissions and
18: limitations under the License.
19:
20: */
21:
22: package org.apache.derby.impl.services.stream;
23:
24: import org.apache.derby.iapi.services.stream.PrintWriterGetHeader;
25: import org.apache.derby.iapi.util.CheapDateFormatter;
26:
27: /**
28: * Get a header to prepend to a line of output. *
29: * A HeaderPrintWriter requires an object which implements
30: * this interface to construct line headers.
31: *
32: * @see org.apache.derby.iapi.services.stream.HeaderPrintWriter
33: */
34:
35: class BasicGetLogHeader implements PrintWriterGetHeader {
36:
37: private boolean doThreadId;
38: private boolean doTimeStamp;
39: private String tag;
40:
41: /*
42: * STUB: This should take a header template. Check if
43: * the error message facility provides something.
44: *
45: * This should be localizable. How?
46: */
47: /**
48: * Constructor for a BasicGetLogHeader object.
49: * <p>
50: * @param doThreadId true means include the calling thread's
51: * id in the header.
52: * @param doTimeStamp true means include the current time in
53: * the header.
54: * @param tag A string to prefix the header. null
55: * means don't prefix the header with
56: * a string.
57: */
58: BasicGetLogHeader(boolean doThreadId, boolean doTimeStamp,
59: String tag) {
60: this .doThreadId = doThreadId;
61: this .doTimeStamp = doTimeStamp;
62: this .tag = tag;
63: }
64:
65: public String getHeader() {
66: StringBuffer header = new StringBuffer(48);
67:
68: if (tag != null) {
69: header.append(tag);
70: header.append(' ');
71: }
72:
73: if (doTimeStamp) {
74: long currentTime = System.currentTimeMillis();
75:
76: header.append(CheapDateFormatter.formatDate(currentTime));
77: header.append(' ');
78:
79: }
80: if (doThreadId) {
81: header.append(Thread.currentThread().toString());
82: header.append(' ');
83: }
84:
85: return header.toString();
86: }
87: }
|