00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one or more 00003 * contributor license agreements. See the NOTICE file distributed with 00004 * this work for additional information regarding copyright ownership. 00005 * The ASF licenses this file to You under the Apache License, Version 2.0 00006 * (the "License"); you may not use this file except in compliance with 00007 * the License. You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 #ifndef _DECAF_UTIL_LOGGING_STREAMHANDLER_H_ 00018 #define _DECAF_UTIL_LOGGING_STREAMHANDLER_H_ 00019 00020 #include <decaf/util/logging/LoggerCommon.h> 00021 #include <decaf/util/logging/Handler.h> 00022 #include <decaf/lang/exceptions/NullPointerException.h> 00023 #include <decaf/lang/exceptions/InvalidStateException.h> 00024 #include <decaf/util/concurrent/Concurrent.h> 00025 #include <decaf/util/Config.h> 00026 00027 namespace decaf{ 00028 namespace io{ 00029 class OutputStream; 00030 class Writer; 00031 } 00032 namespace util{ 00033 namespace logging{ 00034 00056 class DECAF_API StreamHandler : public Handler { 00057 private: 00058 00059 // OutputStream to write to 00060 decaf::io::OutputStream* stream; 00061 00062 // A Writer to wrap the OutputStream 00063 decaf::io::Writer* writer; 00064 00065 // Indicates if the writer has been initialized already 00066 bool writerNotInitialized; 00067 00068 private: 00069 00070 StreamHandler( const StreamHandler& ); 00071 StreamHandler& operator= ( const StreamHandler& ); 00072 00073 public: 00074 00078 StreamHandler(); 00079 00083 StreamHandler( decaf::io::OutputStream* stream, Formatter* formatter ); 00084 00085 virtual ~StreamHandler(); 00086 00097 virtual void close(); 00098 00102 virtual void flush(); 00103 00110 virtual void publish( const LogRecord& record ); 00111 00120 virtual bool isLoggable( const LogRecord& record ) const; 00121 00122 protected: 00123 00136 virtual void setOuputStream( decaf::io::OutputStream* stream ); 00137 00145 void close( bool closeStream ); 00146 00147 private: 00148 00149 // Safely writes the string to the output stream, calling the ErrorManager 00150 // if any exceptions are thrown while writing. 00151 void write( const std::string& value ); 00152 00153 // Initialize the Writer if its not already been initialized. 00154 void initializeWritter(); 00155 00156 }; 00157 00158 }}} 00159 00160 #endif /*_DECAF_UTIL_LOGGING_STREAMHANDLER_H_*/
1.6.1