log.h

00001 /*
00002  * log.h
00003  * This file is part of dbPager Classes Library (DCL)
00004  *
00005  * Copyright (c) 2009 Dennis Prochko <wolfsoft@mail.ru>
00006  *
00007  * DCL is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation version 3.
00010  *
00011  * DCL is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with DCL; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor,
00019  * Boston, MA  02110-1301  USA
00020  */
00021 
00022 #ifndef _LOG_H_
00023 #define _LOG_H_
00024 
00025 #include <iostream>
00026 #include <queue>
00027 #include <string>
00028 
00029 #include <dcl/event.h>
00030 #include <dcl/strutils.h>
00031 #include <dcl/thread.h>
00032 
00033 namespace dbp {
00034 
00036 
00040 class log {
00041 public:
00043 
00049         log(std::ostream &out = std::clog, int verbose = 0);
00051 
00054         virtual ~log();
00056 
00063         void operator()(int level, const std::string &message);
00064 private:
00065         int _verbose;
00066         bool is_terminated;
00067         std::ostream &_out;
00068         // log buffer
00069         typedef std::queue<std::string> log_buffer;
00070         log_buffer buf;
00071         // working thread
00072         thread t;
00073         // synchronizer objects
00074         mutex _mlock;
00075         event _event;
00076         // logging function
00077         void logging(thread_int&);
00078 };
00079 
00080 } // namespace
00081 
00082 #endif /*_LOG_H_*/

 
Support This Project
SourceForge.net Logo