diff options
author | Aleksey Lim <alsroot@activitycentral.org> | 2011-02-28 16:13:13 (GMT) |
---|---|---|
committer | Aleksey Lim <alsroot@activitycentral.org> | 2011-02-28 16:13:13 (GMT) |
commit | a0705d8ff9b25c1172e38925ec27bb28f9e5a1e9 (patch) | |
tree | d3a20dff1d1e8d196fab33530fb21dd470addef5 /common/Util/Clooper/log.cpp | |
parent | 0c8e687ce284d7599b9bfb7c578b0fc7fb32c493 (diff) |
Revert "fixing simlimking build error"
This reverts commit 0c8e687ce284d7599b9bfb7c578b0fc7fb32c493.
Since common/ directory will be copied to .xo in setup.py anyway.
Diffstat (limited to 'common/Util/Clooper/log.cpp')
-rw-r--r-- | common/Util/Clooper/log.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/common/Util/Clooper/log.cpp b/common/Util/Clooper/log.cpp new file mode 100644 index 0000000..d4a8c72 --- /dev/null +++ b/common/Util/Clooper/log.cpp @@ -0,0 +1,52 @@ +#ifndef LOG_HXX +#define LOG_HXX + +#include <stdarg.h> +#include <stdio.h> + +struct log_t +{ + FILE * _file; + int _level; + int _close; + + log_t(const char * logpath, int level = 0) : _file(NULL), _level(level), _close(1) + { + _file = fopen(logpath, "w"); + if (!_file) + { + fprintf(stderr, "Failed to open log file for writing: %s\n", logpath); + } + } + log_t(FILE * file, int level = 0): _file(file), _level(level), _close(0) + { + } + ~log_t() + { + if (_close && _file) fclose(_file); + } + void printf( const char * fmt, ... ) __attribute__(( format (printf, 2,3))) + { + if (!_file) return; + va_list ap; + va_start(ap,fmt); + ::vfprintf(_file, fmt, ap); + va_end(ap); + fflush(_file); + } + void printf( int level, const char * fmt, ... ) __attribute__(( format (printf, 3,4))) + { + if (level <= _level) + { + if (!_file) return; + fprintf(_file, "L%i:", level); + va_list ap; + va_start(ap,fmt); + ::vfprintf(_file, fmt, ap); + va_end(ap); + fflush(_file); + } + } +}; + +#endif |