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 */
24 #include "precompiled.hpp"
25 #include "logging/logDecorators.hpp"
26 #include "logging/logDecorations.hpp"
27 #include "logging/logFileStreamOutput.hpp"
28 #include "logging/logMessageBuffer.hpp"
29 #include "memory/allocation.inline.hpp"
30
31 LogStdoutOutput LogStdoutOutput::_instance;
32 LogStderrOutput LogStderrOutput::_instance;
33
34 int LogFileStreamOutput::write_decorations(const LogDecorations& decorations) {
35 int total_written = 0;
36
37 for (uint i = 0; i < LogDecorators::Count; i++) {
38 LogDecorators::Decorator decorator = static_cast<LogDecorators::Decorator>(i);
39 if (!_decorators.is_decorator(decorator)) {
40 continue;
41 }
42
43 int written = jio_fprintf(_stream, "[%-*s]",
44 _decorator_padding[decorator],
45 decorations.decoration(decorator));
46 if (written <= 0) {
47 return -1;
48 } else if (static_cast<size_t>(written - 2) > _decorator_padding[decorator]) {
49 _decorator_padding[decorator] = written - 2;
50 }
51 total_written += written;
52 }
|
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 */
24 #include "precompiled.hpp"
25 #include "logging/logDecorators.hpp"
26 #include "logging/logDecorations.hpp"
27 #include "logging/logFileStreamOutput.hpp"
28 #include "logging/logMessageBuffer.hpp"
29 #include "memory/allocation.inline.hpp"
30
31 static volatile jint initialized;
32 static char stdoutmem[sizeof(LogStdoutOutput)];
33 static char stderrmem[sizeof(LogStderrOutput)];
34
35 LogStdoutOutput &StdoutLog = reinterpret_cast<LogStdoutOutput&>(stdoutmem);
36 LogStderrOutput &StderrLog = reinterpret_cast<LogStderrOutput&>(stderrmem);
37
38 LogFileStreamInitializer::LogFileStreamInitializer() {
39 if (Atomic::cmpxchg(1, &initialized, 0) == 0) {
40 ::new (&StdoutLog) LogStdoutOutput();
41 ::new (&StderrLog) LogStderrOutput();
42 }
43 }
44
45 int LogFileStreamOutput::write_decorations(const LogDecorations& decorations) {
46 int total_written = 0;
47
48 for (uint i = 0; i < LogDecorators::Count; i++) {
49 LogDecorators::Decorator decorator = static_cast<LogDecorators::Decorator>(i);
50 if (!_decorators.is_decorator(decorator)) {
51 continue;
52 }
53
54 int written = jio_fprintf(_stream, "[%-*s]",
55 _decorator_padding[decorator],
56 decorations.decoration(decorator));
57 if (written <= 0) {
58 return -1;
59 } else if (static_cast<size_t>(written - 2) > _decorator_padding[decorator]) {
60 _decorator_padding[decorator] = written - 2;
61 }
62 total_written += written;
63 }
|