summaryrefslogtreecommitdiff
path: root/protocols/Quotes/src/Log.cpp
blob: d692763bad0da4844ec2b3dd9f8573ab194c0f2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "StdAfx.h"
#include "Log.h"
#include "LightMutex.h"
#include "EconomicRateInfo.h"
#include "CreateFilePath.h"

namespace
{
	CLightMutex g_Mutex;

	tstring get_log_file_name()
	{
		return CreateFilePath(_T("Quotes.log"));
	}

	bool is_log_enabled()
	{
#ifdef _DEBUG
		return true;
#else
		return (1 == DBGetContactSettingByte(NULL,QUOTES_PROTOCOL_NAME,DB_STR_ENABLE_LOG,false));
#endif
	}

	void do_log(const tstring& rsFileName,ESeverity nSeverity,const tstring& rsMsg)
	{
		CGuard<CLightMutex> guard(g_Mutex);
		tofstream file(rsFileName.c_str(),std::ios::ate|std::ios::app);
		if(file.good())
		{
			TCHAR szTime[20];
// 			TCHAR sz[10000+1];
			_tstrtime_s(szTime);
			file << szTime << _T(" ================================>\n") << rsMsg << _T("\n\n");
			
// 			size_t cBytes = rsMsg.size();
// 			const TCHAR* p = rsMsg.c_str();
// 			for(size_t c = 0;c < cBytes;c += 10000,p+=10000)
// 			{
// 				_tcsncpy_s(sz,p,10000);
// 				file << sz;
// 			}
// 			
// 			file << "\n\n";
		}
	}
}

void LogIt(ESeverity nSeverity,const tstring& rsMsg)
{
	if(is_log_enabled())
	{
		tstring sFileName = get_log_file_name();
		do_log(sFileName,nSeverity,rsMsg);
	}
}