1 /*=========================================================================== 2 * 3 * PUBLIC DOMAIN NOTICE 4 * National Center for Biotechnology Information 5 * 6 * This software/database is a "United States Government Work" under the 7 * terms of the United States Copyright Act. It was written as part of 8 * the author's official duties as a United States Government employee and 9 * thus cannot be copyrighted. This software/database is freely available 10 * to the public for use. The National Library of Medicine and the U.S. 11 * Government have not placed any restriction on its use or reproduction. 12 * 13 * Although all reasonable efforts have been taken to ensure the accuracy 14 * and reliability of the software and data, the NLM and the U.S. 15 * Government do not and cannot warrant the performance or results that 16 * may be obtained by using this software or data. The NLM and the U.S. 17 * Government disclaim all warranties, express or implied, including 18 * warranties of performance, merchantability or fitness for any particular 19 * purpose. 20 * 21 * Please cite the author in any work or product based on this material. 22 * 23 * =========================================================================== 24 * 25 */ 26 27 #ifndef _hpp_vdb3_kfc_log_ 28 #define _hpp_vdb3_kfc_log_ 29 30 #ifndef _hpp_vdb3_kfc_ref_ 31 #include <kfc/ref.hpp> 32 #endif 33 34 35 namespace vdb3 36 { 37 38 /*------------------------------------------------------------------ 39 * forwards 40 */ 41 class Log; 42 class Refcount; 43 interface LoggerItf; 44 45 46 /*------------------------------------------------------------------ 47 * LogLevel 48 * mimic unix syslog 49 */ 50 enum LogLevel 51 { 52 log_emerg = 1, 53 log_alert, 54 log_crit, 55 log_err, 56 log_warning, 57 log_notice, 58 log_info 59 }; 60 61 /*------------------------------------------------------------------ 62 * LoggerItf 63 */ 64 interface LoggerItf 65 { 66 // perform the formatting of the message 67 // transfer it to the task log stream 68 virtual void msg ( LogLevel priority, const char * fmt, va_list args ) = 0; 69 70 protected: 71 72 Log make_ref ( Refcount * obj, caps_t caps ); 73 74 private: 75 76 static void * cast ( Refcount * obj ); 77 78 friend class Log; 79 }; 80 81 /*------------------------------------------------------------------ 82 * Log 83 * logging formatter 84 * handles output to the log stream 85 */ 86 class Log : public Ref < LoggerItf > 87 { 88 public: 89 90 // log level get_level() const91 LogLevel get_level () const 92 { return lvl; } 93 void set_level ( LogLevel level ); 94 95 // log message 96 void msg ( LogLevel priority, const char * fmt, ... ) const; 97 void vmsg ( LogLevel priority, const char * fmt, va_list args ) const; 98 99 // C++ 100 Log (); 101 Log ( const Log & r ); 102 void operator = ( const Log & r ); 103 Log ( const Log & r, caps_t reduce ); 104 ~ Log (); 105 106 private: 107 108 // factory 109 Log ( Refcount * obj, LoggerItf * itf, caps_t caps ); 110 111 LogLevel lvl; 112 113 friend interface LoggerItf; 114 }; 115 116 } 117 118 #endif // _hpp_vdb3_kfc_log_ 119