Path: blob/master/src/hotspot/share/logging/logFileStreamOutput.hpp
40930 views
/*1* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/23#ifndef SHARE_LOGGING_LOGFILESTREAMOUTPUT_HPP24#define SHARE_LOGGING_LOGFILESTREAMOUTPUT_HPP2526#include "logging/logDecorators.hpp"27#include "logging/logOutput.hpp"28#include "utilities/globalDefinitions.hpp"2930class LogDecorations;3132class LogFileStreamInitializer {33public:34LogFileStreamInitializer();35};3637// Ensure the default log streams have been initialized (stdout, stderr) using the static initializer below38static LogFileStreamInitializer log_stream_initializer;3940// Base class for all FileStream-based log outputs.41class LogFileStreamOutput : public LogOutput {42private:43bool _write_error_is_shown;44protected:45FILE* _stream;46size_t _decorator_padding[LogDecorators::Count];4748LogFileStreamOutput(FILE *stream) : _write_error_is_shown(false), _stream(stream) {49for (size_t i = 0; i < LogDecorators::Count; i++) {50_decorator_padding[i] = 0;51}52}5354int write_decorations(const LogDecorations& decorations);55bool flush();5657public:58virtual int write(const LogDecorations& decorations, const char* msg);59virtual int write(LogMessageBuffer::Iterator msg_iterator);60};6162class LogStdoutOutput : public LogFileStreamOutput {63friend class LogFileStreamInitializer;64private:65LogStdoutOutput() : LogFileStreamOutput(stdout) {66set_config_string("all=warning");67}68virtual bool initialize(const char* options, outputStream* errstream) {69return false;70}71public:72virtual const char* name() const {73return "stdout";74}75};7677class LogStderrOutput : public LogFileStreamOutput {78friend class LogFileStreamInitializer;79private:80LogStderrOutput() : LogFileStreamOutput(stderr) {81set_config_string("all=off");82}83virtual bool initialize(const char* options, outputStream* errstream) {84return false;85}86public:87virtual const char* name() const {88return "stderr";89}90};9192extern LogStderrOutput &StderrLog;93extern LogStdoutOutput &StdoutLog;9495#endif // SHARE_LOGGING_LOGFILESTREAMOUTPUT_HPP969798