< prev index next >

src/share/vm/logging/logFileStreamOutput.hpp

Print this page
rev 12117 : 8146009:


  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 #ifndef SHARE_VM_LOGGING_LOGFILESTREAMOUTPUT_HPP
  25 #define SHARE_VM_LOGGING_LOGFILESTREAMOUTPUT_HPP
  26 
  27 #include "logging/logDecorators.hpp"
  28 #include "logging/logOutput.hpp"
  29 #include "utilities/globalDefinitions.hpp"
  30 
  31 class LogDecorations;
  32 








  33 // Base class for all FileStream-based log outputs.
  34 class LogFileStreamOutput : public LogOutput {
  35  protected:
  36   FILE*               _stream;
  37   size_t              _decorator_padding[LogDecorators::Count];
  38 
  39   LogFileStreamOutput(FILE *stream) : _stream(stream) {
  40     for (size_t i = 0; i < LogDecorators::Count; i++) {
  41       _decorator_padding[i] = 0;
  42     }
  43   }
  44 
  45   int write_decorations(const LogDecorations& decorations);
  46 
  47  public:
  48   virtual int write(const LogDecorations& decorations, const char* msg);
  49   virtual int write(LogMessageBuffer::Iterator msg_iterator);
  50 };
  51 
  52 class LogStdoutOutput : public LogFileStreamOutput {
  53   friend class LogOutput;
  54  private:
  55   static LogStdoutOutput _instance;
  56   LogStdoutOutput() : LogFileStreamOutput(stdout) {
  57     set_config_string("all=warning");
  58   }
  59   virtual bool initialize(const char* options, outputStream* errstream) {
  60     return false;
  61   }
  62  public:
  63   virtual const char* name() const {
  64     return "stdout";
  65   }
  66 };
  67 
  68 class LogStderrOutput : public LogFileStreamOutput {
  69   friend class LogOutput;
  70  private:
  71   static LogStderrOutput _instance;
  72   LogStderrOutput() : LogFileStreamOutput(stderr) {
  73     set_config_string("all=off");
  74   }
  75   virtual bool initialize(const char* options, outputStream* errstream) {
  76     return false;
  77   }
  78  public:
  79   virtual const char* name() const {
  80     return "stderr";
  81   }
  82 };



  83 
  84 #endif // SHARE_VM_LOGGING_LOGFILESTREAMOUTPUT_HPP


  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 #ifndef SHARE_VM_LOGGING_LOGFILESTREAMOUTPUT_HPP
  25 #define SHARE_VM_LOGGING_LOGFILESTREAMOUTPUT_HPP
  26 
  27 #include "logging/logDecorators.hpp"
  28 #include "logging/logOutput.hpp"
  29 #include "utilities/globalDefinitions.hpp"
  30 
  31 class LogDecorations;
  32 
  33 class LogFileStreamInitializer {
  34  public:
  35   LogFileStreamInitializer();
  36 };
  37 
  38 // Ensure the default log streams have been initialized (stdout, stderr) using the static initializer below
  39 static LogFileStreamInitializer log_stream_initializer;
  40 
  41 // Base class for all FileStream-based log outputs.
  42 class LogFileStreamOutput : public LogOutput {
  43  protected:
  44   FILE*               _stream;
  45   size_t              _decorator_padding[LogDecorators::Count];
  46 
  47   LogFileStreamOutput(FILE *stream) : _stream(stream) {
  48     for (size_t i = 0; i < LogDecorators::Count; i++) {
  49       _decorator_padding[i] = 0;
  50     }
  51   }
  52 
  53   int write_decorations(const LogDecorations& decorations);
  54 
  55  public:
  56   virtual int write(const LogDecorations& decorations, const char* msg);
  57   virtual int write(LogMessageBuffer::Iterator msg_iterator);
  58 };
  59 
  60 class LogStdoutOutput : public LogFileStreamOutput {
  61   friend class LogFileStreamInitializer;
  62  private:

  63   LogStdoutOutput() : LogFileStreamOutput(stdout) {
  64     set_config_string("all=warning");
  65   }
  66   virtual bool initialize(const char* options, outputStream* errstream) {
  67     return false;
  68   }
  69  public:
  70   virtual const char* name() const {
  71     return "stdout";
  72   }
  73 };
  74 
  75 class LogStderrOutput : public LogFileStreamOutput {
  76   friend class LogFileStreamInitializer;
  77  private:

  78   LogStderrOutput() : LogFileStreamOutput(stderr) {
  79     set_config_string("all=off");
  80   }
  81   virtual bool initialize(const char* options, outputStream* errstream) {
  82     return false;
  83   }
  84  public:
  85   virtual const char* name() const {
  86     return "stderr";
  87   }
  88 };
  89 
  90 extern LogStderrOutput &StderrLog;
  91 extern LogStdoutOutput &StdoutLog;
  92 
  93 #endif // SHARE_VM_LOGGING_LOGFILESTREAMOUTPUT_HPP
< prev index next >