author | naoto |
Tue, 09 Jul 2019 08:05:38 -0700 | |
changeset 55627 | 9c1885fb2a42 |
parent 53845 | 1807da9ad196 |
permissions | -rw-r--r-- |
33097 | 1 |
/* |
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
49180
diff
changeset
|
2 |
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
33097 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
* |
|
23 |
*/ |
|
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
49180
diff
changeset
|
24 |
#ifndef SHARE_LOGGING_LOGFILEOUTPUT_HPP |
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
49180
diff
changeset
|
25 |
#define SHARE_LOGGING_LOGFILEOUTPUT_HPP |
33097 | 26 |
|
27 |
#include "logging/logFileStreamOutput.hpp" |
|
35230
a528ea8203ec
8145294: TestLogRotation.java triggers a race in the UL framework
mlarsson
parents:
34637
diff
changeset
|
28 |
#include "runtime/semaphore.hpp" |
33097 | 29 |
#include "utilities/globalDefinitions.hpp" |
30 |
||
31 |
class LogDecorations; |
|
32 |
||
33 |
// The log file output, with support for file rotation based on a target size. |
|
34 |
class LogFileOutput : public LogFileStreamOutput { |
|
35 |
private: |
|
46672
dc24cb5e50a1
8184309: Buld warnings from GCC 7.1 on Fedora 26
ysuenaga
parents:
40902
diff
changeset
|
36 |
static const char* const FileOpenMode; |
dc24cb5e50a1
8184309: Buld warnings from GCC 7.1 on Fedora 26
ysuenaga
parents:
40902
diff
changeset
|
37 |
static const char* const FileCountOptionKey; |
dc24cb5e50a1
8184309: Buld warnings from GCC 7.1 on Fedora 26
ysuenaga
parents:
40902
diff
changeset
|
38 |
static const char* const FileSizeOptionKey; |
dc24cb5e50a1
8184309: Buld warnings from GCC 7.1 on Fedora 26
ysuenaga
parents:
40902
diff
changeset
|
39 |
static const char* const PidFilenamePlaceholder; |
dc24cb5e50a1
8184309: Buld warnings from GCC 7.1 on Fedora 26
ysuenaga
parents:
40902
diff
changeset
|
40 |
static const char* const TimestampFilenamePlaceholder; |
dc24cb5e50a1
8184309: Buld warnings from GCC 7.1 on Fedora 26
ysuenaga
parents:
40902
diff
changeset
|
41 |
static const char* const TimestampFormat; |
37465
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
35230
diff
changeset
|
42 |
static const size_t DefaultFileCount = 5; |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
35230
diff
changeset
|
43 |
static const size_t DefaultFileSize = 20 * M; |
33097 | 44 |
static const size_t StartTimeBufferSize = 20; |
37465
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
35230
diff
changeset
|
45 |
static const size_t PidBufferSize = 21; |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
35230
diff
changeset
|
46 |
static const uint MaxRotationFileCount = 1000; |
33097 | 47 |
static char _pid_str[PidBufferSize]; |
48 |
static char _vm_start_time_str[StartTimeBufferSize]; |
|
49 |
||
50 |
const char* _name; |
|
51 |
char* _file_name; |
|
52 |
char* _archive_name; |
|
53 |
||
54 |
uint _current_file; |
|
55 |
uint _file_count; |
|
56 |
uint _file_count_max_digits; |
|
53369
55cee96fefec
8215699: -Xlog::file cannot be used with named pipe
hseigel
parents:
53244
diff
changeset
|
57 |
bool _is_default_file_count; |
33097 | 58 |
|
59 |
size_t _archive_name_len; |
|
60 |
size_t _rotate_size; |
|
61 |
size_t _current_size; |
|
62 |
||
35230
a528ea8203ec
8145294: TestLogRotation.java triggers a race in the UL framework
mlarsson
parents:
34637
diff
changeset
|
63 |
// Semaphore used for synchronizing file rotations and writes |
a528ea8203ec
8145294: TestLogRotation.java triggers a race in the UL framework
mlarsson
parents:
34637
diff
changeset
|
64 |
Semaphore _rotation_semaphore; |
a528ea8203ec
8145294: TestLogRotation.java triggers a race in the UL framework
mlarsson
parents:
34637
diff
changeset
|
65 |
|
33097 | 66 |
void archive(); |
35230
a528ea8203ec
8145294: TestLogRotation.java triggers a race in the UL framework
mlarsson
parents:
34637
diff
changeset
|
67 |
void rotate(); |
37465
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
35230
diff
changeset
|
68 |
bool parse_options(const char* options, outputStream* errstream); |
33097 | 69 |
char *make_file_name(const char* file_name, const char* pid_string, const char* timestamp_string); |
70 |
||
35230
a528ea8203ec
8145294: TestLogRotation.java triggers a race in the UL framework
mlarsson
parents:
34637
diff
changeset
|
71 |
bool should_rotate() { |
a528ea8203ec
8145294: TestLogRotation.java triggers a race in the UL framework
mlarsson
parents:
34637
diff
changeset
|
72 |
return _file_count > 0 && _rotate_size > 0 && _current_size >= _rotate_size; |
33097 | 73 |
} |
74 |
||
37465
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
35230
diff
changeset
|
75 |
void increment_file_count() { |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
35230
diff
changeset
|
76 |
_current_file++; |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
35230
diff
changeset
|
77 |
if (_current_file == _file_count) { |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
35230
diff
changeset
|
78 |
_current_file = 0; |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
35230
diff
changeset
|
79 |
} |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
35230
diff
changeset
|
80 |
} |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
35230
diff
changeset
|
81 |
|
33097 | 82 |
public: |
83 |
LogFileOutput(const char *name); |
|
84 |
virtual ~LogFileOutput(); |
|
37465
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
35230
diff
changeset
|
85 |
virtual bool initialize(const char* options, outputStream* errstream); |
33097 | 86 |
virtual int write(const LogDecorations& decorations, const char* msg); |
38263
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
87 |
virtual int write(LogMessageBuffer::Iterator msg_iterator); |
35230
a528ea8203ec
8145294: TestLogRotation.java triggers a race in the UL framework
mlarsson
parents:
34637
diff
changeset
|
88 |
virtual void force_rotate(); |
49180
9637557def32
8190346: improve unified JVM logging help message and warnings
mlarsson
parents:
47216
diff
changeset
|
89 |
virtual void describe(outputStream* out); |
34637
9b9298044d23
8140556: Add force rotation option to VM.log jcmd
ysuenaga
parents:
33097
diff
changeset
|
90 |
|
33097 | 91 |
virtual const char* name() const { |
92 |
return _name; |
|
93 |
} |
|
94 |
||
53845
1807da9ad196
8167548: [TESTBUG] Logging tests put log files in source tree
hseigel
parents:
53369
diff
changeset
|
95 |
const char* cur_log_file_name(); |
46672
dc24cb5e50a1
8184309: Buld warnings from GCC 7.1 on Fedora 26
ysuenaga
parents:
40902
diff
changeset
|
96 |
static const char* const Prefix; |
33097 | 97 |
static void set_file_name_parameters(jlong start_time); |
98 |
}; |
|
99 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
49180
diff
changeset
|
100 |
#endif // SHARE_LOGGING_LOGFILEOUTPUT_HPP |