OSDN Git Service

01e33b773cf4431324536e549bbf183c2cb292dc
[wintimer/wintimer.git] / wintimer / logger.cpp
1 /*
2 ==============================================================================
3
4 This file is part of the S.F.Tracker
5 Copyright 2005-7 by Satoshi Fujiwara.
6
7 S.F.Tracker can be redistributed and/or modified under the terms of the
8 GNU General Public License, as published by the Free Software Foundation;
9 either version 2 of the License, or (at your option) any later version.
10
11 S.F.Tracker is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with S.F.Tracker; if not, visit www.gnu.org/licenses or write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
19 Boston, MA 02111-1307 USA
20
21 ==============================================================================
22 */
23 /** @file
24 *  @author S.F. (Satoshi Fujiwara)
25 */
26
27 #include "stdafx.h"
28 #if _DEBUG
29 #define _CRTDBG_MAP_ALLOC
30 #include <crtdbg.h>
31 #define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
32 #endif
33 namespace sf {
34
35   struct logger::impl 
36   {
37     impl() : m_log_file("sftracker.log",std::ios_base::out | std::ios_base::trunc ){};
38     ~impl() {m_log_file.close();}
39
40     void write(const boost::wformat & fmt)
41     {
42       write(fmt.str());
43     };
44
45     void write(const std::wistream & st)
46     {
47       {   
48         //mutex_type::scoped_lock lock_(m_mutex);
49         m_log_file << st << std::endl;
50       }
51       boost::gregorian::date dt = boost::gregorian::day_clock::local_day();
52
53     };
54
55     void write(const std::wstring & mes) 
56     {   
57       write(mes.c_str());
58     }
59
60     void write(const TCHAR * mes) 
61     {   
62       //mutex_type::scoped_lock lock_(m_mutex);
63       m_log_file << mes << std::endl;
64       m_log_file.flush();
65     }   
66   private:
67     std::wofstream m_log_file;
68     //mutex_type m_mutex;
69   };
70
71   logger::logger() : m_impl(new logger::impl())
72   {
73   }
74   void logger::write(const boost::wformat & fmt)
75   {
76     m_impl->write(fmt);
77   };
78
79   void logger::write(const std::wstring & mes) 
80   {   
81     m_impl->write(mes);
82   }
83
84   void logger::write(const TCHAR * mes) 
85   {   
86     m_impl->write(mes);
87   }   
88
89   void logger::write(const std::wistream & st)
90   {
91     m_impl->write(st);
92   }
93
94   logger::~logger()
95   {
96
97   }
98
99   void debug_out(const char * file_name,const int line,boost::wformat& fmt)
100   {
101     OutputDebugString((boost::wformat(_T("%s(%d) %s \n")) % std::wstring(sf::code_converter<char,wchar_t>(file_name)) % line % fmt).str().c_str());
102   };
103
104   void debug_out(const char * file_name,const int line,const std::wstring& str)
105   {
106     OutputDebugString((boost::wformat(_T("%s(%d) %s \n")) % std::wstring(sf::code_converter<char,wchar_t>(file_name)) % line % str).str().c_str());
107   };
108
109   void debug_out(const char * file_name,const int line,const char* str)
110   {
111     OutputDebugString((boost::wformat(_T("%s(%d) %s \n")) % std::wstring(sf::code_converter<char,wchar_t>(file_name)) %  line % sf::code_converter<char,wchar_t>(str)).str().c_str());
112   }
113
114   void debug_outW(const char * file_name,const int line,const wchar_t* str)
115   {
116     OutputDebugString((boost::wformat(_T("%s(%d) %s \n")) % std::wstring(sf::code_converter<char,wchar_t>(file_name)) % line % str).str().c_str());
117   };
118
119 }