~stomato463/+junk/nvdajp

« back to all changes in this revision

Viewing changes to nvdaHelper/remote/log.h

  • Committer: Masataka Shinke
  • Date: 2011-10-25 12:35:26 UTC
  • mfrom: (4185 jpmain)
  • mto: This revision was merged to the branch mainline in revision 4211.
  • Revision ID: mshinke@users.sourceforge.jp-20111025123526-ze527a2rl3z0g2ky
lp:~nishimotz/nvdajp/main : 4185 をマージ

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
This file is a part of the NVDA project.
 
3
URL: http://www.nvda-project.org/
 
4
Copyright 2006-2010 NVDA contributers.
 
5
    This program is free software: you can redistribute it and/or modify
 
6
    it under the terms of the GNU General Public License version 2.0, as published by
 
7
    the Free Software Foundation.
 
8
    This program is distributed in the hope that it will be useful,
 
9
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
11
This license can be found at:
 
12
http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 
13
*/
 
14
 
1
15
#ifndef NVDAHELPER_LOG_H
2
16
#define NVDAHELPER_LOG_H
3
17
 
4
18
#include <string>
5
19
#include <sstream>
6
 
 
7
 
#define __STR2WSTR(x) L##x
8
 
#define _STR2WSTR(x) __STR2WSTR(x)
9
 
 
10
 
#define _LOG_MSG(level,message) {\
11
 
        std::wostringstream* s = new std::wostringstream;\
12
 
        (*s)<<message;\
13
 
        nvdaControllerInternal_logMessage(GetCurrentProcessId(),GetCurrentThreadId(),level,_STR2WSTR(__FILE__),_STR2WSTR(__FUNCTION__),__LINE__,s->str().c_str());\
14
 
        delete s;\
15
 
}
 
20
#include <common/lock.h>
 
21
 
 
22
#define nhAssert _ASSERTE
 
23
 
 
24
void logMessage(int level, const wchar_t* msg);
 
25
 
 
26
int NVDALogCrtReportHook(int reportType, const wchar_t* msg, int* returnVal);
16
27
 
17
28
#define loglevel_none 60
18
 
#define loglevel_critical 50
 
29
#define LOGLEVEL_CRITICAL 50
19
30
#define LOGLEVEL_ERROR 40
20
31
#define LOGLEVEL_WARNING 30
21
32
#define LOGLEVEL_INFO 20
22
33
#define LOGLEVEL_DEBUGWARNING 15
23
34
#define LOGLEVEL_DEBUG 10
24
35
 
 
36
#define __STR2WSTR(x) L##x
 
37
#define _STR2WSTR(x) __STR2WSTR(x)
 
38
 
 
39
static std::wostringstream _logStringStream;
 
40
static LockableObject _logLock;
 
41
 
 
42
#define _LOG_MSG_MACRO(level,message) {\
 
43
        _logLock.acquire();\
 
44
        _logStringStream.str(L"");\
 
45
        _logStringStream<<L"Thread "<<GetCurrentThreadId()<<L", "<<_STR2WSTR(__FILE__)<<L", "<<_STR2WSTR(__FUNCTION__)<<L", "<<__LINE__<<L":"<<std::endl<<message<<std::endl;\
 
46
        logMessage(level,_logStringStream.str().c_str());\
 
47
        _logLock.release();\
 
48
}
 
49
 
25
50
#ifndef LOGLEVEL
26
51
#define LOGLEVEL LOGLEVEL_NONE
27
52
#endif
28
53
 
29
54
#if LOGLEVEL <= LOGLEVEL_CRITICAL
30
 
#define LOG_CRITICAL(message) _LOG_MSG(LOGLEVEL_CRITICAL,message)
 
55
#define LOG_CRITICAL(message) _LOG_MSG_MACRO(LOGLEVEL_CRITICAL,message)
31
56
 #else
32
57
#define LOG_CRITICAL(message)
33
58
#endif
34
59
 
35
60
#if LOGLEVEL <= LOGLEVEL_ERROR
36
 
#define LOG_ERROR(message) _LOG_MSG(LOGLEVEL_ERROR,message)
 
61
#define LOG_ERROR(message) _LOG_MSG_MACRO(LOGLEVEL_ERROR,message)
37
62
 #else
38
63
#define LOG_ERROR(message)
39
64
#endif
40
65
 
41
66
#if LOGLEVEL <= LOGLEVEL_WARNING
42
 
#define LOG_WARNING(message) _LOG_MSG(LOGLEVEL_WARNING,message)
 
67
#define LOG_WARNING(message) _LOG_MSG_MACRO(LOGLEVEL_WARNING,message)
43
68
 #else
44
69
#define LOG_WARNING(message)
45
70
#endif
46
71
 
47
72
#if LOGLEVEL <= LOGLEVEL_INFO
48
 
#define LOG_INFO(message) _LOG_MSG(LOGLEVEL_INFO,message)
 
73
#define LOG_INFO(message) _LOG_MSG_MACRO(LOGLEVEL_INFO,message)
49
74
 #else
50
75
#define LOG_INFO(message)
51
76
#endif
52
77
 
53
78
#if LOGLEVEL <= LOGLEVEL_DEBUGWARNING
54
 
#define LOG_DEBUGWARNING(message) _LOG_MSG(LOGLEVEL_DEBUGWARNING,message)
 
79
#define LOG_DEBUGWARNING(message) _LOG_MSG_MACRO(LOGLEVEL_DEBUGWARNING,message)
55
80
 #else
56
81
#define LOG_DEBUGWARNING(message)
57
82
#endif
58
83
 
59
84
#if LOGLEVEL <= LOGLEVEL_DEBUG
60
 
#define LOG_DEBUG(message) _LOG_MSG(LOGLEVEL_DEBUG,message)
 
85
#define LOG_DEBUG(message) _LOG_MSG_MACRO(LOGLEVEL_DEBUG,message)
61
86
 #else
62
87
#define LOG_DEBUG(message)
63
88
#endif