├── README.md
├── DumpHelper.h
├── FileHelper.h
├── LogHelper.h
├── TTSHelper.h
├── TimeHelper.h
├── MonitorHelper.h
├── StringHelper.h
├── SystemHelper.h
├── demo
├── demo
│ ├── main.cpp
│ ├── glog
│ │ ├── libglog.lib
│ │ ├── log_severity.h
│ │ ├── vlog_is_on.h
│ │ ├── stl_logging.h
│ │ ├── raw_logging.h
│ │ └── logging.h
│ ├── demo.vcxproj.filters
│ ├── demo.vcxproj
│ └── hashtool
│ │ └── hi_md5.h
├── Release
│ ├── demo.exe
│ └── libglog.dll
└── demo.sln
├── glog
├── libglog.lib
├── log_severity.h
├── vlog_is_on.h
├── stl_logging.h
├── raw_logging.h
└── logging.h
├── doc
└── html
│ └── win32_cplusplus_code.chm
└── hashtool
└── hi_md5.h
/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lossed1990/win32_cplusplus_code/HEAD/README.md
--------------------------------------------------------------------------------
/DumpHelper.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lossed1990/win32_cplusplus_code/HEAD/DumpHelper.h
--------------------------------------------------------------------------------
/FileHelper.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lossed1990/win32_cplusplus_code/HEAD/FileHelper.h
--------------------------------------------------------------------------------
/LogHelper.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lossed1990/win32_cplusplus_code/HEAD/LogHelper.h
--------------------------------------------------------------------------------
/TTSHelper.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lossed1990/win32_cplusplus_code/HEAD/TTSHelper.h
--------------------------------------------------------------------------------
/TimeHelper.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lossed1990/win32_cplusplus_code/HEAD/TimeHelper.h
--------------------------------------------------------------------------------
/MonitorHelper.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lossed1990/win32_cplusplus_code/HEAD/MonitorHelper.h
--------------------------------------------------------------------------------
/StringHelper.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lossed1990/win32_cplusplus_code/HEAD/StringHelper.h
--------------------------------------------------------------------------------
/SystemHelper.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lossed1990/win32_cplusplus_code/HEAD/SystemHelper.h
--------------------------------------------------------------------------------
/demo/demo/main.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lossed1990/win32_cplusplus_code/HEAD/demo/demo/main.cpp
--------------------------------------------------------------------------------
/glog/libglog.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lossed1990/win32_cplusplus_code/HEAD/glog/libglog.lib
--------------------------------------------------------------------------------
/demo/Release/demo.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lossed1990/win32_cplusplus_code/HEAD/demo/Release/demo.exe
--------------------------------------------------------------------------------
/demo/Release/libglog.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lossed1990/win32_cplusplus_code/HEAD/demo/Release/libglog.dll
--------------------------------------------------------------------------------
/demo/demo/glog/libglog.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lossed1990/win32_cplusplus_code/HEAD/demo/demo/glog/libglog.lib
--------------------------------------------------------------------------------
/doc/html/win32_cplusplus_code.chm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lossed1990/win32_cplusplus_code/HEAD/doc/html/win32_cplusplus_code.chm
--------------------------------------------------------------------------------
/demo/demo.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.40629.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "demo", "demo\demo.vcxproj", "{657C1495-2063-4E67-909A-A9E0B129949E}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Win32 = Debug|Win32
11 | Release|Win32 = Release|Win32
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {657C1495-2063-4E67-909A-A9E0B129949E}.Debug|Win32.ActiveCfg = Debug|Win32
15 | {657C1495-2063-4E67-909A-A9E0B129949E}.Debug|Win32.Build.0 = Debug|Win32
16 | {657C1495-2063-4E67-909A-A9E0B129949E}.Release|Win32.ActiveCfg = Release|Win32
17 | {657C1495-2063-4E67-909A-A9E0B129949E}.Release|Win32.Build.0 = Release|Win32
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/demo/demo/demo.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
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 |
--------------------------------------------------------------------------------
/glog/log_severity.h:
--------------------------------------------------------------------------------
1 | // This file is automatically generated from src/glog/log_severity.h
2 | // using src/windows/preprocess.sh.
3 | // DO NOT EDIT!
4 |
5 | // Copyright (c) 2007, Google Inc.
6 | // All rights reserved.
7 | //
8 | // Redistribution and use in source and binary forms, with or without
9 | // modification, are permitted provided that the following conditions are
10 | // met:
11 | //
12 | // * Redistributions of source code must retain the above copyright
13 | // notice, this list of conditions and the following disclaimer.
14 | // * Redistributions in binary form must reproduce the above
15 | // copyright notice, this list of conditions and the following disclaimer
16 | // in the documentation and/or other materials provided with the
17 | // distribution.
18 | // * Neither the name of Google Inc. nor the names of its
19 | // contributors may be used to endorse or promote products derived from
20 | // this software without specific prior written permission.
21 | //
22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 | #ifndef BASE_LOG_SEVERITY_H__
35 | #define BASE_LOG_SEVERITY_H__
36 |
37 | // Annoying stuff for windows -- makes sure clients can import these functions
38 | #ifndef GOOGLE_GLOG_DLL_DECL
39 | # if defined(_WIN32) && !defined(__CYGWIN__)
40 | # define GOOGLE_GLOG_DLL_DECL __declspec(dllimport)
41 | # else
42 | # define GOOGLE_GLOG_DLL_DECL
43 | # endif
44 | #endif
45 |
46 | // Variables of type LogSeverity are widely taken to lie in the range
47 | // [0, NUM_SEVERITIES-1]. Be careful to preserve this assumption if
48 | // you ever need to change their values or add a new severity.
49 | typedef int LogSeverity;
50 |
51 | const int GLOG_INFO = 0, GLOG_WARNING = 1, GLOG_ERROR = 2, GLOG_FATAL = 3,
52 | NUM_SEVERITIES = 4;
53 | #ifndef GLOG_NO_ABBREVIATED_SEVERITIES
54 | # ifdef ERROR
55 | # error ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
56 | # endif
57 | const int INFO = GLOG_INFO, WARNING = GLOG_WARNING,
58 | ERROR = GLOG_ERROR, FATAL = GLOG_FATAL;
59 | #endif
60 |
61 | // DFATAL is FATAL in debug mode, ERROR in normal mode
62 | #ifdef NDEBUG
63 | #define DFATAL_LEVEL ERROR
64 | #else
65 | #define DFATAL_LEVEL FATAL
66 | #endif
67 |
68 | extern GOOGLE_GLOG_DLL_DECL const char* const LogSeverityNames[NUM_SEVERITIES];
69 |
70 | // NDEBUG usage helpers related to (RAW_)DCHECK:
71 | //
72 | // DEBUG_MODE is for small !NDEBUG uses like
73 | // if (DEBUG_MODE) foo.CheckThatFoo();
74 | // instead of substantially more verbose
75 | // #ifndef NDEBUG
76 | // foo.CheckThatFoo();
77 | // #endif
78 | //
79 | // IF_DEBUG_MODE is for small !NDEBUG uses like
80 | // IF_DEBUG_MODE( string error; )
81 | // DCHECK(Foo(&error)) << error;
82 | // instead of substantially more verbose
83 | // #ifndef NDEBUG
84 | // string error;
85 | // DCHECK(Foo(&error)) << error;
86 | // #endif
87 | //
88 | #ifdef NDEBUG
89 | enum { DEBUG_MODE = 0 };
90 | #define IF_DEBUG_MODE(x)
91 | #else
92 | enum { DEBUG_MODE = 1 };
93 | #define IF_DEBUG_MODE(x) x
94 | #endif
95 |
96 | #endif // BASE_LOG_SEVERITY_H__
97 |
--------------------------------------------------------------------------------
/demo/demo/glog/log_severity.h:
--------------------------------------------------------------------------------
1 | // This file is automatically generated from src/glog/log_severity.h
2 | // using src/windows/preprocess.sh.
3 | // DO NOT EDIT!
4 |
5 | // Copyright (c) 2007, Google Inc.
6 | // All rights reserved.
7 | //
8 | // Redistribution and use in source and binary forms, with or without
9 | // modification, are permitted provided that the following conditions are
10 | // met:
11 | //
12 | // * Redistributions of source code must retain the above copyright
13 | // notice, this list of conditions and the following disclaimer.
14 | // * Redistributions in binary form must reproduce the above
15 | // copyright notice, this list of conditions and the following disclaimer
16 | // in the documentation and/or other materials provided with the
17 | // distribution.
18 | // * Neither the name of Google Inc. nor the names of its
19 | // contributors may be used to endorse or promote products derived from
20 | // this software without specific prior written permission.
21 | //
22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 | #ifndef BASE_LOG_SEVERITY_H__
35 | #define BASE_LOG_SEVERITY_H__
36 |
37 | // Annoying stuff for windows -- makes sure clients can import these functions
38 | #ifndef GOOGLE_GLOG_DLL_DECL
39 | # if defined(_WIN32) && !defined(__CYGWIN__)
40 | # define GOOGLE_GLOG_DLL_DECL __declspec(dllimport)
41 | # else
42 | # define GOOGLE_GLOG_DLL_DECL
43 | # endif
44 | #endif
45 |
46 | // Variables of type LogSeverity are widely taken to lie in the range
47 | // [0, NUM_SEVERITIES-1]. Be careful to preserve this assumption if
48 | // you ever need to change their values or add a new severity.
49 | typedef int LogSeverity;
50 |
51 | const int GLOG_INFO = 0, GLOG_WARNING = 1, GLOG_ERROR = 2, GLOG_FATAL = 3,
52 | NUM_SEVERITIES = 4;
53 | #ifndef GLOG_NO_ABBREVIATED_SEVERITIES
54 | # ifdef ERROR
55 | # error ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
56 | # endif
57 | const int INFO = GLOG_INFO, WARNING = GLOG_WARNING,
58 | ERROR = GLOG_ERROR, FATAL = GLOG_FATAL;
59 | #endif
60 |
61 | // DFATAL is FATAL in debug mode, ERROR in normal mode
62 | #ifdef NDEBUG
63 | #define DFATAL_LEVEL ERROR
64 | #else
65 | #define DFATAL_LEVEL FATAL
66 | #endif
67 |
68 | extern GOOGLE_GLOG_DLL_DECL const char* const LogSeverityNames[NUM_SEVERITIES];
69 |
70 | // NDEBUG usage helpers related to (RAW_)DCHECK:
71 | //
72 | // DEBUG_MODE is for small !NDEBUG uses like
73 | // if (DEBUG_MODE) foo.CheckThatFoo();
74 | // instead of substantially more verbose
75 | // #ifndef NDEBUG
76 | // foo.CheckThatFoo();
77 | // #endif
78 | //
79 | // IF_DEBUG_MODE is for small !NDEBUG uses like
80 | // IF_DEBUG_MODE( string error; )
81 | // DCHECK(Foo(&error)) << error;
82 | // instead of substantially more verbose
83 | // #ifndef NDEBUG
84 | // string error;
85 | // DCHECK(Foo(&error)) << error;
86 | // #endif
87 | //
88 | #ifdef NDEBUG
89 | enum { DEBUG_MODE = 0 };
90 | #define IF_DEBUG_MODE(x)
91 | #else
92 | enum { DEBUG_MODE = 1 };
93 | #define IF_DEBUG_MODE(x) x
94 | #endif
95 |
96 | #endif // BASE_LOG_SEVERITY_H__
97 |
--------------------------------------------------------------------------------
/demo/demo/demo.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | {657C1495-2063-4E67-909A-A9E0B129949E}
15 | Win32Proj
16 | demo
17 |
18 |
19 |
20 | Application
21 | true
22 | v120
23 | MultiByte
24 |
25 |
26 | Application
27 | false
28 | v120
29 | true
30 | MultiByte
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 | true
44 |
45 |
46 | false
47 |
48 |
49 |
50 |
51 |
52 | Level3
53 | Disabled
54 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
55 | true
56 |
57 |
58 | Console
59 | true
60 |
61 |
62 |
63 |
64 | Level3
65 |
66 |
67 | MaxSpeed
68 | true
69 | true
70 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
71 | true
72 | MultiThreadedDLL
73 |
74 |
75 | Console
76 | true
77 | true
78 | true
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
--------------------------------------------------------------------------------
/glog/vlog_is_on.h:
--------------------------------------------------------------------------------
1 | // This file is automatically generated from src/glog/vlog_is_on.h.in
2 | // using src/windows/preprocess.sh.
3 | // DO NOT EDIT!
4 |
5 | // Copyright (c) 1999, 2007, Google Inc.
6 | // All rights reserved.
7 | //
8 | // Redistribution and use in source and binary forms, with or without
9 | // modification, are permitted provided that the following conditions are
10 | // met:
11 | //
12 | // * Redistributions of source code must retain the above copyright
13 | // notice, this list of conditions and the following disclaimer.
14 | // * Redistributions in binary form must reproduce the above
15 | // copyright notice, this list of conditions and the following disclaimer
16 | // in the documentation and/or other materials provided with the
17 | // distribution.
18 | // * Neither the name of Google Inc. nor the names of its
19 | // contributors may be used to endorse or promote products derived from
20 | // this software without specific prior written permission.
21 | //
22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 | //
34 | // Author: Ray Sidney and many others
35 | //
36 | // Defines the VLOG_IS_ON macro that controls the variable-verbosity
37 | // conditional logging.
38 | //
39 | // It's used by VLOG and VLOG_IF in logging.h
40 | // and by RAW_VLOG in raw_logging.h to trigger the logging.
41 | //
42 | // It can also be used directly e.g. like this:
43 | // if (VLOG_IS_ON(2)) {
44 | // // do some logging preparation and logging
45 | // // that can't be accomplished e.g. via just VLOG(2) << ...;
46 | // }
47 | //
48 | // The truth value that VLOG_IS_ON(level) returns is determined by
49 | // the three verbosity level flags:
50 | // --v= Gives the default maximal active V-logging level;
51 | // 0 is the default.
52 | // Normally positive values are used for V-logging levels.
53 | // --vmodule= Gives the per-module maximal V-logging levels to override
54 | // the value given by --v.
55 | // E.g. "my_module=2,foo*=3" would change the logging level
56 | // for all code in source files "my_module.*" and "foo*.*"
57 | // ("-inl" suffixes are also disregarded for this matching).
58 | //
59 | // SetVLOGLevel helper function is provided to do limited dynamic control over
60 | // V-logging by overriding the per-module settings given via --vmodule flag.
61 | //
62 | // CAVEAT: --vmodule functionality is not available in non gcc compilers.
63 | //
64 |
65 | #ifndef BASE_VLOG_IS_ON_H_
66 | #define BASE_VLOG_IS_ON_H_
67 |
68 | #include "glog/log_severity.h"
69 |
70 | // Annoying stuff for windows -- makes sure clients can import these functions
71 | #ifndef GOOGLE_GLOG_DLL_DECL
72 | # if defined(_WIN32) && !defined(__CYGWIN__)
73 | # define GOOGLE_GLOG_DLL_DECL __declspec(dllimport)
74 | # else
75 | # define GOOGLE_GLOG_DLL_DECL
76 | # endif
77 | #endif
78 |
79 | #if defined(__GNUC__)
80 | // We emit an anonymous static int* variable at every VLOG_IS_ON(n) site.
81 | // (Normally) the first time every VLOG_IS_ON(n) site is hit,
82 | // we determine what variable will dynamically control logging at this site:
83 | // it's either FLAGS_v or an appropriate internal variable
84 | // matching the current source file that represents results of
85 | // parsing of --vmodule flag and/or SetVLOGLevel calls.
86 | #define VLOG_IS_ON(verboselevel) \
87 | __extension__ \
88 | ({ static google::int32* vlocal__ = &google::kLogSiteUninitialized; \
89 | google::int32 verbose_level__ = (verboselevel); \
90 | (*vlocal__ >= verbose_level__) && \
91 | ((vlocal__ != &google::kLogSiteUninitialized) || \
92 | (google::InitVLOG3__(&vlocal__, &FLAGS_v, \
93 | __FILE__, verbose_level__))); })
94 | #else
95 | // GNU extensions not available, so we do not support --vmodule.
96 | // Dynamic value of FLAGS_v always controls the logging level.
97 | #define VLOG_IS_ON(verboselevel) (FLAGS_v >= (verboselevel))
98 | #endif
99 |
100 | // Set VLOG(_IS_ON) level for module_pattern to log_level.
101 | // This lets us dynamically control what is normally set by the --vmodule flag.
102 | // Returns the level that previously applied to module_pattern.
103 | // NOTE: To change the log level for VLOG(_IS_ON) sites
104 | // that have already executed after/during InitGoogleLogging,
105 | // one needs to supply the exact --vmodule pattern that applied to them.
106 | // (If no --vmodule pattern applied to them
107 | // the value of FLAGS_v will continue to control them.)
108 | extern GOOGLE_GLOG_DLL_DECL int SetVLOGLevel(const char* module_pattern,
109 | int log_level);
110 |
111 | // Various declarations needed for VLOG_IS_ON above: =========================
112 |
113 | // Special value used to indicate that a VLOG_IS_ON site has not been
114 | // initialized. We make this a large value, so the common-case check
115 | // of "*vlocal__ >= verbose_level__" in VLOG_IS_ON definition
116 | // passes in such cases and InitVLOG3__ is then triggered.
117 | extern google::int32 kLogSiteUninitialized;
118 |
119 | // Helper routine which determines the logging info for a particalur VLOG site.
120 | // site_flag is the address of the site-local pointer to the controlling
121 | // verbosity level
122 | // site_default is the default to use for *site_flag
123 | // fname is the current source file name
124 | // verbose_level is the argument to VLOG_IS_ON
125 | // We will return the return value for VLOG_IS_ON
126 | // and if possible set *site_flag appropriately.
127 | extern GOOGLE_GLOG_DLL_DECL bool InitVLOG3__(
128 | google::int32** site_flag,
129 | google::int32* site_default,
130 | const char* fname,
131 | google::int32 verbose_level);
132 |
133 | #endif // BASE_VLOG_IS_ON_H_
134 |
--------------------------------------------------------------------------------
/demo/demo/glog/vlog_is_on.h:
--------------------------------------------------------------------------------
1 | // This file is automatically generated from src/glog/vlog_is_on.h.in
2 | // using src/windows/preprocess.sh.
3 | // DO NOT EDIT!
4 |
5 | // Copyright (c) 1999, 2007, Google Inc.
6 | // All rights reserved.
7 | //
8 | // Redistribution and use in source and binary forms, with or without
9 | // modification, are permitted provided that the following conditions are
10 | // met:
11 | //
12 | // * Redistributions of source code must retain the above copyright
13 | // notice, this list of conditions and the following disclaimer.
14 | // * Redistributions in binary form must reproduce the above
15 | // copyright notice, this list of conditions and the following disclaimer
16 | // in the documentation and/or other materials provided with the
17 | // distribution.
18 | // * Neither the name of Google Inc. nor the names of its
19 | // contributors may be used to endorse or promote products derived from
20 | // this software without specific prior written permission.
21 | //
22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 | //
34 | // Author: Ray Sidney and many others
35 | //
36 | // Defines the VLOG_IS_ON macro that controls the variable-verbosity
37 | // conditional logging.
38 | //
39 | // It's used by VLOG and VLOG_IF in logging.h
40 | // and by RAW_VLOG in raw_logging.h to trigger the logging.
41 | //
42 | // It can also be used directly e.g. like this:
43 | // if (VLOG_IS_ON(2)) {
44 | // // do some logging preparation and logging
45 | // // that can't be accomplished e.g. via just VLOG(2) << ...;
46 | // }
47 | //
48 | // The truth value that VLOG_IS_ON(level) returns is determined by
49 | // the three verbosity level flags:
50 | // --v= Gives the default maximal active V-logging level;
51 | // 0 is the default.
52 | // Normally positive values are used for V-logging levels.
53 | // --vmodule= Gives the per-module maximal V-logging levels to override
54 | // the value given by --v.
55 | // E.g. "my_module=2,foo*=3" would change the logging level
56 | // for all code in source files "my_module.*" and "foo*.*"
57 | // ("-inl" suffixes are also disregarded for this matching).
58 | //
59 | // SetVLOGLevel helper function is provided to do limited dynamic control over
60 | // V-logging by overriding the per-module settings given via --vmodule flag.
61 | //
62 | // CAVEAT: --vmodule functionality is not available in non gcc compilers.
63 | //
64 |
65 | #ifndef BASE_VLOG_IS_ON_H_
66 | #define BASE_VLOG_IS_ON_H_
67 |
68 | #include "glog/log_severity.h"
69 |
70 | // Annoying stuff for windows -- makes sure clients can import these functions
71 | #ifndef GOOGLE_GLOG_DLL_DECL
72 | # if defined(_WIN32) && !defined(__CYGWIN__)
73 | # define GOOGLE_GLOG_DLL_DECL __declspec(dllimport)
74 | # else
75 | # define GOOGLE_GLOG_DLL_DECL
76 | # endif
77 | #endif
78 |
79 | #if defined(__GNUC__)
80 | // We emit an anonymous static int* variable at every VLOG_IS_ON(n) site.
81 | // (Normally) the first time every VLOG_IS_ON(n) site is hit,
82 | // we determine what variable will dynamically control logging at this site:
83 | // it's either FLAGS_v or an appropriate internal variable
84 | // matching the current source file that represents results of
85 | // parsing of --vmodule flag and/or SetVLOGLevel calls.
86 | #define VLOG_IS_ON(verboselevel) \
87 | __extension__ \
88 | ({ static google::int32* vlocal__ = &google::kLogSiteUninitialized; \
89 | google::int32 verbose_level__ = (verboselevel); \
90 | (*vlocal__ >= verbose_level__) && \
91 | ((vlocal__ != &google::kLogSiteUninitialized) || \
92 | (google::InitVLOG3__(&vlocal__, &FLAGS_v, \
93 | __FILE__, verbose_level__))); })
94 | #else
95 | // GNU extensions not available, so we do not support --vmodule.
96 | // Dynamic value of FLAGS_v always controls the logging level.
97 | #define VLOG_IS_ON(verboselevel) (FLAGS_v >= (verboselevel))
98 | #endif
99 |
100 | // Set VLOG(_IS_ON) level for module_pattern to log_level.
101 | // This lets us dynamically control what is normally set by the --vmodule flag.
102 | // Returns the level that previously applied to module_pattern.
103 | // NOTE: To change the log level for VLOG(_IS_ON) sites
104 | // that have already executed after/during InitGoogleLogging,
105 | // one needs to supply the exact --vmodule pattern that applied to them.
106 | // (If no --vmodule pattern applied to them
107 | // the value of FLAGS_v will continue to control them.)
108 | extern GOOGLE_GLOG_DLL_DECL int SetVLOGLevel(const char* module_pattern,
109 | int log_level);
110 |
111 | // Various declarations needed for VLOG_IS_ON above: =========================
112 |
113 | // Special value used to indicate that a VLOG_IS_ON site has not been
114 | // initialized. We make this a large value, so the common-case check
115 | // of "*vlocal__ >= verbose_level__" in VLOG_IS_ON definition
116 | // passes in such cases and InitVLOG3__ is then triggered.
117 | extern google::int32 kLogSiteUninitialized;
118 |
119 | // Helper routine which determines the logging info for a particalur VLOG site.
120 | // site_flag is the address of the site-local pointer to the controlling
121 | // verbosity level
122 | // site_default is the default to use for *site_flag
123 | // fname is the current source file name
124 | // verbose_level is the argument to VLOG_IS_ON
125 | // We will return the return value for VLOG_IS_ON
126 | // and if possible set *site_flag appropriately.
127 | extern GOOGLE_GLOG_DLL_DECL bool InitVLOG3__(
128 | google::int32** site_flag,
129 | google::int32* site_default,
130 | const char* fname,
131 | google::int32 verbose_level);
132 |
133 | #endif // BASE_VLOG_IS_ON_H_
134 |
--------------------------------------------------------------------------------
/glog/stl_logging.h:
--------------------------------------------------------------------------------
1 | // This file is automatically generated from src/glog/stl_logging.h.in
2 | // using src/windows/preprocess.sh.
3 | // DO NOT EDIT!
4 |
5 | // Copyright (c) 2003, Google Inc.
6 | // All rights reserved.
7 | //
8 | // Redistribution and use in source and binary forms, with or without
9 | // modification, are permitted provided that the following conditions are
10 | // met:
11 | //
12 | // * Redistributions of source code must retain the above copyright
13 | // notice, this list of conditions and the following disclaimer.
14 | // * Redistributions in binary form must reproduce the above
15 | // copyright notice, this list of conditions and the following disclaimer
16 | // in the documentation and/or other materials provided with the
17 | // distribution.
18 | // * Neither the name of Google Inc. nor the names of its
19 | // contributors may be used to endorse or promote products derived from
20 | // this software without specific prior written permission.
21 | //
22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 | //
34 | // Stream output operators for STL containers; to be used for logging *only*.
35 | // Inclusion of this file lets you do:
36 | //
37 | // list x;
38 | // LOG(INFO) << "data: " << x;
39 | // vector v1, v2;
40 | // CHECK_EQ(v1, v2);
41 |
42 | #ifndef UTIL_GTL_STL_LOGGING_INL_H_
43 | #define UTIL_GTL_STL_LOGGING_INL_H_
44 |
45 | #if !1
46 | # error We do not support stl_logging for this compiler
47 | #endif
48 |
49 | #include
50 | #include
51 | #include
52 | #include
53 | #include
54 | #include
55 | #include
56 |
57 | #ifdef __GNUC__
58 | # include
59 | # include
60 | # include
61 | #endif
62 |
63 | // Forward declare these two, and define them after all the container streams
64 | // operators so that we can recurse from pair -> container -> container -> pair
65 | // properly.
66 | template
67 | std::ostream& operator<<(std::ostream& out, const std::pair& p);
68 |
69 | namespace google {
70 |
71 | template
72 | void PrintSequence(std::ostream& out, Iter begin, Iter end);
73 |
74 | }
75 |
76 | #define OUTPUT_TWO_ARG_CONTAINER(Sequence) \
77 | template \
78 | inline std::ostream& operator<<(std::ostream& out, \
79 | const Sequence& seq) { \
80 | google::PrintSequence(out, seq.begin(), seq.end()); \
81 | return out; \
82 | }
83 |
84 | OUTPUT_TWO_ARG_CONTAINER(std::vector)
85 | OUTPUT_TWO_ARG_CONTAINER(std::deque)
86 | OUTPUT_TWO_ARG_CONTAINER(std::list)
87 | #ifdef __GNUC__
88 | OUTPUT_TWO_ARG_CONTAINER(__gnu_cxx::slist)
89 | #endif
90 |
91 | #undef OUTPUT_TWO_ARG_CONTAINER
92 |
93 | #define OUTPUT_THREE_ARG_CONTAINER(Sequence) \
94 | template \
95 | inline std::ostream& operator<<(std::ostream& out, \
96 | const Sequence& seq) { \
97 | google::PrintSequence(out, seq.begin(), seq.end()); \
98 | return out; \
99 | }
100 |
101 | OUTPUT_THREE_ARG_CONTAINER(std::set)
102 | OUTPUT_THREE_ARG_CONTAINER(std::multiset)
103 |
104 | #undef OUTPUT_THREE_ARG_CONTAINER
105 |
106 | #define OUTPUT_FOUR_ARG_CONTAINER(Sequence) \
107 | template \
108 | inline std::ostream& operator<<(std::ostream& out, \
109 | const Sequence& seq) { \
110 | google::PrintSequence(out, seq.begin(), seq.end()); \
111 | return out; \
112 | }
113 |
114 | OUTPUT_FOUR_ARG_CONTAINER(std::map)
115 | OUTPUT_FOUR_ARG_CONTAINER(std::multimap)
116 | #ifdef __GNUC__
117 | OUTPUT_FOUR_ARG_CONTAINER(__gnu_cxx::hash_set)
118 | OUTPUT_FOUR_ARG_CONTAINER(__gnu_cxx::hash_multiset)
119 | #endif
120 |
121 | #undef OUTPUT_FOUR_ARG_CONTAINER
122 |
123 | #define OUTPUT_FIVE_ARG_CONTAINER(Sequence) \
124 | template \
125 | inline std::ostream& operator<<(std::ostream& out, \
126 | const Sequence& seq) { \
127 | google::PrintSequence(out, seq.begin(), seq.end()); \
128 | return out; \
129 | }
130 |
131 | #ifdef __GNUC__
132 | OUTPUT_FIVE_ARG_CONTAINER(__gnu_cxx::hash_map)
133 | OUTPUT_FIVE_ARG_CONTAINER(__gnu_cxx::hash_multimap)
134 | #endif
135 |
136 | #undef OUTPUT_FIVE_ARG_CONTAINER
137 |
138 | template
139 | inline std::ostream& operator<<(std::ostream& out,
140 | const std::pair& p) {
141 | out << '(' << p.first << ", " << p.second << ')';
142 | return out;
143 | }
144 |
145 | namespace google {
146 |
147 | template
148 | inline void PrintSequence(std::ostream& out, Iter begin, Iter end) {
149 | // Output at most 100 elements -- appropriate if used for logging.
150 | for (int i = 0; begin != end && i < 100; ++i, ++begin) {
151 | if (i > 0) out << ' ';
152 | out << *begin;
153 | }
154 | if (begin != end) {
155 | out << " ...";
156 | }
157 | }
158 |
159 | }
160 |
161 | // Note that this is technically undefined behavior! We are adding things into
162 | // the std namespace for a reason though -- we are providing new operations on
163 | // types which are themselves defined with this namespace. Without this, these
164 | // operator overloads cannot be found via ADL. If these definitions are not
165 | // found via ADL, they must be #included before they're used, which requires
166 | // this header to be included before apparently independent other headers.
167 | //
168 | // For example, base/logging.h defines various template functions to implement
169 | // CHECK_EQ(x, y) and stream x and y into the log in the event the check fails.
170 | // It does so via the function template MakeCheckOpValueString:
171 | // template
172 | // void MakeCheckOpValueString(strstream* ss, const T& v) {
173 | // (*ss) << v;
174 | // }
175 | // Because 'glog/logging.h' is included before 'glog/stl_logging.h',
176 | // subsequent CHECK_EQ(v1, v2) for vector<...> typed variable v1 and v2 can only
177 | // find these operator definitions via ADL.
178 | //
179 | // Even this solution has problems -- it may pull unintended operators into the
180 | // namespace as well, allowing them to also be found via ADL, and creating code
181 | // that only works with a particular order of includes. Long term, we need to
182 | // move all of the *definitions* into namespace std, bet we need to ensure no
183 | // one references them first. This lets us take that step. We cannot define them
184 | // in both because that would create ambiguous overloads when both are found.
185 | namespace std { using ::operator<<; }
186 |
187 | #endif // UTIL_GTL_STL_LOGGING_INL_H_
188 |
--------------------------------------------------------------------------------
/demo/demo/glog/stl_logging.h:
--------------------------------------------------------------------------------
1 | // This file is automatically generated from src/glog/stl_logging.h.in
2 | // using src/windows/preprocess.sh.
3 | // DO NOT EDIT!
4 |
5 | // Copyright (c) 2003, Google Inc.
6 | // All rights reserved.
7 | //
8 | // Redistribution and use in source and binary forms, with or without
9 | // modification, are permitted provided that the following conditions are
10 | // met:
11 | //
12 | // * Redistributions of source code must retain the above copyright
13 | // notice, this list of conditions and the following disclaimer.
14 | // * Redistributions in binary form must reproduce the above
15 | // copyright notice, this list of conditions and the following disclaimer
16 | // in the documentation and/or other materials provided with the
17 | // distribution.
18 | // * Neither the name of Google Inc. nor the names of its
19 | // contributors may be used to endorse or promote products derived from
20 | // this software without specific prior written permission.
21 | //
22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 | //
34 | // Stream output operators for STL containers; to be used for logging *only*.
35 | // Inclusion of this file lets you do:
36 | //
37 | // list x;
38 | // LOG(INFO) << "data: " << x;
39 | // vector v1, v2;
40 | // CHECK_EQ(v1, v2);
41 |
42 | #ifndef UTIL_GTL_STL_LOGGING_INL_H_
43 | #define UTIL_GTL_STL_LOGGING_INL_H_
44 |
45 | #if !1
46 | # error We do not support stl_logging for this compiler
47 | #endif
48 |
49 | #include
50 | #include
51 | #include
52 | #include
53 | #include
54 | #include
55 | #include
56 |
57 | #ifdef __GNUC__
58 | # include
59 | # include
60 | # include
61 | #endif
62 |
63 | // Forward declare these two, and define them after all the container streams
64 | // operators so that we can recurse from pair -> container -> container -> pair
65 | // properly.
66 | template
67 | std::ostream& operator<<(std::ostream& out, const std::pair& p);
68 |
69 | namespace google {
70 |
71 | template
72 | void PrintSequence(std::ostream& out, Iter begin, Iter end);
73 |
74 | }
75 |
76 | #define OUTPUT_TWO_ARG_CONTAINER(Sequence) \
77 | template \
78 | inline std::ostream& operator<<(std::ostream& out, \
79 | const Sequence& seq) { \
80 | google::PrintSequence(out, seq.begin(), seq.end()); \
81 | return out; \
82 | }
83 |
84 | OUTPUT_TWO_ARG_CONTAINER(std::vector)
85 | OUTPUT_TWO_ARG_CONTAINER(std::deque)
86 | OUTPUT_TWO_ARG_CONTAINER(std::list)
87 | #ifdef __GNUC__
88 | OUTPUT_TWO_ARG_CONTAINER(__gnu_cxx::slist)
89 | #endif
90 |
91 | #undef OUTPUT_TWO_ARG_CONTAINER
92 |
93 | #define OUTPUT_THREE_ARG_CONTAINER(Sequence) \
94 | template \
95 | inline std::ostream& operator<<(std::ostream& out, \
96 | const Sequence& seq) { \
97 | google::PrintSequence(out, seq.begin(), seq.end()); \
98 | return out; \
99 | }
100 |
101 | OUTPUT_THREE_ARG_CONTAINER(std::set)
102 | OUTPUT_THREE_ARG_CONTAINER(std::multiset)
103 |
104 | #undef OUTPUT_THREE_ARG_CONTAINER
105 |
106 | #define OUTPUT_FOUR_ARG_CONTAINER(Sequence) \
107 | template \
108 | inline std::ostream& operator<<(std::ostream& out, \
109 | const Sequence& seq) { \
110 | google::PrintSequence(out, seq.begin(), seq.end()); \
111 | return out; \
112 | }
113 |
114 | OUTPUT_FOUR_ARG_CONTAINER(std::map)
115 | OUTPUT_FOUR_ARG_CONTAINER(std::multimap)
116 | #ifdef __GNUC__
117 | OUTPUT_FOUR_ARG_CONTAINER(__gnu_cxx::hash_set)
118 | OUTPUT_FOUR_ARG_CONTAINER(__gnu_cxx::hash_multiset)
119 | #endif
120 |
121 | #undef OUTPUT_FOUR_ARG_CONTAINER
122 |
123 | #define OUTPUT_FIVE_ARG_CONTAINER(Sequence) \
124 | template \
125 | inline std::ostream& operator<<(std::ostream& out, \
126 | const Sequence& seq) { \
127 | google::PrintSequence(out, seq.begin(), seq.end()); \
128 | return out; \
129 | }
130 |
131 | #ifdef __GNUC__
132 | OUTPUT_FIVE_ARG_CONTAINER(__gnu_cxx::hash_map)
133 | OUTPUT_FIVE_ARG_CONTAINER(__gnu_cxx::hash_multimap)
134 | #endif
135 |
136 | #undef OUTPUT_FIVE_ARG_CONTAINER
137 |
138 | template
139 | inline std::ostream& operator<<(std::ostream& out,
140 | const std::pair& p) {
141 | out << '(' << p.first << ", " << p.second << ')';
142 | return out;
143 | }
144 |
145 | namespace google {
146 |
147 | template
148 | inline void PrintSequence(std::ostream& out, Iter begin, Iter end) {
149 | // Output at most 100 elements -- appropriate if used for logging.
150 | for (int i = 0; begin != end && i < 100; ++i, ++begin) {
151 | if (i > 0) out << ' ';
152 | out << *begin;
153 | }
154 | if (begin != end) {
155 | out << " ...";
156 | }
157 | }
158 |
159 | }
160 |
161 | // Note that this is technically undefined behavior! We are adding things into
162 | // the std namespace for a reason though -- we are providing new operations on
163 | // types which are themselves defined with this namespace. Without this, these
164 | // operator overloads cannot be found via ADL. If these definitions are not
165 | // found via ADL, they must be #included before they're used, which requires
166 | // this header to be included before apparently independent other headers.
167 | //
168 | // For example, base/logging.h defines various template functions to implement
169 | // CHECK_EQ(x, y) and stream x and y into the log in the event the check fails.
170 | // It does so via the function template MakeCheckOpValueString:
171 | // template
172 | // void MakeCheckOpValueString(strstream* ss, const T& v) {
173 | // (*ss) << v;
174 | // }
175 | // Because 'glog/logging.h' is included before 'glog/stl_logging.h',
176 | // subsequent CHECK_EQ(v1, v2) for vector<...> typed variable v1 and v2 can only
177 | // find these operator definitions via ADL.
178 | //
179 | // Even this solution has problems -- it may pull unintended operators into the
180 | // namespace as well, allowing them to also be found via ADL, and creating code
181 | // that only works with a particular order of includes. Long term, we need to
182 | // move all of the *definitions* into namespace std, bet we need to ensure no
183 | // one references them first. This lets us take that step. We cannot define them
184 | // in both because that would create ambiguous overloads when both are found.
185 | namespace std { using ::operator<<; }
186 |
187 | #endif // UTIL_GTL_STL_LOGGING_INL_H_
188 |
--------------------------------------------------------------------------------
/glog/raw_logging.h:
--------------------------------------------------------------------------------
1 | // This file is automatically generated from src/glog/raw_logging.h.in
2 | // using src/windows/preprocess.sh.
3 | // DO NOT EDIT!
4 |
5 | // Copyright (c) 2006, Google Inc.
6 | // All rights reserved.
7 | //
8 | // Redistribution and use in source and binary forms, with or without
9 | // modification, are permitted provided that the following conditions are
10 | // met:
11 | //
12 | // * Redistributions of source code must retain the above copyright
13 | // notice, this list of conditions and the following disclaimer.
14 | // * Redistributions in binary form must reproduce the above
15 | // copyright notice, this list of conditions and the following disclaimer
16 | // in the documentation and/or other materials provided with the
17 | // distribution.
18 | // * Neither the name of Google Inc. nor the names of its
19 | // contributors may be used to endorse or promote products derived from
20 | // this software without specific prior written permission.
21 | //
22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 | //
34 | // Author: Maxim Lifantsev
35 | //
36 | // Thread-safe logging routines that do not allocate any memory or
37 | // acquire any locks, and can therefore be used by low-level memory
38 | // allocation and synchronization code.
39 |
40 | #ifndef BASE_RAW_LOGGING_H_
41 | #define BASE_RAW_LOGGING_H_
42 |
43 | #include
44 |
45 | namespace google {
46 |
47 | #include "glog/log_severity.h"
48 | #include "glog/vlog_is_on.h"
49 |
50 | // Annoying stuff for windows -- makes sure clients can import these functions
51 | #ifndef GOOGLE_GLOG_DLL_DECL
52 | # if defined(_WIN32) && !defined(__CYGWIN__)
53 | # define GOOGLE_GLOG_DLL_DECL __declspec(dllimport)
54 | # else
55 | # define GOOGLE_GLOG_DLL_DECL
56 | # endif
57 | #endif
58 |
59 | // This is similar to LOG(severity) << format... and VLOG(level) << format..,
60 | // but
61 | // * it is to be used ONLY by low-level modules that can't use normal LOG()
62 | // * it is desiged to be a low-level logger that does not allocate any
63 | // memory and does not need any locks, hence:
64 | // * it logs straight and ONLY to STDERR w/o buffering
65 | // * it uses an explicit format and arguments list
66 | // * it will silently chop off really long message strings
67 | // Usage example:
68 | // RAW_LOG(ERROR, "Failed foo with %i: %s", status, error);
69 | // RAW_VLOG(3, "status is %i", status);
70 | // These will print an almost standard log lines like this to stderr only:
71 | // E0821 211317 file.cc:123] RAW: Failed foo with 22: bad_file
72 | // I0821 211317 file.cc:142] RAW: status is 20
73 | #define RAW_LOG(severity, ...) \
74 | do { \
75 | switch (google::GLOG_ ## severity) { \
76 | case 0: \
77 | RAW_LOG_INFO(__VA_ARGS__); \
78 | break; \
79 | case 1: \
80 | RAW_LOG_WARNING(__VA_ARGS__); \
81 | break; \
82 | case 2: \
83 | RAW_LOG_ERROR(__VA_ARGS__); \
84 | break; \
85 | case 3: \
86 | RAW_LOG_FATAL(__VA_ARGS__); \
87 | break; \
88 | default: \
89 | break; \
90 | } \
91 | } while (0)
92 |
93 | // The following STRIP_LOG testing is performed in the header file so that it's
94 | // possible to completely compile out the logging code and the log messages.
95 | #if STRIP_LOG == 0
96 | #define RAW_VLOG(verboselevel, ...) \
97 | do { \
98 | if (VLOG_IS_ON(verboselevel)) { \
99 | RAW_LOG_INFO(__VA_ARGS__); \
100 | } \
101 | } while (0)
102 | #else
103 | #define RAW_VLOG(verboselevel, ...) RawLogStub__(0, __VA_ARGS__)
104 | #endif // STRIP_LOG == 0
105 |
106 | #if STRIP_LOG == 0
107 | #define RAW_LOG_INFO(...) google::RawLog__(google::GLOG_INFO, \
108 | __FILE__, __LINE__, __VA_ARGS__)
109 | #else
110 | #define RAW_LOG_INFO(...) google::RawLogStub__(0, __VA_ARGS__)
111 | #endif // STRIP_LOG == 0
112 |
113 | #if STRIP_LOG <= 1
114 | #define RAW_LOG_WARNING(...) google::RawLog__(google::GLOG_WARNING, \
115 | __FILE__, __LINE__, __VA_ARGS__)
116 | #else
117 | #define RAW_LOG_WARNING(...) google::RawLogStub__(0, __VA_ARGS__)
118 | #endif // STRIP_LOG <= 1
119 |
120 | #if STRIP_LOG <= 2
121 | #define RAW_LOG_ERROR(...) google::RawLog__(google::GLOG_ERROR, \
122 | __FILE__, __LINE__, __VA_ARGS__)
123 | #else
124 | #define RAW_LOG_ERROR(...) google::RawLogStub__(0, __VA_ARGS__)
125 | #endif // STRIP_LOG <= 2
126 |
127 | #if STRIP_LOG <= 3
128 | #define RAW_LOG_FATAL(...) google::RawLog__(google::GLOG_FATAL, \
129 | __FILE__, __LINE__, __VA_ARGS__)
130 | #else
131 | #define RAW_LOG_FATAL(...) \
132 | do { \
133 | google::RawLogStub__(0, __VA_ARGS__); \
134 | exit(1); \
135 | } while (0)
136 | #endif // STRIP_LOG <= 3
137 |
138 | // Similar to CHECK(condition) << message,
139 | // but for low-level modules: we use only RAW_LOG that does not allocate memory.
140 | // We do not want to provide args list here to encourage this usage:
141 | // if (!cond) RAW_LOG(FATAL, "foo ...", hard_to_compute_args);
142 | // so that the args are not computed when not needed.
143 | #define RAW_CHECK(condition, message) \
144 | do { \
145 | if (!(condition)) { \
146 | RAW_LOG(FATAL, "Check %s failed: %s", #condition, message); \
147 | } \
148 | } while (0)
149 |
150 | // Debug versions of RAW_LOG and RAW_CHECK
151 | #ifndef NDEBUG
152 |
153 | #define RAW_DLOG(severity, ...) RAW_LOG(severity, __VA_ARGS__)
154 | #define RAW_DCHECK(condition, message) RAW_CHECK(condition, message)
155 |
156 | #else // NDEBUG
157 |
158 | #define RAW_DLOG(severity, ...) \
159 | while (false) \
160 | RAW_LOG(severity, __VA_ARGS__)
161 | #define RAW_DCHECK(condition, message) \
162 | while (false) \
163 | RAW_CHECK(condition, message)
164 |
165 | #endif // NDEBUG
166 |
167 | // Stub log function used to work around for unused variable warnings when
168 | // building with STRIP_LOG > 0.
169 | static inline void RawLogStub__(int /* ignored */, ...) {
170 | }
171 |
172 | // Helper function to implement RAW_LOG and RAW_VLOG
173 | // Logs format... at "severity" level, reporting it
174 | // as called from file:line.
175 | // This does not allocate memory or acquire locks.
176 | GOOGLE_GLOG_DLL_DECL void RawLog__(LogSeverity severity,
177 | const char* file,
178 | int line,
179 | const char* format, ...)
180 | ;
181 |
182 | // Hack to propagate time information into this module so that
183 | // this module does not have to directly call localtime_r(),
184 | // which could allocate memory.
185 | GOOGLE_GLOG_DLL_DECL void RawLog__SetLastTime(const struct tm& t, int usecs);
186 |
187 | }
188 |
189 | #endif // BASE_RAW_LOGGING_H_
190 |
--------------------------------------------------------------------------------
/demo/demo/glog/raw_logging.h:
--------------------------------------------------------------------------------
1 | // This file is automatically generated from src/glog/raw_logging.h.in
2 | // using src/windows/preprocess.sh.
3 | // DO NOT EDIT!
4 |
5 | // Copyright (c) 2006, Google Inc.
6 | // All rights reserved.
7 | //
8 | // Redistribution and use in source and binary forms, with or without
9 | // modification, are permitted provided that the following conditions are
10 | // met:
11 | //
12 | // * Redistributions of source code must retain the above copyright
13 | // notice, this list of conditions and the following disclaimer.
14 | // * Redistributions in binary form must reproduce the above
15 | // copyright notice, this list of conditions and the following disclaimer
16 | // in the documentation and/or other materials provided with the
17 | // distribution.
18 | // * Neither the name of Google Inc. nor the names of its
19 | // contributors may be used to endorse or promote products derived from
20 | // this software without specific prior written permission.
21 | //
22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 | //
34 | // Author: Maxim Lifantsev
35 | //
36 | // Thread-safe logging routines that do not allocate any memory or
37 | // acquire any locks, and can therefore be used by low-level memory
38 | // allocation and synchronization code.
39 |
40 | #ifndef BASE_RAW_LOGGING_H_
41 | #define BASE_RAW_LOGGING_H_
42 |
43 | #include
44 |
45 | namespace google {
46 |
47 | #include "glog/log_severity.h"
48 | #include "glog/vlog_is_on.h"
49 |
50 | // Annoying stuff for windows -- makes sure clients can import these functions
51 | #ifndef GOOGLE_GLOG_DLL_DECL
52 | # if defined(_WIN32) && !defined(__CYGWIN__)
53 | # define GOOGLE_GLOG_DLL_DECL __declspec(dllimport)
54 | # else
55 | # define GOOGLE_GLOG_DLL_DECL
56 | # endif
57 | #endif
58 |
59 | // This is similar to LOG(severity) << format... and VLOG(level) << format..,
60 | // but
61 | // * it is to be used ONLY by low-level modules that can't use normal LOG()
62 | // * it is desiged to be a low-level logger that does not allocate any
63 | // memory and does not need any locks, hence:
64 | // * it logs straight and ONLY to STDERR w/o buffering
65 | // * it uses an explicit format and arguments list
66 | // * it will silently chop off really long message strings
67 | // Usage example:
68 | // RAW_LOG(ERROR, "Failed foo with %i: %s", status, error);
69 | // RAW_VLOG(3, "status is %i", status);
70 | // These will print an almost standard log lines like this to stderr only:
71 | // E0821 211317 file.cc:123] RAW: Failed foo with 22: bad_file
72 | // I0821 211317 file.cc:142] RAW: status is 20
73 | #define RAW_LOG(severity, ...) \
74 | do { \
75 | switch (google::GLOG_ ## severity) { \
76 | case 0: \
77 | RAW_LOG_INFO(__VA_ARGS__); \
78 | break; \
79 | case 1: \
80 | RAW_LOG_WARNING(__VA_ARGS__); \
81 | break; \
82 | case 2: \
83 | RAW_LOG_ERROR(__VA_ARGS__); \
84 | break; \
85 | case 3: \
86 | RAW_LOG_FATAL(__VA_ARGS__); \
87 | break; \
88 | default: \
89 | break; \
90 | } \
91 | } while (0)
92 |
93 | // The following STRIP_LOG testing is performed in the header file so that it's
94 | // possible to completely compile out the logging code and the log messages.
95 | #if STRIP_LOG == 0
96 | #define RAW_VLOG(verboselevel, ...) \
97 | do { \
98 | if (VLOG_IS_ON(verboselevel)) { \
99 | RAW_LOG_INFO(__VA_ARGS__); \
100 | } \
101 | } while (0)
102 | #else
103 | #define RAW_VLOG(verboselevel, ...) RawLogStub__(0, __VA_ARGS__)
104 | #endif // STRIP_LOG == 0
105 |
106 | #if STRIP_LOG == 0
107 | #define RAW_LOG_INFO(...) google::RawLog__(google::GLOG_INFO, \
108 | __FILE__, __LINE__, __VA_ARGS__)
109 | #else
110 | #define RAW_LOG_INFO(...) google::RawLogStub__(0, __VA_ARGS__)
111 | #endif // STRIP_LOG == 0
112 |
113 | #if STRIP_LOG <= 1
114 | #define RAW_LOG_WARNING(...) google::RawLog__(google::GLOG_WARNING, \
115 | __FILE__, __LINE__, __VA_ARGS__)
116 | #else
117 | #define RAW_LOG_WARNING(...) google::RawLogStub__(0, __VA_ARGS__)
118 | #endif // STRIP_LOG <= 1
119 |
120 | #if STRIP_LOG <= 2
121 | #define RAW_LOG_ERROR(...) google::RawLog__(google::GLOG_ERROR, \
122 | __FILE__, __LINE__, __VA_ARGS__)
123 | #else
124 | #define RAW_LOG_ERROR(...) google::RawLogStub__(0, __VA_ARGS__)
125 | #endif // STRIP_LOG <= 2
126 |
127 | #if STRIP_LOG <= 3
128 | #define RAW_LOG_FATAL(...) google::RawLog__(google::GLOG_FATAL, \
129 | __FILE__, __LINE__, __VA_ARGS__)
130 | #else
131 | #define RAW_LOG_FATAL(...) \
132 | do { \
133 | google::RawLogStub__(0, __VA_ARGS__); \
134 | exit(1); \
135 | } while (0)
136 | #endif // STRIP_LOG <= 3
137 |
138 | // Similar to CHECK(condition) << message,
139 | // but for low-level modules: we use only RAW_LOG that does not allocate memory.
140 | // We do not want to provide args list here to encourage this usage:
141 | // if (!cond) RAW_LOG(FATAL, "foo ...", hard_to_compute_args);
142 | // so that the args are not computed when not needed.
143 | #define RAW_CHECK(condition, message) \
144 | do { \
145 | if (!(condition)) { \
146 | RAW_LOG(FATAL, "Check %s failed: %s", #condition, message); \
147 | } \
148 | } while (0)
149 |
150 | // Debug versions of RAW_LOG and RAW_CHECK
151 | #ifndef NDEBUG
152 |
153 | #define RAW_DLOG(severity, ...) RAW_LOG(severity, __VA_ARGS__)
154 | #define RAW_DCHECK(condition, message) RAW_CHECK(condition, message)
155 |
156 | #else // NDEBUG
157 |
158 | #define RAW_DLOG(severity, ...) \
159 | while (false) \
160 | RAW_LOG(severity, __VA_ARGS__)
161 | #define RAW_DCHECK(condition, message) \
162 | while (false) \
163 | RAW_CHECK(condition, message)
164 |
165 | #endif // NDEBUG
166 |
167 | // Stub log function used to work around for unused variable warnings when
168 | // building with STRIP_LOG > 0.
169 | static inline void RawLogStub__(int /* ignored */, ...) {
170 | }
171 |
172 | // Helper function to implement RAW_LOG and RAW_VLOG
173 | // Logs format... at "severity" level, reporting it
174 | // as called from file:line.
175 | // This does not allocate memory or acquire locks.
176 | GOOGLE_GLOG_DLL_DECL void RawLog__(LogSeverity severity,
177 | const char* file,
178 | int line,
179 | const char* format, ...)
180 | ;
181 |
182 | // Hack to propagate time information into this module so that
183 | // this module does not have to directly call localtime_r(),
184 | // which could allocate memory.
185 | GOOGLE_GLOG_DLL_DECL void RawLog__SetLastTime(const struct tm& t, int usecs);
186 |
187 | }
188 |
189 | #endif // BASE_RAW_LOGGING_H_
190 |
--------------------------------------------------------------------------------
/hashtool/hi_md5.h:
--------------------------------------------------------------------------------
1 | #ifndef MD5_H
2 | #define MD5_H
3 |
4 | #include
5 |
6 | typedef unsigned char *POINTER;
7 |
8 | /**
9 | * @brief this struct represents a MD5-hash context.
10 | */
11 | typedef struct
12 | {
13 | /** state (ABCD) */
14 | unsigned long int state[4];
15 |
16 | /** number of bits, modulo 2^64 (lsb first) */
17 | unsigned long int count[2];
18 |
19 | /** input buffer */
20 | unsigned char buffer[64];
21 | } HL_MD5_CTX;
22 |
23 | // Constants for MD5Transform routine.
24 | #define S11 7
25 | #define S12 12
26 | #define S13 17
27 | #define S14 22
28 | #define S21 5
29 | #define S22 9
30 | #define S23 14
31 | #define S24 20
32 | #define S31 4
33 | #define S32 11
34 | #define S33 16
35 | #define S34 23
36 | #define S41 6
37 | #define S42 10
38 | #define S43 15
39 | #define S44 21
40 |
41 | static unsigned char PADDING[64] = {
42 | 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
43 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
44 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
45 | };
46 |
47 | /* F, G, H and I are basic MD5 functions. */
48 | #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
49 | #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
50 | #define H(x, y, z) ((x) ^ (y) ^ (z))
51 | #define I(x, y, z) ((y) ^ ((x) | (~z)))
52 |
53 | /*
54 | * ROTATE_LEFT rotates x left n bits.
55 | * cast to unsigned int to guarantee support for 64Bit System
56 | */
57 | #define ROTATE_LEFT(x, n) (((x) << (n)) | (( (unsigned int) x) >> (32-(n))))
58 |
59 | /*
60 | FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
61 | Rotation is separate from addition to prevent recomputation.
62 | */
63 | #define FF(a, b, c, d, x, s, ac) { \
64 | (a) += F ((b), (c), (d)) + (x) + (unsigned long int)(ac); \
65 | (a) = ROTATE_LEFT ((a), (s)); \
66 | (a) += (b); \
67 | }
68 |
69 | #define GG(a, b, c, d, x, s, ac) { \
70 | (a) += G ((b), (c), (d)) + (x) + (unsigned long int)(ac); \
71 | (a) = ROTATE_LEFT ((a), (s)); \
72 | (a) += (b); \
73 | }
74 | #define HH(a, b, c, d, x, s, ac) { \
75 | (a) += H ((b), (c), (d)) + (x) + (unsigned long int)(ac); \
76 | (a) = ROTATE_LEFT ((a), (s)); \
77 | (a) += (b); \
78 | }
79 | #define II(a, b, c, d, x, s, ac) { \
80 | (a) += I ((b), (c), (d)) + (x) + (unsigned long int)(ac); \
81 | (a) = ROTATE_LEFT ((a), (s)); \
82 | (a) += (b); \
83 | }
84 |
85 | class MD5
86 | {
87 | private:
88 | /**
89 | * @brief Basic transformation. Transforms state based on block.
90 | * @param state state to transform
91 | * @param block block to transform
92 | */
93 | void MD5Transform (unsigned long int state[4], unsigned char block[64])
94 | {
95 | unsigned long int a = state[0], b = state[1], c = state[2], d = state[3], x[16];
96 |
97 | Decode (x, block, 64);
98 |
99 | /* Round 1 */
100 | FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
101 | FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
102 | FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
103 | FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
104 | FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
105 | FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
106 | FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
107 | FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
108 | FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
109 | FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
110 | FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
111 | FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
112 | FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
113 | FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
114 | FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
115 | FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
116 |
117 | /* Round 2 */
118 | GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
119 | GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
120 | GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
121 | GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
122 | GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
123 | GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
124 | GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
125 | GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
126 | GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
127 | GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
128 | GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
129 |
130 | GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
131 | GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
132 | GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
133 | GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
134 | GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
135 |
136 | /* Round 3 */
137 | HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
138 | HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
139 | HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
140 | HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
141 | HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
142 | HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
143 | HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
144 | HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
145 | HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
146 | HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
147 | HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
148 | HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
149 | HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
150 | HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
151 | HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
152 | HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
153 |
154 | /* Round 4 */
155 | II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
156 | II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
157 | II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
158 | II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
159 | II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
160 | II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
161 | II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
162 | II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
163 | II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
164 | II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
165 | II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
166 | II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
167 | II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
168 | II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
169 | II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
170 | II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
171 |
172 | state[0] += a;
173 | state[1] += b;
174 | state[2] += c;
175 | state[3] += d;
176 |
177 | /*
178 | * Zeroize sensitive information.
179 | */
180 | MD5_memset ((POINTER)x, 0, sizeof (x));
181 | }
182 |
183 | /**
184 | * @brief Encodes input data
185 | * @param output Encoded data as OUT parameter
186 | * @param input Input data
187 | * @param len The length of the input assuming it is a
188 | * multiple of 4
189 | */
190 | void Encode (unsigned char *output, unsigned long int *input, unsigned int len)
191 | {
192 | unsigned int i, j;
193 |
194 | for (i = 0, j = 0; j < len; i++, j += 4) {
195 | output[j] = (unsigned char)(input[i] & 0xff);
196 | output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
197 | output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
198 | output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
199 | }
200 | }
201 |
202 | /**
203 | * @brief Decodes input data into output
204 | * @param output Decoded data as OUT parameter
205 | * @param input Input data
206 | * @param len The length of the input assuming it is a
207 | * multiple of 4
208 | */
209 | void Decode (unsigned long int *output, unsigned char *input, unsigned int len)
210 | {
211 | unsigned int i, j;
212 |
213 | for (i = 0, j = 0; j < len; i++, j += 4)
214 | output[i] = ((unsigned long int)input[j]) |
215 | (((unsigned long int)input[j+1]) << 8) |
216 | (((unsigned long int)input[j+2]) << 16) |
217 | (((unsigned long int)input[j+3]) << 24);
218 | }
219 |
220 | /**
221 | * @brief internal memory management
222 | * @param output OUT parameter where POINTER is a unsigned
223 | * char*
224 | * @param input Data to copy where POINTER is a unsigned char*
225 | * @param len The length of the data
226 | */
227 | void MD5_memcpy (POINTER output, POINTER input, unsigned int len)
228 | {
229 | /*
230 | * TODO-Note: Replace "for loop" with standard memcpy if possible.
231 | */
232 | unsigned int i;
233 |
234 | for (i = 0; i < len; i++)
235 | output[i] = input[i];
236 | }
237 |
238 | /**
239 | * @brief internal memory management
240 | * @param output OUT parameter where POINTER is an unsigned
241 | * char*
242 | * @param value Value to fill the memory with
243 | * @param len The length of the data
244 | *
245 | */
246 | void MD5_memset (POINTER output,int value,unsigned int len)
247 | {
248 | /*
249 | * TODO-Note: Replace "for loop" with standard memset if possible.
250 | */
251 | unsigned int i;
252 | for (i = 0; i < len; i++)
253 | ((char *)output)[i] = (char)value;
254 | }
255 |
256 | //----------------------------------------------------------------------
257 | //public member-functions
258 | public:
259 | /**
260 | * @brief Initialization begins an operation,
261 | * writing a new context
262 | * @param context The HL_MD5_CTX context to initialize
263 | */
264 | void MD5Init (HL_MD5_CTX *context)
265 | {
266 | context->count[0] = context->count[1] = 0;
267 | context->state[0] = 0x67452301;
268 | context->state[1] = 0xefcdab89;
269 | context->state[2] = 0x98badcfe;
270 | context->state[3] = 0x10325476;
271 | }
272 |
273 | /**
274 | * @brief Block update operation. Continues an md5
275 | * message-digest operation, processing another
276 | * message block, and updating the context.
277 | * @param context The HL_MD5_CTX context to update
278 | * @param input The data to write into the context
279 | * @param inputLen The length of the input data
280 | */
281 | void MD5Update (HL_MD5_CTX *context, unsigned char *input, unsigned int inputLen)
282 | {
283 | unsigned int i, index, partLen;
284 |
285 | /* Compute number of bytes mod 64 */
286 | index = (unsigned int)((context->count[0] >> 3) & 0x3F);
287 |
288 | /* Update number of bits */
289 | if ( (context->count[0] += ((unsigned long int)inputLen << 3))
290 | < ((unsigned long int)inputLen << 3))
291 | context->count[1]++;
292 |
293 | context->count[1] += ((unsigned long int)inputLen >> 29);
294 | partLen = 64 - index;
295 |
296 | /*
297 | * Transform as many times as possible.
298 | */
299 | if (inputLen >= partLen)
300 | {
301 | MD5_memcpy ((POINTER)&context->buffer[index], (POINTER)input, partLen);
302 | MD5Transform (context->state, context->buffer);
303 |
304 | for (i = partLen; i + 63 < inputLen; i += 64)
305 | MD5Transform (context->state, &input[i]);
306 |
307 | index = 0;
308 | }
309 | else
310 | i = 0;
311 |
312 | /* Buffer remaining input */
313 | MD5_memcpy ((POINTER)&context->buffer[index],
314 | (POINTER)&input[i],
315 | inputLen-i);
316 | }
317 |
318 | /**
319 | * @brief Finalization ends the md5 message-digest
320 | * operation, writing the the message digest and
321 | * zeroizing the context.
322 | * @param digest This is an OUT parameter which contains
323 | * the created hash after the method returns
324 | * @param context The context to finalize
325 | */
326 | void MD5Final (unsigned char digest[16], HL_MD5_CTX *context)
327 | {
328 | unsigned char bits[8];
329 | unsigned int index, padLen;
330 |
331 | /* Save number of bits */
332 | Encode (bits, context->count, 8);
333 |
334 | /*
335 | * Pad out to 56 mod 64.
336 | */
337 | index = (unsigned int)((context->count[0] >> 3) & 0x3f);
338 | padLen = (index < 56) ? (56 - index) : (120 - index);
339 | MD5Update (context, PADDING, padLen);
340 |
341 | /* Append length (before padding) */
342 | MD5Update (context, bits, 8);
343 |
344 | /* Store state in digest */
345 | Encode (digest, context->state, 16);
346 |
347 | /*
348 | * Zeroize sensitive information.
349 | */
350 | MD5_memset ((POINTER)context, 0, sizeof (*context));
351 | }
352 |
353 | MD5(){};
354 | };
355 |
356 | #endif // MD5_H
--------------------------------------------------------------------------------
/demo/demo/hashtool/hi_md5.h:
--------------------------------------------------------------------------------
1 | #ifndef MD5_H
2 | #define MD5_H
3 |
4 | #include
5 |
6 | typedef unsigned char *POINTER;
7 |
8 | /**
9 | * @brief this struct represents a MD5-hash context.
10 | */
11 | typedef struct
12 | {
13 | /** state (ABCD) */
14 | unsigned long int state[4];
15 |
16 | /** number of bits, modulo 2^64 (lsb first) */
17 | unsigned long int count[2];
18 |
19 | /** input buffer */
20 | unsigned char buffer[64];
21 | } HL_MD5_CTX;
22 |
23 | // Constants for MD5Transform routine.
24 | #define S11 7
25 | #define S12 12
26 | #define S13 17
27 | #define S14 22
28 | #define S21 5
29 | #define S22 9
30 | #define S23 14
31 | #define S24 20
32 | #define S31 4
33 | #define S32 11
34 | #define S33 16
35 | #define S34 23
36 | #define S41 6
37 | #define S42 10
38 | #define S43 15
39 | #define S44 21
40 |
41 | static unsigned char PADDING[64] = {
42 | 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
43 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
44 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
45 | };
46 |
47 | /* F, G, H and I are basic MD5 functions. */
48 | #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
49 | #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
50 | #define H(x, y, z) ((x) ^ (y) ^ (z))
51 | #define I(x, y, z) ((y) ^ ((x) | (~z)))
52 |
53 | /*
54 | * ROTATE_LEFT rotates x left n bits.
55 | * cast to unsigned int to guarantee support for 64Bit System
56 | */
57 | #define ROTATE_LEFT(x, n) (((x) << (n)) | (( (unsigned int) x) >> (32-(n))))
58 |
59 | /*
60 | FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
61 | Rotation is separate from addition to prevent recomputation.
62 | */
63 | #define FF(a, b, c, d, x, s, ac) { \
64 | (a) += F ((b), (c), (d)) + (x) + (unsigned long int)(ac); \
65 | (a) = ROTATE_LEFT ((a), (s)); \
66 | (a) += (b); \
67 | }
68 |
69 | #define GG(a, b, c, d, x, s, ac) { \
70 | (a) += G ((b), (c), (d)) + (x) + (unsigned long int)(ac); \
71 | (a) = ROTATE_LEFT ((a), (s)); \
72 | (a) += (b); \
73 | }
74 | #define HH(a, b, c, d, x, s, ac) { \
75 | (a) += H ((b), (c), (d)) + (x) + (unsigned long int)(ac); \
76 | (a) = ROTATE_LEFT ((a), (s)); \
77 | (a) += (b); \
78 | }
79 | #define II(a, b, c, d, x, s, ac) { \
80 | (a) += I ((b), (c), (d)) + (x) + (unsigned long int)(ac); \
81 | (a) = ROTATE_LEFT ((a), (s)); \
82 | (a) += (b); \
83 | }
84 |
85 | class MD5
86 | {
87 | private:
88 | /**
89 | * @brief Basic transformation. Transforms state based on block.
90 | * @param state state to transform
91 | * @param block block to transform
92 | */
93 | void MD5Transform (unsigned long int state[4], unsigned char block[64])
94 | {
95 | unsigned long int a = state[0], b = state[1], c = state[2], d = state[3], x[16];
96 |
97 | Decode (x, block, 64);
98 |
99 | /* Round 1 */
100 | FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
101 | FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
102 | FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
103 | FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
104 | FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
105 | FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
106 | FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
107 | FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
108 | FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
109 | FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
110 | FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
111 | FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
112 | FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
113 | FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
114 | FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
115 | FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
116 |
117 | /* Round 2 */
118 | GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
119 | GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
120 | GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
121 | GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
122 | GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
123 | GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
124 | GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
125 | GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
126 | GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
127 | GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
128 | GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
129 |
130 | GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
131 | GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
132 | GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
133 | GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
134 | GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
135 |
136 | /* Round 3 */
137 | HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
138 | HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
139 | HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
140 | HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
141 | HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
142 | HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
143 | HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
144 | HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
145 | HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
146 | HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
147 | HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
148 | HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
149 | HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
150 | HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
151 | HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
152 | HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
153 |
154 | /* Round 4 */
155 | II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
156 | II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
157 | II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
158 | II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
159 | II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
160 | II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
161 | II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
162 | II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
163 | II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
164 | II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
165 | II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
166 | II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
167 | II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
168 | II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
169 | II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
170 | II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
171 |
172 | state[0] += a;
173 | state[1] += b;
174 | state[2] += c;
175 | state[3] += d;
176 |
177 | /*
178 | * Zeroize sensitive information.
179 | */
180 | MD5_memset ((POINTER)x, 0, sizeof (x));
181 | }
182 |
183 | /**
184 | * @brief Encodes input data
185 | * @param output Encoded data as OUT parameter
186 | * @param input Input data
187 | * @param len The length of the input assuming it is a
188 | * multiple of 4
189 | */
190 | void Encode (unsigned char *output, unsigned long int *input, unsigned int len)
191 | {
192 | unsigned int i, j;
193 |
194 | for (i = 0, j = 0; j < len; i++, j += 4) {
195 | output[j] = (unsigned char)(input[i] & 0xff);
196 | output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
197 | output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
198 | output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
199 | }
200 | }
201 |
202 | /**
203 | * @brief Decodes input data into output
204 | * @param output Decoded data as OUT parameter
205 | * @param input Input data
206 | * @param len The length of the input assuming it is a
207 | * multiple of 4
208 | */
209 | void Decode (unsigned long int *output, unsigned char *input, unsigned int len)
210 | {
211 | unsigned int i, j;
212 |
213 | for (i = 0, j = 0; j < len; i++, j += 4)
214 | output[i] = ((unsigned long int)input[j]) |
215 | (((unsigned long int)input[j+1]) << 8) |
216 | (((unsigned long int)input[j+2]) << 16) |
217 | (((unsigned long int)input[j+3]) << 24);
218 | }
219 |
220 | /**
221 | * @brief internal memory management
222 | * @param output OUT parameter where POINTER is a unsigned
223 | * char*
224 | * @param input Data to copy where POINTER is a unsigned char*
225 | * @param len The length of the data
226 | */
227 | void MD5_memcpy (POINTER output, POINTER input, unsigned int len)
228 | {
229 | /*
230 | * TODO-Note: Replace "for loop" with standard memcpy if possible.
231 | */
232 | unsigned int i;
233 |
234 | for (i = 0; i < len; i++)
235 | output[i] = input[i];
236 | }
237 |
238 | /**
239 | * @brief internal memory management
240 | * @param output OUT parameter where POINTER is an unsigned
241 | * char*
242 | * @param value Value to fill the memory with
243 | * @param len The length of the data
244 | *
245 | */
246 | void MD5_memset (POINTER output,int value,unsigned int len)
247 | {
248 | /*
249 | * TODO-Note: Replace "for loop" with standard memset if possible.
250 | */
251 | unsigned int i;
252 | for (i = 0; i < len; i++)
253 | ((char *)output)[i] = (char)value;
254 | }
255 |
256 | //----------------------------------------------------------------------
257 | //public member-functions
258 | public:
259 | /**
260 | * @brief Initialization begins an operation,
261 | * writing a new context
262 | * @param context The HL_MD5_CTX context to initialize
263 | */
264 | void MD5Init (HL_MD5_CTX *context)
265 | {
266 | context->count[0] = context->count[1] = 0;
267 | context->state[0] = 0x67452301;
268 | context->state[1] = 0xefcdab89;
269 | context->state[2] = 0x98badcfe;
270 | context->state[3] = 0x10325476;
271 | }
272 |
273 | /**
274 | * @brief Block update operation. Continues an md5
275 | * message-digest operation, processing another
276 | * message block, and updating the context.
277 | * @param context The HL_MD5_CTX context to update
278 | * @param input The data to write into the context
279 | * @param inputLen The length of the input data
280 | */
281 | void MD5Update (HL_MD5_CTX *context, unsigned char *input, unsigned int inputLen)
282 | {
283 | unsigned int i, index, partLen;
284 |
285 | /* Compute number of bytes mod 64 */
286 | index = (unsigned int)((context->count[0] >> 3) & 0x3F);
287 |
288 | /* Update number of bits */
289 | if ( (context->count[0] += ((unsigned long int)inputLen << 3))
290 | < ((unsigned long int)inputLen << 3))
291 | context->count[1]++;
292 |
293 | context->count[1] += ((unsigned long int)inputLen >> 29);
294 | partLen = 64 - index;
295 |
296 | /*
297 | * Transform as many times as possible.
298 | */
299 | if (inputLen >= partLen)
300 | {
301 | MD5_memcpy ((POINTER)&context->buffer[index], (POINTER)input, partLen);
302 | MD5Transform (context->state, context->buffer);
303 |
304 | for (i = partLen; i + 63 < inputLen; i += 64)
305 | MD5Transform (context->state, &input[i]);
306 |
307 | index = 0;
308 | }
309 | else
310 | i = 0;
311 |
312 | /* Buffer remaining input */
313 | MD5_memcpy ((POINTER)&context->buffer[index],
314 | (POINTER)&input[i],
315 | inputLen-i);
316 | }
317 |
318 | /**
319 | * @brief Finalization ends the md5 message-digest
320 | * operation, writing the the message digest and
321 | * zeroizing the context.
322 | * @param digest This is an OUT parameter which contains
323 | * the created hash after the method returns
324 | * @param context The context to finalize
325 | */
326 | void MD5Final (unsigned char digest[16], HL_MD5_CTX *context)
327 | {
328 | unsigned char bits[8];
329 | unsigned int index, padLen;
330 |
331 | /* Save number of bits */
332 | Encode (bits, context->count, 8);
333 |
334 | /*
335 | * Pad out to 56 mod 64.
336 | */
337 | index = (unsigned int)((context->count[0] >> 3) & 0x3f);
338 | padLen = (index < 56) ? (56 - index) : (120 - index);
339 | MD5Update (context, PADDING, padLen);
340 |
341 | /* Append length (before padding) */
342 | MD5Update (context, bits, 8);
343 |
344 | /* Store state in digest */
345 | Encode (digest, context->state, 16);
346 |
347 | /*
348 | * Zeroize sensitive information.
349 | */
350 | MD5_memset ((POINTER)context, 0, sizeof (*context));
351 | }
352 |
353 | MD5(){};
354 | };
355 |
356 | #endif // MD5_H
--------------------------------------------------------------------------------
/glog/logging.h:
--------------------------------------------------------------------------------
1 | // This file is automatically generated from src/glog/logging.h.in
2 | // using src/windows/preprocess.sh.
3 | // DO NOT EDIT!
4 |
5 | // Copyright (c) 1999, Google Inc.
6 | // All rights reserved.
7 | //
8 | // Redistribution and use in source and binary forms, with or without
9 | // modification, are permitted provided that the following conditions are
10 | // met:
11 | //
12 | // * Redistributions of source code must retain the above copyright
13 | // notice, this list of conditions and the following disclaimer.
14 | // * Redistributions in binary form must reproduce the above
15 | // copyright notice, this list of conditions and the following disclaimer
16 | // in the documentation and/or other materials provided with the
17 | // distribution.
18 | // * Neither the name of Google Inc. nor the names of its
19 | // contributors may be used to endorse or promote products derived from
20 | // this software without specific prior written permission.
21 | //
22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 | //
34 | // Author: Ray Sidney
35 | //
36 | // This file contains #include information about logging-related stuff.
37 | // Pretty much everybody needs to #include this file so that they can
38 | // log various happenings.
39 | //
40 | #ifndef _LOGGING_H_
41 | #define _LOGGING_H_
42 |
43 | #include
44 | #include
45 | #include
46 | #include
47 | #include
48 | #include
49 | #include
50 | #if 0
51 | # include
52 | #endif
53 | #include
54 |
55 | // Annoying stuff for windows -- makes sure clients can import these functions
56 | #ifndef GOOGLE_GLOG_DLL_DECL
57 | # if defined(_WIN32) && !defined(__CYGWIN__)
58 | # define GOOGLE_GLOG_DLL_DECL __declspec(dllimport)
59 | # else
60 | # define GOOGLE_GLOG_DLL_DECL
61 | # endif
62 | #endif
63 | #if defined(_MSC_VER)
64 | #define GLOG_MSVC_PUSH_DISABLE_WARNING(n) __pragma(warning(push)) \
65 | __pragma(warning(disable:n))
66 | #define GLOG_MSVC_POP_WARNING() __pragma(warning(pop))
67 | #else
68 | #define GLOG_MSVC_PUSH_DISABLE_WARNING(n)
69 | #define GLOG_MSVC_POP_WARNING()
70 | #endif
71 |
72 | // We care a lot about number of bits things take up. Unfortunately,
73 | // systems define their bit-specific ints in a lot of different ways.
74 | // We use our own way, and have a typedef to get there.
75 | // Note: these commands below may look like "#if 1" or "#if 0", but
76 | // that's because they were constructed that way at ./configure time.
77 | // Look at logging.h.in to see how they're calculated (based on your config).
78 | #if 0
79 | #include // the normal place uint16_t is defined
80 | #endif
81 | #if 0
82 | #include // the normal place u_int16_t is defined
83 | #endif
84 | #if 0
85 | #include // a third place for uint16_t or u_int16_t
86 | #endif
87 |
88 | #if 0
89 | #include
90 | #endif
91 |
92 | namespace google {
93 |
94 | #if 0 // the C99 format
95 | typedef int32_t int32;
96 | typedef uint32_t uint32;
97 | typedef int64_t int64;
98 | typedef uint64_t uint64;
99 | #elif 0 // the BSD format
100 | typedef int32_t int32;
101 | typedef u_int32_t uint32;
102 | typedef int64_t int64;
103 | typedef u_int64_t uint64;
104 | #elif 1 // the windows (vc7) format
105 | typedef __int32 int32;
106 | typedef unsigned __int32 uint32;
107 | typedef __int64 int64;
108 | typedef unsigned __int64 uint64;
109 | #else
110 | #error Do not know how to define a 32-bit integer quantity on your system
111 | #endif
112 |
113 | }
114 |
115 | // The global value of GOOGLE_STRIP_LOG. All the messages logged to
116 | // LOG(XXX) with severity less than GOOGLE_STRIP_LOG will not be displayed.
117 | // If it can be determined at compile time that the message will not be
118 | // printed, the statement will be compiled out.
119 | //
120 | // Example: to strip out all INFO and WARNING messages, use the value
121 | // of 2 below. To make an exception for WARNING messages from a single
122 | // file, add "#define GOOGLE_STRIP_LOG 1" to that file _before_ including
123 | // base/logging.h
124 | #ifndef GOOGLE_STRIP_LOG
125 | #define GOOGLE_STRIP_LOG 0
126 | #endif
127 |
128 | // GCC can be told that a certain branch is not likely to be taken (for
129 | // instance, a CHECK failure), and use that information in static analysis.
130 | // Giving it this information can help it optimize for the common case in
131 | // the absence of better information (ie. -fprofile-arcs).
132 | //
133 | #ifndef GOOGLE_PREDICT_BRANCH_NOT_TAKEN
134 | #if 0
135 | #define GOOGLE_PREDICT_BRANCH_NOT_TAKEN(x) (__builtin_expect(x, 0))
136 | #define GOOGLE_PREDICT_FALSE(x) (__builtin_expect(x, 0))
137 | #define GOOGLE_PREDICT_TRUE(x) (__builtin_expect(!!(x), 1))
138 | #else
139 | #define GOOGLE_PREDICT_BRANCH_NOT_TAKEN(x) x
140 | #define GOOGLE_PREDICT_FALSE(x) x
141 | #define GOOGLE_PREDICT_TRUE(x) x
142 | #endif
143 | #endif
144 |
145 | // Make a bunch of macros for logging. The way to log things is to stream
146 | // things to LOG(). E.g.,
147 | //
148 | // LOG(INFO) << "Found " << num_cookies << " cookies";
149 | //
150 | // You can capture log messages in a string, rather than reporting them
151 | // immediately:
152 | //
153 | // vector errors;
154 | // LOG_STRING(ERROR, &errors) << "Couldn't parse cookie #" << cookie_num;
155 | //
156 | // This pushes back the new error onto 'errors'; if given a NULL pointer,
157 | // it reports the error via LOG(ERROR).
158 | //
159 | // You can also do conditional logging:
160 | //
161 | // LOG_IF(INFO, num_cookies > 10) << "Got lots of cookies";
162 | //
163 | // You can also do occasional logging (log every n'th occurrence of an
164 | // event):
165 | //
166 | // LOG_EVERY_N(INFO, 10) << "Got the " << google::COUNTER << "th cookie";
167 | //
168 | // The above will cause log messages to be output on the 1st, 11th, 21st, ...
169 | // times it is executed. Note that the special google::COUNTER value is used
170 | // to identify which repetition is happening.
171 | //
172 | // You can also do occasional conditional logging (log every n'th
173 | // occurrence of an event, when condition is satisfied):
174 | //
175 | // LOG_IF_EVERY_N(INFO, (size > 1024), 10) << "Got the " << google::COUNTER
176 | // << "th big cookie";
177 | //
178 | // You can log messages the first N times your code executes a line. E.g.
179 | //
180 | // LOG_FIRST_N(INFO, 20) << "Got the " << google::COUNTER << "th cookie";
181 | //
182 | // Outputs log messages for the first 20 times it is executed.
183 | //
184 | // Analogous SYSLOG, SYSLOG_IF, and SYSLOG_EVERY_N macros are available.
185 | // These log to syslog as well as to the normal logs. If you use these at
186 | // all, you need to be aware that syslog can drastically reduce performance,
187 | // especially if it is configured for remote logging! Don't use these
188 | // unless you fully understand this and have a concrete need to use them.
189 | // Even then, try to minimize your use of them.
190 | //
191 | // There are also "debug mode" logging macros like the ones above:
192 | //
193 | // DLOG(INFO) << "Found cookies";
194 | //
195 | // DLOG_IF(INFO, num_cookies > 10) << "Got lots of cookies";
196 | //
197 | // DLOG_EVERY_N(INFO, 10) << "Got the " << google::COUNTER << "th cookie";
198 | //
199 | // All "debug mode" logging is compiled away to nothing for non-debug mode
200 | // compiles.
201 | //
202 | // We also have
203 | //
204 | // LOG_ASSERT(assertion);
205 | // DLOG_ASSERT(assertion);
206 | //
207 | // which is syntactic sugar for {,D}LOG_IF(FATAL, assert fails) << assertion;
208 | //
209 | // There are "verbose level" logging macros. They look like
210 | //
211 | // VLOG(1) << "I'm printed when you run the program with --v=1 or more";
212 | // VLOG(2) << "I'm printed when you run the program with --v=2 or more";
213 | //
214 | // These always log at the INFO log level (when they log at all).
215 | // The verbose logging can also be turned on module-by-module. For instance,
216 | // --vmodule=mapreduce=2,file=1,gfs*=3 --v=0
217 | // will cause:
218 | // a. VLOG(2) and lower messages to be printed from mapreduce.{h,cc}
219 | // b. VLOG(1) and lower messages to be printed from file.{h,cc}
220 | // c. VLOG(3) and lower messages to be printed from files prefixed with "gfs"
221 | // d. VLOG(0) and lower messages to be printed from elsewhere
222 | //
223 | // The wildcarding functionality shown by (c) supports both '*' (match
224 | // 0 or more characters) and '?' (match any single character) wildcards.
225 | //
226 | // There's also VLOG_IS_ON(n) "verbose level" condition macro. To be used as
227 | //
228 | // if (VLOG_IS_ON(2)) {
229 | // // do some logging preparation and logging
230 | // // that can't be accomplished with just VLOG(2) << ...;
231 | // }
232 | //
233 | // There are also VLOG_IF, VLOG_EVERY_N and VLOG_IF_EVERY_N "verbose level"
234 | // condition macros for sample cases, when some extra computation and
235 | // preparation for logs is not needed.
236 | // VLOG_IF(1, (size > 1024))
237 | // << "I'm printed when size is more than 1024 and when you run the "
238 | // "program with --v=1 or more";
239 | // VLOG_EVERY_N(1, 10)
240 | // << "I'm printed every 10th occurrence, and when you run the program "
241 | // "with --v=1 or more. Present occurence is " << google::COUNTER;
242 | // VLOG_IF_EVERY_N(1, (size > 1024), 10)
243 | // << "I'm printed on every 10th occurence of case when size is more "
244 | // " than 1024, when you run the program with --v=1 or more. ";
245 | // "Present occurence is " << google::COUNTER;
246 | //
247 | // The supported severity levels for macros that allow you to specify one
248 | // are (in increasing order of severity) INFO, WARNING, ERROR, and FATAL.
249 | // Note that messages of a given severity are logged not only in the
250 | // logfile for that severity, but also in all logfiles of lower severity.
251 | // E.g., a message of severity FATAL will be logged to the logfiles of
252 | // severity FATAL, ERROR, WARNING, and INFO.
253 | //
254 | // There is also the special severity of DFATAL, which logs FATAL in
255 | // debug mode, ERROR in normal mode.
256 | //
257 | // Very important: logging a message at the FATAL severity level causes
258 | // the program to terminate (after the message is logged).
259 | //
260 | // Unless otherwise specified, logs will be written to the filename
261 | // "...log..", followed
262 | // by the date, time, and pid (you can't prevent the date, time, and pid
263 | // from being in the filename).
264 | //
265 | // The logging code takes two flags:
266 | // --v=# set the verbose level
267 | // --logtostderr log all the messages to stderr instead of to logfiles
268 |
269 | // LOG LINE PREFIX FORMAT
270 | //
271 | // Log lines have this form:
272 | //
273 | // Lmmdd hh:mm:ss.uuuuuu threadid file:line] msg...
274 | //
275 | // where the fields are defined as follows:
276 | //
277 | // L A single character, representing the log level
278 | // (eg 'I' for INFO)
279 | // mm The month (zero padded; ie May is '05')
280 | // dd The day (zero padded)
281 | // hh:mm:ss.uuuuuu Time in hours, minutes and fractional seconds
282 | // threadid The space-padded thread ID as returned by GetTID()
283 | // (this matches the PID on Linux)
284 | // file The file name
285 | // line The line number
286 | // msg The user-supplied message
287 | //
288 | // Example:
289 | //
290 | // I1103 11:57:31.739339 24395 google.cc:2341] Command line: ./some_prog
291 | // I1103 11:57:31.739403 24395 google.cc:2342] Process id 24395
292 | //
293 | // NOTE: although the microseconds are useful for comparing events on
294 | // a single machine, clocks on different machines may not be well
295 | // synchronized. Hence, use caution when comparing the low bits of
296 | // timestamps from different machines.
297 |
298 | #ifndef DECLARE_VARIABLE
299 | #define MUST_UNDEF_GFLAGS_DECLARE_MACROS
300 | #define DECLARE_VARIABLE(type, shorttype, name, tn) \
301 | namespace fL##shorttype { \
302 | extern GOOGLE_GLOG_DLL_DECL type FLAGS_##name; \
303 | } \
304 | using fL##shorttype::FLAGS_##name
305 |
306 | // bool specialization
307 | #define DECLARE_bool(name) \
308 | DECLARE_VARIABLE(bool, B, name, bool)
309 |
310 | // int32 specialization
311 | #define DECLARE_int32(name) \
312 | DECLARE_VARIABLE(google::int32, I, name, int32)
313 |
314 | // Special case for string, because we have to specify the namespace
315 | // std::string, which doesn't play nicely with our FLAG__namespace hackery.
316 | #define DECLARE_string(name) \
317 | namespace fLS { \
318 | extern GOOGLE_GLOG_DLL_DECL std::string& FLAGS_##name; \
319 | } \
320 | using fLS::FLAGS_##name
321 | #endif
322 |
323 | // Set whether log messages go to stderr instead of logfiles
324 | DECLARE_bool(logtostderr);
325 |
326 | // Set whether log messages go to stderr in addition to logfiles.
327 | DECLARE_bool(alsologtostderr);
328 |
329 | // Set color messages logged to stderr (if supported by terminal).
330 | DECLARE_bool(colorlogtostderr);
331 |
332 | // Log messages at a level >= this flag are automatically sent to
333 | // stderr in addition to log files.
334 | DECLARE_int32(stderrthreshold);
335 |
336 | // Set whether the log prefix should be prepended to each line of output.
337 | DECLARE_bool(log_prefix);
338 |
339 | // Log messages at a level <= this flag are buffered.
340 | // Log messages at a higher level are flushed immediately.
341 | DECLARE_int32(logbuflevel);
342 |
343 | // Sets the maximum number of seconds which logs may be buffered for.
344 | DECLARE_int32(logbufsecs);
345 |
346 | // Log suppression level: messages logged at a lower level than this
347 | // are suppressed.
348 | DECLARE_int32(minloglevel);
349 |
350 | // If specified, logfiles are written into this directory instead of the
351 | // default logging directory.
352 | DECLARE_string(log_dir);
353 |
354 | // Sets the path of the directory into which to put additional links
355 | // to the log files.
356 | DECLARE_string(log_link);
357 |
358 | DECLARE_int32(v); // in vlog_is_on.cc
359 |
360 | // Sets the maximum log file size (in MB).
361 | DECLARE_int32(max_log_size);
362 |
363 | // Sets whether to avoid logging to the disk if the disk is full.
364 | DECLARE_bool(stop_logging_if_full_disk);
365 |
366 | #ifdef MUST_UNDEF_GFLAGS_DECLARE_MACROS
367 | #undef MUST_UNDEF_GFLAGS_DECLARE_MACROS
368 | #undef DECLARE_VARIABLE
369 | #undef DECLARE_bool
370 | #undef DECLARE_int32
371 | #undef DECLARE_string
372 | #endif
373 |
374 | // Log messages below the GOOGLE_STRIP_LOG level will be compiled away for
375 | // security reasons. See LOG(severtiy) below.
376 |
377 | // A few definitions of macros that don't generate much code. Since
378 | // LOG(INFO) and its ilk are used all over our code, it's
379 | // better to have compact code for these operations.
380 |
381 | #if GOOGLE_STRIP_LOG == 0
382 | #define COMPACT_GOOGLE_LOG_INFO google::LogMessage( \
383 | __FILE__, __LINE__)
384 | #define LOG_TO_STRING_INFO(message) google::LogMessage( \
385 | __FILE__, __LINE__, google::GLOG_INFO, message)
386 | #else
387 | #define COMPACT_GOOGLE_LOG_INFO google::NullStream()
388 | #define LOG_TO_STRING_INFO(message) google::NullStream()
389 | #endif
390 |
391 | #if GOOGLE_STRIP_LOG <= 1
392 | #define COMPACT_GOOGLE_LOG_WARNING google::LogMessage( \
393 | __FILE__, __LINE__, google::GLOG_WARNING)
394 | #define LOG_TO_STRING_WARNING(message) google::LogMessage( \
395 | __FILE__, __LINE__, google::GLOG_WARNING, message)
396 | #else
397 | #define COMPACT_GOOGLE_LOG_WARNING google::NullStream()
398 | #define LOG_TO_STRING_WARNING(message) google::NullStream()
399 | #endif
400 |
401 | #if GOOGLE_STRIP_LOG <= 2
402 | #define COMPACT_GOOGLE_LOG_ERROR google::LogMessage( \
403 | __FILE__, __LINE__, google::GLOG_ERROR)
404 | #define LOG_TO_STRING_ERROR(message) google::LogMessage( \
405 | __FILE__, __LINE__, google::GLOG_ERROR, message)
406 | #else
407 | #define COMPACT_GOOGLE_LOG_ERROR google::NullStream()
408 | #define LOG_TO_STRING_ERROR(message) google::NullStream()
409 | #endif
410 |
411 | #if GOOGLE_STRIP_LOG <= 3
412 | #define COMPACT_GOOGLE_LOG_FATAL google::LogMessageFatal( \
413 | __FILE__, __LINE__)
414 | #define LOG_TO_STRING_FATAL(message) google::LogMessage( \
415 | __FILE__, __LINE__, google::GLOG_FATAL, message)
416 | #else
417 | #define COMPACT_GOOGLE_LOG_FATAL google::NullStreamFatal()
418 | #define LOG_TO_STRING_FATAL(message) google::NullStreamFatal()
419 | #endif
420 |
421 | // For DFATAL, we want to use LogMessage (as opposed to
422 | // LogMessageFatal), to be consistent with the original behavior.
423 | #ifdef NDEBUG
424 | #define COMPACT_GOOGLE_LOG_DFATAL COMPACT_GOOGLE_LOG_ERROR
425 | #elif GOOGLE_STRIP_LOG <= 3
426 | #define COMPACT_GOOGLE_LOG_DFATAL google::LogMessage( \
427 | __FILE__, __LINE__, google::GLOG_FATAL)
428 | #else
429 | #define COMPACT_GOOGLE_LOG_DFATAL google::NullStreamFatal()
430 | #endif
431 |
432 | #define GOOGLE_LOG_INFO(counter) google::LogMessage(__FILE__, __LINE__, google::GLOG_INFO, counter, &google::LogMessage::SendToLog)
433 | #define SYSLOG_INFO(counter) \
434 | google::LogMessage(__FILE__, __LINE__, google::GLOG_INFO, counter, \
435 | &google::LogMessage::SendToSyslogAndLog)
436 | #define GOOGLE_LOG_WARNING(counter) \
437 | google::LogMessage(__FILE__, __LINE__, google::GLOG_WARNING, counter, \
438 | &google::LogMessage::SendToLog)
439 | #define SYSLOG_WARNING(counter) \
440 | google::LogMessage(__FILE__, __LINE__, google::GLOG_WARNING, counter, \
441 | &google::LogMessage::SendToSyslogAndLog)
442 | #define GOOGLE_LOG_ERROR(counter) \
443 | google::LogMessage(__FILE__, __LINE__, google::GLOG_ERROR, counter, \
444 | &google::LogMessage::SendToLog)
445 | #define SYSLOG_ERROR(counter) \
446 | google::LogMessage(__FILE__, __LINE__, google::GLOG_ERROR, counter, \
447 | &google::LogMessage::SendToSyslogAndLog)
448 | #define GOOGLE_LOG_FATAL(counter) \
449 | google::LogMessage(__FILE__, __LINE__, google::GLOG_FATAL, counter, \
450 | &google::LogMessage::SendToLog)
451 | #define SYSLOG_FATAL(counter) \
452 | google::LogMessage(__FILE__, __LINE__, google::GLOG_FATAL, counter, \
453 | &google::LogMessage::SendToSyslogAndLog)
454 | #define GOOGLE_LOG_DFATAL(counter) \
455 | google::LogMessage(__FILE__, __LINE__, google::DFATAL_LEVEL, counter, \
456 | &google::LogMessage::SendToLog)
457 | #define SYSLOG_DFATAL(counter) \
458 | google::LogMessage(__FILE__, __LINE__, google::DFATAL_LEVEL, counter, \
459 | &google::LogMessage::SendToSyslogAndLog)
460 |
461 | #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) || defined(__CYGWIN32__)
462 | // A very useful logging macro to log windows errors:
463 | #define LOG_SYSRESULT(result) \
464 | if (FAILED(HRESULT_FROM_WIN32(result))) { \
465 | LPSTR message = NULL; \
466 | LPSTR msg = reinterpret_cast(&message); \
467 | DWORD message_length = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | \
468 | FORMAT_MESSAGE_FROM_SYSTEM, \
469 | 0, result, 0, msg, 100, NULL); \
470 | if (message_length > 0) { \
471 | google::LogMessage(__FILE__, __LINE__, google::GLOG_ERROR, 0, \
472 | &google::LogMessage::SendToLog).stream() \
473 | << reinterpret_cast(message); \
474 | LocalFree(message); \
475 | } \
476 | }
477 | #endif
478 |
479 | // We use the preprocessor's merging operator, "##", so that, e.g.,
480 | // LOG(INFO) becomes the token GOOGLE_LOG_INFO. There's some funny
481 | // subtle difference between ostream member streaming functions (e.g.,
482 | // ostream::operator<<(int) and ostream non-member streaming functions
483 | // (e.g., ::operator<<(ostream&, string&): it turns out that it's
484 | // impossible to stream something like a string directly to an unnamed
485 | // ostream. We employ a neat hack by calling the stream() member
486 | // function of LogMessage which seems to avoid the problem.
487 | #define LOG(severity) COMPACT_GOOGLE_LOG_ ## severity.stream()
488 | #define SYSLOG(severity) SYSLOG_ ## severity(0).stream()
489 |
490 | namespace google {
491 |
492 | // They need the definitions of integer types.
493 | #include "glog/log_severity.h"
494 | #include "glog/vlog_is_on.h"
495 |
496 | // Initialize google's logging library. You will see the program name
497 | // specified by argv0 in log outputs.
498 | GOOGLE_GLOG_DLL_DECL void InitGoogleLogging(const char* argv0);
499 |
500 | // Shutdown google's logging library.
501 | GOOGLE_GLOG_DLL_DECL void ShutdownGoogleLogging();
502 |
503 | // Install a function which will be called after LOG(FATAL).
504 | GOOGLE_GLOG_DLL_DECL void InstallFailureFunction(void (*fail_func)());
505 |
506 | class LogSink; // defined below
507 |
508 | // If a non-NULL sink pointer is given, we push this message to that sink.
509 | // For LOG_TO_SINK we then do normal LOG(severity) logging as well.
510 | // This is useful for capturing messages and passing/storing them
511 | // somewhere more specific than the global log of the process.
512 | // Argument types:
513 | // LogSink* sink;
514 | // LogSeverity severity;
515 | // The cast is to disambiguate NULL arguments.
516 | #define LOG_TO_SINK(sink, severity) \
517 | google::LogMessage( \
518 | __FILE__, __LINE__, \
519 | google::GLOG_ ## severity, \
520 | static_cast(sink), true).stream()
521 | #define LOG_TO_SINK_BUT_NOT_TO_LOGFILE(sink, severity) \
522 | google::LogMessage( \
523 | __FILE__, __LINE__, \
524 | google::GLOG_ ## severity, \
525 | static_cast(sink), false).stream()
526 |
527 | // If a non-NULL string pointer is given, we write this message to that string.
528 | // We then do normal LOG(severity) logging as well.
529 | // This is useful for capturing messages and storing them somewhere more
530 | // specific than the global log of the process.
531 | // Argument types:
532 | // string* message;
533 | // LogSeverity severity;
534 | // The cast is to disambiguate NULL arguments.
535 | // NOTE: LOG(severity) expands to LogMessage().stream() for the specified
536 | // severity.
537 | #define LOG_TO_STRING(severity, message) \
538 | LOG_TO_STRING_##severity(static_cast(message)).stream()
539 |
540 | // If a non-NULL pointer is given, we push the message onto the end
541 | // of a vector of strings; otherwise, we report it with LOG(severity).
542 | // This is handy for capturing messages and perhaps passing them back
543 | // to the caller, rather than reporting them immediately.
544 | // Argument types:
545 | // LogSeverity severity;
546 | // vector *outvec;
547 | // The cast is to disambiguate NULL arguments.
548 | #define LOG_STRING(severity, outvec) \
549 | LOG_TO_STRING_##severity(static_cast*>(outvec)).stream()
550 |
551 | #define LOG_IF(severity, condition) \
552 | !(condition) ? (void) 0 : google::LogMessageVoidify() & LOG(severity)
553 | #define SYSLOG_IF(severity, condition) \
554 | !(condition) ? (void) 0 : google::LogMessageVoidify() & SYSLOG(severity)
555 |
556 | #define LOG_ASSERT(condition) \
557 | LOG_IF(FATAL, !(condition)) << "Assert failed: " #condition
558 | #define SYSLOG_ASSERT(condition) \
559 | SYSLOG_IF(FATAL, !(condition)) << "Assert failed: " #condition
560 |
561 | // CHECK dies with a fatal error if condition is not true. It is *not*
562 | // controlled by NDEBUG, so the check will be executed regardless of
563 | // compilation mode. Therefore, it is safe to do things like:
564 | // CHECK(fp->Write(x) == 4)
565 | #define CHECK(condition) \
566 | LOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN(!(condition))) \
567 | << "Check failed: " #condition " "
568 |
569 | // A container for a string pointer which can be evaluated to a bool -
570 | // true iff the pointer is NULL.
571 | struct CheckOpString {
572 | CheckOpString(std::string* str) : str_(str) { }
573 | // No destructor: if str_ is non-NULL, we're about to LOG(FATAL),
574 | // so there's no point in cleaning up str_.
575 | operator bool() const {
576 | return GOOGLE_PREDICT_BRANCH_NOT_TAKEN(str_ != NULL);
577 | }
578 | std::string* str_;
579 | };
580 |
581 | // Function is overloaded for integral types to allow static const
582 | // integrals declared in classes and not defined to be used as arguments to
583 | // CHECK* macros. It's not encouraged though.
584 | template
585 | inline const T& GetReferenceableValue(const T& t) { return t; }
586 | inline char GetReferenceableValue(char t) { return t; }
587 | inline unsigned char GetReferenceableValue(unsigned char t) { return t; }
588 | inline signed char GetReferenceableValue(signed char t) { return t; }
589 | inline short GetReferenceableValue(short t) { return t; }
590 | inline unsigned short GetReferenceableValue(unsigned short t) { return t; }
591 | inline int GetReferenceableValue(int t) { return t; }
592 | inline unsigned int GetReferenceableValue(unsigned int t) { return t; }
593 | inline long GetReferenceableValue(long t) { return t; }
594 | inline unsigned long GetReferenceableValue(unsigned long t) { return t; }
595 | inline long long GetReferenceableValue(long long t) { return t; }
596 | inline unsigned long long GetReferenceableValue(unsigned long long t) {
597 | return t;
598 | }
599 |
600 | // This is a dummy class to define the following operator.
601 | struct DummyClassToDefineOperator {};
602 |
603 | }
604 |
605 | // Define global operator<< to declare using ::operator<<.
606 | // This declaration will allow use to use CHECK macros for user
607 | // defined classes which have operator<< (e.g., stl_logging.h).
608 | inline std::ostream& operator<<(
609 | std::ostream& out, const google::DummyClassToDefineOperator&) {
610 | return out;
611 | }
612 |
613 | namespace google {
614 |
615 | // This formats a value for a failing CHECK_XX statement. Ordinarily,
616 | // it uses the definition for operator<<, with a few special cases below.
617 | template
618 | inline void MakeCheckOpValueString(std::ostream* os, const T& v) {
619 | (*os) << v;
620 | }
621 |
622 | // Overrides for char types provide readable values for unprintable
623 | // characters.
624 | template <> GOOGLE_GLOG_DLL_DECL
625 | void MakeCheckOpValueString(std::ostream* os, const char& v);
626 | template <> GOOGLE_GLOG_DLL_DECL
627 | void MakeCheckOpValueString(std::ostream* os, const signed char& v);
628 | template <> GOOGLE_GLOG_DLL_DECL
629 | void MakeCheckOpValueString(std::ostream* os, const unsigned char& v);
630 |
631 | // Build the error message string. Specify no inlining for code size.
632 | template
633 | std::string* MakeCheckOpString(const T1& v1, const T2& v2, const char* exprtext)
634 | ;
635 |
636 | namespace base {
637 | namespace internal {
638 |
639 | // If "s" is less than base_logging::INFO, returns base_logging::INFO.
640 | // If "s" is greater than base_logging::FATAL, returns
641 | // base_logging::ERROR. Otherwise, returns "s".
642 | LogSeverity NormalizeSeverity(LogSeverity s);
643 |
644 | } // namespace internal
645 |
646 | // A helper class for formatting "expr (V1 vs. V2)" in a CHECK_XX
647 | // statement. See MakeCheckOpString for sample usage. Other
648 | // approaches were considered: use of a template method (e.g.,
649 | // base::BuildCheckOpString(exprtext, base::Print, &v1,
650 | // base::Print, &v2), however this approach has complications
651 | // related to volatile arguments and function-pointer arguments).
652 | class GOOGLE_GLOG_DLL_DECL CheckOpMessageBuilder {
653 | public:
654 | // Inserts "exprtext" and " (" to the stream.
655 | explicit CheckOpMessageBuilder(const char *exprtext);
656 | // Deletes "stream_".
657 | ~CheckOpMessageBuilder();
658 | // For inserting the first variable.
659 | std::ostream* ForVar1() { return stream_; }
660 | // For inserting the second variable (adds an intermediate " vs. ").
661 | std::ostream* ForVar2();
662 | // Get the result (inserts the closing ")").
663 | std::string* NewString();
664 |
665 | private:
666 | std::ostringstream *stream_;
667 | };
668 |
669 | } // namespace base
670 |
671 | template
672 | std::string* MakeCheckOpString(const T1& v1, const T2& v2, const char* exprtext) {
673 | base::CheckOpMessageBuilder comb(exprtext);
674 | MakeCheckOpValueString(comb.ForVar1(), v1);
675 | MakeCheckOpValueString(comb.ForVar2(), v2);
676 | return comb.NewString();
677 | }
678 |
679 | // Helper functions for CHECK_OP macro.
680 | // The (int, int) specialization works around the issue that the compiler
681 | // will not instantiate the template version of the function on values of
682 | // unnamed enum type - see comment below.
683 | #define DEFINE_CHECK_OP_IMPL(name, op) \
684 | template \
685 | inline std::string* name##Impl(const T1& v1, const T2& v2, \
686 | const char* exprtext) { \
687 | if (GOOGLE_PREDICT_TRUE(v1 op v2)) return NULL; \
688 | else return MakeCheckOpString(v1, v2, exprtext); \
689 | } \
690 | inline std::string* name##Impl(int v1, int v2, const char* exprtext) { \
691 | return name##Impl(v1, v2, exprtext); \
692 | }
693 |
694 | // We use the full name Check_EQ, Check_NE, etc. in case the file including
695 | // base/logging.h provides its own #defines for the simpler names EQ, NE, etc.
696 | // This happens if, for example, those are used as token names in a
697 | // yacc grammar.
698 | DEFINE_CHECK_OP_IMPL(Check_EQ, ==) // Compilation error with CHECK_EQ(NULL, x)?
699 | DEFINE_CHECK_OP_IMPL(Check_NE, !=) // Use CHECK(x == NULL) instead.
700 | DEFINE_CHECK_OP_IMPL(Check_LE, <=)
701 | DEFINE_CHECK_OP_IMPL(Check_LT, < )
702 | DEFINE_CHECK_OP_IMPL(Check_GE, >=)
703 | DEFINE_CHECK_OP_IMPL(Check_GT, > )
704 | #undef DEFINE_CHECK_OP_IMPL
705 |
706 | // Helper macro for binary operators.
707 | // Don't use this macro directly in your code, use CHECK_EQ et al below.
708 |
709 | #if defined(STATIC_ANALYSIS)
710 | // Only for static analysis tool to know that it is equivalent to assert
711 | #define CHECK_OP_LOG(name, op, val1, val2, log) CHECK((val1) op (val2))
712 | #elif !defined(NDEBUG)
713 | // In debug mode, avoid constructing CheckOpStrings if possible,
714 | // to reduce the overhead of CHECK statments by 2x.
715 | // Real DCHECK-heavy tests have seen 1.5x speedups.
716 |
717 | // The meaning of "string" might be different between now and
718 | // when this macro gets invoked (e.g., if someone is experimenting
719 | // with other string implementations that get defined after this
720 | // file is included). Save the current meaning now and use it
721 | // in the macro.
722 | typedef std::string _Check_string;
723 | #define CHECK_OP_LOG(name, op, val1, val2, log) \
724 | while (google::_Check_string* _result = \
725 | google::Check##name##Impl( \
726 | google::GetReferenceableValue(val1), \
727 | google::GetReferenceableValue(val2), \
728 | #val1 " " #op " " #val2)) \
729 | log(__FILE__, __LINE__, \
730 | google::CheckOpString(_result)).stream()
731 | #else
732 | // In optimized mode, use CheckOpString to hint to compiler that
733 | // the while condition is unlikely.
734 | #define CHECK_OP_LOG(name, op, val1, val2, log) \
735 | while (google::CheckOpString _result = \
736 | google::Check##name##Impl( \
737 | google::GetReferenceableValue(val1), \
738 | google::GetReferenceableValue(val2), \
739 | #val1 " " #op " " #val2)) \
740 | log(__FILE__, __LINE__, _result).stream()
741 | #endif // STATIC_ANALYSIS, !NDEBUG
742 |
743 | #if GOOGLE_STRIP_LOG <= 3
744 | #define CHECK_OP(name, op, val1, val2) \
745 | CHECK_OP_LOG(name, op, val1, val2, google::LogMessageFatal)
746 | #else
747 | #define CHECK_OP(name, op, val1, val2) \
748 | CHECK_OP_LOG(name, op, val1, val2, google::NullStreamFatal)
749 | #endif // STRIP_LOG <= 3
750 |
751 | // Equality/Inequality checks - compare two values, and log a FATAL message
752 | // including the two values when the result is not as expected. The values
753 | // must have operator<<(ostream, ...) defined.
754 | //
755 | // You may append to the error message like so:
756 | // CHECK_NE(1, 2) << ": The world must be ending!";
757 | //
758 | // We are very careful to ensure that each argument is evaluated exactly
759 | // once, and that anything which is legal to pass as a function argument is
760 | // legal here. In particular, the arguments may be temporary expressions
761 | // which will end up being destroyed at the end of the apparent statement,
762 | // for example:
763 | // CHECK_EQ(string("abc")[1], 'b');
764 | //
765 | // WARNING: These don't compile correctly if one of the arguments is a pointer
766 | // and the other is NULL. To work around this, simply static_cast NULL to the
767 | // type of the desired pointer.
768 |
769 | #define CHECK_EQ(val1, val2) CHECK_OP(_EQ, ==, val1, val2)
770 | #define CHECK_NE(val1, val2) CHECK_OP(_NE, !=, val1, val2)
771 | #define CHECK_LE(val1, val2) CHECK_OP(_LE, <=, val1, val2)
772 | #define CHECK_LT(val1, val2) CHECK_OP(_LT, < , val1, val2)
773 | #define CHECK_GE(val1, val2) CHECK_OP(_GE, >=, val1, val2)
774 | #define CHECK_GT(val1, val2) CHECK_OP(_GT, > , val1, val2)
775 |
776 | // Check that the input is non NULL. This very useful in constructor
777 | // initializer lists.
778 |
779 | #define CHECK_NOTNULL(val) \
780 | google::CheckNotNull(__FILE__, __LINE__, "'" #val "' Must be non NULL", (val))
781 |
782 | // Helper functions for string comparisons.
783 | // To avoid bloat, the definitions are in logging.cc.
784 | #define DECLARE_CHECK_STROP_IMPL(func, expected) \
785 | GOOGLE_GLOG_DLL_DECL std::string* Check##func##expected##Impl( \
786 | const char* s1, const char* s2, const char* names);
787 | DECLARE_CHECK_STROP_IMPL(strcmp, true)
788 | DECLARE_CHECK_STROP_IMPL(strcmp, false)
789 | DECLARE_CHECK_STROP_IMPL(strcasecmp, true)
790 | DECLARE_CHECK_STROP_IMPL(strcasecmp, false)
791 | #undef DECLARE_CHECK_STROP_IMPL
792 |
793 | // Helper macro for string comparisons.
794 | // Don't use this macro directly in your code, use CHECK_STREQ et al below.
795 | #define CHECK_STROP(func, op, expected, s1, s2) \
796 | while (google::CheckOpString _result = \
797 | google::Check##func##expected##Impl((s1), (s2), \
798 | #s1 " " #op " " #s2)) \
799 | LOG(FATAL) << *_result.str_
800 |
801 |
802 | // String (char*) equality/inequality checks.
803 | // CASE versions are case-insensitive.
804 | //
805 | // Note that "s1" and "s2" may be temporary strings which are destroyed
806 | // by the compiler at the end of the current "full expression"
807 | // (e.g. CHECK_STREQ(Foo().c_str(), Bar().c_str())).
808 |
809 | #define CHECK_STREQ(s1, s2) CHECK_STROP(strcmp, ==, true, s1, s2)
810 | #define CHECK_STRNE(s1, s2) CHECK_STROP(strcmp, !=, false, s1, s2)
811 | #define CHECK_STRCASEEQ(s1, s2) CHECK_STROP(strcasecmp, ==, true, s1, s2)
812 | #define CHECK_STRCASENE(s1, s2) CHECK_STROP(strcasecmp, !=, false, s1, s2)
813 |
814 | #define CHECK_INDEX(I,A) CHECK(I < (sizeof(A)/sizeof(A[0])))
815 | #define CHECK_BOUND(B,A) CHECK(B <= (sizeof(A)/sizeof(A[0])))
816 |
817 | #define CHECK_DOUBLE_EQ(val1, val2) \
818 | do { \
819 | CHECK_LE((val1), (val2)+0.000000000000001L); \
820 | CHECK_GE((val1), (val2)-0.000000000000001L); \
821 | } while (0)
822 |
823 | #define CHECK_NEAR(val1, val2, margin) \
824 | do { \
825 | CHECK_LE((val1), (val2)+(margin)); \
826 | CHECK_GE((val1), (val2)-(margin)); \
827 | } while (0)
828 |
829 | // perror()..googly style!
830 | //
831 | // PLOG() and PLOG_IF() and PCHECK() behave exactly like their LOG* and
832 | // CHECK equivalents with the addition that they postpend a description
833 | // of the current state of errno to their output lines.
834 |
835 | #define PLOG(severity) GOOGLE_PLOG(severity, 0).stream()
836 |
837 | #define GOOGLE_PLOG(severity, counter) \
838 | google::ErrnoLogMessage( \
839 | __FILE__, __LINE__, google::GLOG_ ## severity, counter, \
840 | &google::LogMessage::SendToLog)
841 |
842 | #define PLOG_IF(severity, condition) \
843 | !(condition) ? (void) 0 : google::LogMessageVoidify() & PLOG(severity)
844 |
845 | // A CHECK() macro that postpends errno if the condition is false. E.g.
846 | //
847 | // if (poll(fds, nfds, timeout) == -1) { PCHECK(errno == EINTR); ... }
848 | #define PCHECK(condition) \
849 | PLOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN(!(condition))) \
850 | << "Check failed: " #condition " "
851 |
852 | // A CHECK() macro that lets you assert the success of a function that
853 | // returns -1 and sets errno in case of an error. E.g.
854 | //
855 | // CHECK_ERR(mkdir(path, 0700));
856 | //
857 | // or
858 | //
859 | // int fd = open(filename, flags); CHECK_ERR(fd) << ": open " << filename;
860 | #define CHECK_ERR(invocation) \
861 | PLOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN((invocation) == -1)) \
862 | << #invocation
863 |
864 | // Use macro expansion to create, for each use of LOG_EVERY_N(), static
865 | // variables with the __LINE__ expansion as part of the variable name.
866 | #define LOG_EVERY_N_VARNAME(base, line) LOG_EVERY_N_VARNAME_CONCAT(base, line)
867 | #define LOG_EVERY_N_VARNAME_CONCAT(base, line) base ## line
868 |
869 | #define LOG_OCCURRENCES LOG_EVERY_N_VARNAME(occurrences_, __LINE__)
870 | #define LOG_OCCURRENCES_MOD_N LOG_EVERY_N_VARNAME(occurrences_mod_n_, __LINE__)
871 |
872 | #define SOME_KIND_OF_LOG_EVERY_N(severity, n, what_to_do) \
873 | static int LOG_OCCURRENCES = 0, LOG_OCCURRENCES_MOD_N = 0; \
874 | ++LOG_OCCURRENCES; \
875 | if (++LOG_OCCURRENCES_MOD_N > n) LOG_OCCURRENCES_MOD_N -= n; \
876 | if (LOG_OCCURRENCES_MOD_N == 1) \
877 | google::LogMessage( \
878 | __FILE__, __LINE__, google::GLOG_ ## severity, LOG_OCCURRENCES, \
879 | &what_to_do).stream()
880 |
881 | #define SOME_KIND_OF_LOG_IF_EVERY_N(severity, condition, n, what_to_do) \
882 | static int LOG_OCCURRENCES = 0, LOG_OCCURRENCES_MOD_N = 0; \
883 | ++LOG_OCCURRENCES; \
884 | if (condition && \
885 | ((LOG_OCCURRENCES_MOD_N=(LOG_OCCURRENCES_MOD_N + 1) % n) == (1 % n))) \
886 | google::LogMessage( \
887 | __FILE__, __LINE__, google::GLOG_ ## severity, LOG_OCCURRENCES, \
888 | &what_to_do).stream()
889 |
890 | #define SOME_KIND_OF_PLOG_EVERY_N(severity, n, what_to_do) \
891 | static int LOG_OCCURRENCES = 0, LOG_OCCURRENCES_MOD_N = 0; \
892 | ++LOG_OCCURRENCES; \
893 | if (++LOG_OCCURRENCES_MOD_N > n) LOG_OCCURRENCES_MOD_N -= n; \
894 | if (LOG_OCCURRENCES_MOD_N == 1) \
895 | google::ErrnoLogMessage( \
896 | __FILE__, __LINE__, google::GLOG_ ## severity, LOG_OCCURRENCES, \
897 | &what_to_do).stream()
898 |
899 | #define SOME_KIND_OF_LOG_FIRST_N(severity, n, what_to_do) \
900 | static int LOG_OCCURRENCES = 0; \
901 | if (LOG_OCCURRENCES <= n) \
902 | ++LOG_OCCURRENCES; \
903 | if (LOG_OCCURRENCES <= n) \
904 | google::LogMessage( \
905 | __FILE__, __LINE__, google::GLOG_ ## severity, LOG_OCCURRENCES, \
906 | &what_to_do).stream()
907 |
908 | namespace glog_internal_namespace_ {
909 | template
910 | struct CompileAssert {
911 | };
912 | struct CrashReason;
913 | } // namespace glog_internal_namespace_
914 |
915 | #define GOOGLE_GLOG_COMPILE_ASSERT(expr, msg) \
916 | typedef google::glog_internal_namespace_::CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1]
917 |
918 | #define LOG_EVERY_N(severity, n) \
919 | GOOGLE_GLOG_COMPILE_ASSERT(google::GLOG_ ## severity < \
920 | google::NUM_SEVERITIES, \
921 | INVALID_REQUESTED_LOG_SEVERITY); \
922 | SOME_KIND_OF_LOG_EVERY_N(severity, (n), google::LogMessage::SendToLog)
923 |
924 | #define SYSLOG_EVERY_N(severity, n) \
925 | SOME_KIND_OF_LOG_EVERY_N(severity, (n), google::LogMessage::SendToSyslogAndLog)
926 |
927 | #define PLOG_EVERY_N(severity, n) \
928 | SOME_KIND_OF_PLOG_EVERY_N(severity, (n), google::LogMessage::SendToLog)
929 |
930 | #define LOG_FIRST_N(severity, n) \
931 | SOME_KIND_OF_LOG_FIRST_N(severity, (n), google::LogMessage::SendToLog)
932 |
933 | #define LOG_IF_EVERY_N(severity, condition, n) \
934 | SOME_KIND_OF_LOG_IF_EVERY_N(severity, (condition), (n), google::LogMessage::SendToLog)
935 |
936 | // We want the special COUNTER value available for LOG_EVERY_X()'ed messages
937 | enum PRIVATE_Counter {COUNTER};
938 |
939 | #ifdef GLOG_NO_ABBREVIATED_SEVERITIES
940 | // wingdi.h defines ERROR to be 0. When we call LOG(ERROR), it gets
941 | // substituted with 0, and it expands to COMPACT_GOOGLE_LOG_0. To allow us
942 | // to keep using this syntax, we define this macro to do the same thing
943 | // as COMPACT_GOOGLE_LOG_ERROR.
944 | #define COMPACT_GOOGLE_LOG_0 COMPACT_GOOGLE_LOG_ERROR
945 | #define SYSLOG_0 SYSLOG_ERROR
946 | #define LOG_TO_STRING_0 LOG_TO_STRING_ERROR
947 | // Needed for LOG_IS_ON(ERROR).
948 | const LogSeverity GLOG_0 = GLOG_ERROR;
949 | #else
950 | // Users may include windows.h after logging.h without
951 | // GLOG_NO_ABBREVIATED_SEVERITIES nor WIN32_LEAN_AND_MEAN.
952 | // For this case, we cannot detect if ERROR is defined before users
953 | // actually use ERROR. Let's make an undefined symbol to warn users.
954 | # define GLOG_ERROR_MSG ERROR_macro_is_defined_Define_GLOG_NO_ABBREVIATED_SEVERITIES_before_including_logging_h_See_the_document_for_detail
955 | # define COMPACT_GOOGLE_LOG_0 GLOG_ERROR_MSG
956 | # define SYSLOG_0 GLOG_ERROR_MSG
957 | # define LOG_TO_STRING_0 GLOG_ERROR_MSG
958 | # define GLOG_0 GLOG_ERROR_MSG
959 | #endif
960 |
961 | // Plus some debug-logging macros that get compiled to nothing for production
962 |
963 | #ifndef NDEBUG
964 |
965 | #define DLOG(severity) LOG(severity)
966 | #define DVLOG(verboselevel) VLOG(verboselevel)
967 | #define DLOG_IF(severity, condition) LOG_IF(severity, condition)
968 | #define DLOG_EVERY_N(severity, n) LOG_EVERY_N(severity, n)
969 | #define DLOG_IF_EVERY_N(severity, condition, n) \
970 | LOG_IF_EVERY_N(severity, condition, n)
971 | #define DLOG_ASSERT(condition) LOG_ASSERT(condition)
972 |
973 | // debug-only checking. not executed in NDEBUG mode.
974 | #define DCHECK(condition) CHECK(condition)
975 | #define DCHECK_EQ(val1, val2) CHECK_EQ(val1, val2)
976 | #define DCHECK_NE(val1, val2) CHECK_NE(val1, val2)
977 | #define DCHECK_LE(val1, val2) CHECK_LE(val1, val2)
978 | #define DCHECK_LT(val1, val2) CHECK_LT(val1, val2)
979 | #define DCHECK_GE(val1, val2) CHECK_GE(val1, val2)
980 | #define DCHECK_GT(val1, val2) CHECK_GT(val1, val2)
981 | #define DCHECK_NOTNULL(val) CHECK_NOTNULL(val)
982 | #define DCHECK_STREQ(str1, str2) CHECK_STREQ(str1, str2)
983 | #define DCHECK_STRCASEEQ(str1, str2) CHECK_STRCASEEQ(str1, str2)
984 | #define DCHECK_STRNE(str1, str2) CHECK_STRNE(str1, str2)
985 | #define DCHECK_STRCASENE(str1, str2) CHECK_STRCASENE(str1, str2)
986 |
987 | #else // NDEBUG
988 |
989 | #define DLOG(severity) \
990 | true ? (void) 0 : google::LogMessageVoidify() & LOG(severity)
991 |
992 | #define DVLOG(verboselevel) \
993 | (true || !VLOG_IS_ON(verboselevel)) ?\
994 | (void) 0 : google::LogMessageVoidify() & LOG(INFO)
995 |
996 | #define DLOG_IF(severity, condition) \
997 | (true || !(condition)) ? (void) 0 : google::LogMessageVoidify() & LOG(severity)
998 |
999 | #define DLOG_EVERY_N(severity, n) \
1000 | true ? (void) 0 : google::LogMessageVoidify() & LOG(severity)
1001 |
1002 | #define DLOG_IF_EVERY_N(severity, condition, n) \
1003 | (true || !(condition))? (void) 0 : google::LogMessageVoidify() & LOG(severity)
1004 |
1005 | #define DLOG_ASSERT(condition) \
1006 | true ? (void) 0 : LOG_ASSERT(condition)
1007 |
1008 | // MSVC warning C4127: conditional expression is constant
1009 | #define DCHECK(condition) \
1010 | GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
1011 | while (false) \
1012 | GLOG_MSVC_POP_WARNING() CHECK(condition)
1013 |
1014 | #define DCHECK_EQ(val1, val2) \
1015 | GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
1016 | while (false) \
1017 | GLOG_MSVC_POP_WARNING() CHECK_EQ(val1, val2)
1018 |
1019 | #define DCHECK_NE(val1, val2) \
1020 | GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
1021 | while (false) \
1022 | GLOG_MSVC_POP_WARNING() CHECK_NE(val1, val2)
1023 |
1024 | #define DCHECK_LE(val1, val2) \
1025 | GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
1026 | while (false) \
1027 | GLOG_MSVC_POP_WARNING() CHECK_LE(val1, val2)
1028 |
1029 | #define DCHECK_LT(val1, val2) \
1030 | GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
1031 | while (false) \
1032 | GLOG_MSVC_POP_WARNING() CHECK_LT(val1, val2)
1033 |
1034 | #define DCHECK_GE(val1, val2) \
1035 | GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
1036 | while (false) \
1037 | GLOG_MSVC_POP_WARNING() CHECK_GE(val1, val2)
1038 |
1039 | #define DCHECK_GT(val1, val2) \
1040 | GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
1041 | while (false) \
1042 | GLOG_MSVC_POP_WARNING() CHECK_GT(val1, val2)
1043 |
1044 | // You may see warnings in release mode if you don't use the return
1045 | // value of DCHECK_NOTNULL. Please just use DCHECK for such cases.
1046 | #define DCHECK_NOTNULL(val) (val)
1047 |
1048 | #define DCHECK_STREQ(str1, str2) \
1049 | GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
1050 | while (false) \
1051 | GLOG_MSVC_POP_WARNING() CHECK_STREQ(str1, str2)
1052 |
1053 | #define DCHECK_STRCASEEQ(str1, str2) \
1054 | GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
1055 | while (false) \
1056 | GLOG_MSVC_POP_WARNING() CHECK_STRCASEEQ(str1, str2)
1057 |
1058 | #define DCHECK_STRNE(str1, str2) \
1059 | GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
1060 | while (false) \
1061 | GLOG_MSVC_POP_WARNING() CHECK_STRNE(str1, str2)
1062 |
1063 | #define DCHECK_STRCASENE(str1, str2) \
1064 | GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
1065 | while (false) \
1066 | GLOG_MSVC_POP_WARNING() CHECK_STRCASENE(str1, str2)
1067 |
1068 | #endif // NDEBUG
1069 |
1070 | // Log only in verbose mode.
1071 |
1072 | #define VLOG(verboselevel) LOG_IF(INFO, VLOG_IS_ON(verboselevel))
1073 |
1074 | #define VLOG_IF(verboselevel, condition) \
1075 | LOG_IF(INFO, (condition) && VLOG_IS_ON(verboselevel))
1076 |
1077 | #define VLOG_EVERY_N(verboselevel, n) \
1078 | LOG_IF_EVERY_N(INFO, VLOG_IS_ON(verboselevel), n)
1079 |
1080 | #define VLOG_IF_EVERY_N(verboselevel, condition, n) \
1081 | LOG_IF_EVERY_N(INFO, (condition) && VLOG_IS_ON(verboselevel), n)
1082 |
1083 | namespace base_logging {
1084 |
1085 | // LogMessage::LogStream is a std::ostream backed by this streambuf.
1086 | // This class ignores overflow and leaves two bytes at the end of the
1087 | // buffer to allow for a '\n' and '\0'.
1088 | class LogStreamBuf : public std::streambuf {
1089 | public:
1090 | // REQUIREMENTS: "len" must be >= 2 to account for the '\n' and '\n'.
1091 | LogStreamBuf(char *buf, int len) {
1092 | setp(buf, buf + len - 2);
1093 | }
1094 | // This effectively ignores overflow.
1095 | virtual int_type overflow(int_type ch) {
1096 | return ch;
1097 | }
1098 |
1099 | // Legacy public ostrstream method.
1100 | size_t pcount() const { return pptr() - pbase(); }
1101 | char* pbase() const { return std::streambuf::pbase(); }
1102 | };
1103 |
1104 | } // namespace base_logging
1105 |
1106 | //
1107 | // This class more or less represents a particular log message. You
1108 | // create an instance of LogMessage and then stream stuff to it.
1109 | // When you finish streaming to it, ~LogMessage is called and the
1110 | // full message gets streamed to the appropriate destination.
1111 | //
1112 | // You shouldn't actually use LogMessage's constructor to log things,
1113 | // though. You should use the LOG() macro (and variants thereof)
1114 | // above.
1115 | class GOOGLE_GLOG_DLL_DECL LogMessage {
1116 | public:
1117 | enum {
1118 | // Passing kNoLogPrefix for the line number disables the
1119 | // log-message prefix. Useful for using the LogMessage
1120 | // infrastructure as a printing utility. See also the --log_prefix
1121 | // flag for controlling the log-message prefix on an
1122 | // application-wide basis.
1123 | kNoLogPrefix = -1
1124 | };
1125 |
1126 | // LogStream inherit from non-DLL-exported class (std::ostrstream)
1127 | // and VC++ produces a warning for this situation.
1128 | // However, MSDN says "C4275 can be ignored in Microsoft Visual C++
1129 | // 2005 if you are deriving from a type in the Standard C++ Library"
1130 | // http://msdn.microsoft.com/en-us/library/3tdb471s(VS.80).aspx
1131 | // Let's just ignore the warning.
1132 | #ifdef _MSC_VER
1133 | # pragma warning(disable: 4275)
1134 | #endif
1135 | class GOOGLE_GLOG_DLL_DECL LogStream : public std::ostream {
1136 | #ifdef _MSC_VER
1137 | # pragma warning(default: 4275)
1138 | #endif
1139 | public:
1140 | LogStream(char *buf, int len, int ctr)
1141 | : std::ostream(NULL),
1142 | streambuf_(buf, len),
1143 | ctr_(ctr),
1144 | self_(this) {
1145 | rdbuf(&streambuf_);
1146 | }
1147 |
1148 | int ctr() const { return ctr_; }
1149 | void set_ctr(int ctr) { ctr_ = ctr; }
1150 | LogStream* self() const { return self_; }
1151 |
1152 | // Legacy std::streambuf methods.
1153 | size_t pcount() const { return streambuf_.pcount(); }
1154 | char* pbase() const { return streambuf_.pbase(); }
1155 | char* str() const { return pbase(); }
1156 |
1157 | private:
1158 | base_logging::LogStreamBuf streambuf_;
1159 | int ctr_; // Counter hack (for the LOG_EVERY_X() macro)
1160 | LogStream *self_; // Consistency check hack
1161 | };
1162 |
1163 | public:
1164 | // icc 8 requires this typedef to avoid an internal compiler error.
1165 | typedef void (LogMessage::*SendMethod)();
1166 |
1167 | LogMessage(const char* file, int line, LogSeverity severity, int ctr,
1168 | SendMethod send_method);
1169 |
1170 | // Two special constructors that generate reduced amounts of code at
1171 | // LOG call sites for common cases.
1172 |
1173 | // Used for LOG(INFO): Implied are:
1174 | // severity = INFO, ctr = 0, send_method = &LogMessage::SendToLog.
1175 | //
1176 | // Using this constructor instead of the more complex constructor above
1177 | // saves 19 bytes per call site.
1178 | LogMessage(const char* file, int line);
1179 |
1180 | // Used for LOG(severity) where severity != INFO. Implied
1181 | // are: ctr = 0, send_method = &LogMessage::SendToLog
1182 | //
1183 | // Using this constructor instead of the more complex constructor above
1184 | // saves 17 bytes per call site.
1185 | LogMessage(const char* file, int line, LogSeverity severity);
1186 |
1187 | // Constructor to log this message to a specified sink (if not NULL).
1188 | // Implied are: ctr = 0, send_method = &LogMessage::SendToSinkAndLog if
1189 | // also_send_to_log is true, send_method = &LogMessage::SendToSink otherwise.
1190 | LogMessage(const char* file, int line, LogSeverity severity, LogSink* sink,
1191 | bool also_send_to_log);
1192 |
1193 | // Constructor where we also give a vector pointer
1194 | // for storing the messages (if the pointer is not NULL).
1195 | // Implied are: ctr = 0, send_method = &LogMessage::SaveOrSendToLog.
1196 | LogMessage(const char* file, int line, LogSeverity severity,
1197 | std::vector* outvec);
1198 |
1199 | // Constructor where we also give a string pointer for storing the
1200 | // message (if the pointer is not NULL). Implied are: ctr = 0,
1201 | // send_method = &LogMessage::WriteToStringAndLog.
1202 | LogMessage(const char* file, int line, LogSeverity severity,
1203 | std::string* message);
1204 |
1205 | // A special constructor used for check failures
1206 | LogMessage(const char* file, int line, const CheckOpString& result);
1207 |
1208 | ~LogMessage();
1209 |
1210 | // Flush a buffered message to the sink set in the constructor. Always
1211 | // called by the destructor, it may also be called from elsewhere if
1212 | // needed. Only the first call is actioned; any later ones are ignored.
1213 | void Flush();
1214 |
1215 | // An arbitrary limit on the length of a single log message. This
1216 | // is so that streaming can be done more efficiently.
1217 | static const size_t kMaxLogMessageLen;
1218 |
1219 | // Theses should not be called directly outside of logging.*,
1220 | // only passed as SendMethod arguments to other LogMessage methods:
1221 | void SendToLog(); // Actually dispatch to the logs
1222 | void SendToSyslogAndLog(); // Actually dispatch to syslog and the logs
1223 |
1224 | // Call abort() or similar to perform LOG(FATAL) crash.
1225 | static void Fail() ;
1226 |
1227 | std::ostream& stream();
1228 |
1229 | int preserved_errno() const;
1230 |
1231 | // Must be called without the log_mutex held. (L < log_mutex)
1232 | static int64 num_messages(int severity);
1233 |
1234 | struct LogMessageData;
1235 |
1236 | private:
1237 | // Fully internal SendMethod cases:
1238 | void SendToSinkAndLog(); // Send to sink if provided and dispatch to the logs
1239 | void SendToSink(); // Send to sink if provided, do nothing otherwise.
1240 |
1241 | // Write to string if provided and dispatch to the logs.
1242 | void WriteToStringAndLog();
1243 |
1244 | void SaveOrSendToLog(); // Save to stringvec if provided, else to logs
1245 |
1246 | void Init(const char* file, int line, LogSeverity severity,
1247 | void (LogMessage::*send_method)());
1248 |
1249 | // Used to fill in crash information during LOG(FATAL) failures.
1250 | void RecordCrashReason(glog_internal_namespace_::CrashReason* reason);
1251 |
1252 | // Counts of messages sent at each priority:
1253 | static int64 num_messages_[NUM_SEVERITIES]; // under log_mutex
1254 |
1255 | // We keep the data in a separate struct so that each instance of
1256 | // LogMessage uses less stack space.
1257 | LogMessageData* allocated_;
1258 | LogMessageData* data_;
1259 |
1260 | friend class LogDestination;
1261 |
1262 | LogMessage(const LogMessage&);
1263 | void operator=(const LogMessage&);
1264 | };
1265 |
1266 | // This class happens to be thread-hostile because all instances share
1267 | // a single data buffer, but since it can only be created just before
1268 | // the process dies, we don't worry so much.
1269 | class GOOGLE_GLOG_DLL_DECL LogMessageFatal : public LogMessage {
1270 | public:
1271 | LogMessageFatal(const char* file, int line);
1272 | LogMessageFatal(const char* file, int line, const CheckOpString& result);
1273 | ~LogMessageFatal() ;
1274 | };
1275 |
1276 | // A non-macro interface to the log facility; (useful
1277 | // when the logging level is not a compile-time constant).
1278 | inline void LogAtLevel(int const severity, std::string const &msg) {
1279 | LogMessage(__FILE__, __LINE__, severity).stream() << msg;
1280 | }
1281 |
1282 | // A macro alternative of LogAtLevel. New code may want to use this
1283 | // version since there are two advantages: 1. this version outputs the
1284 | // file name and the line number where this macro is put like other
1285 | // LOG macros, 2. this macro can be used as C++ stream.
1286 | #define LOG_AT_LEVEL(severity) google::LogMessage(__FILE__, __LINE__, severity).stream()
1287 |
1288 | // A small helper for CHECK_NOTNULL().
1289 | template
1290 | T* CheckNotNull(const char *file, int line, const char *names, T* t) {
1291 | if (t == NULL) {
1292 | LogMessageFatal(file, line, new std::string(names));
1293 | }
1294 | return t;
1295 | }
1296 |
1297 | // Allow folks to put a counter in the LOG_EVERY_X()'ed messages. This
1298 | // only works if ostream is a LogStream. If the ostream is not a
1299 | // LogStream you'll get an assert saying as much at runtime.
1300 | GOOGLE_GLOG_DLL_DECL std::ostream& operator<<(std::ostream &os,
1301 | const PRIVATE_Counter&);
1302 |
1303 |
1304 | // Derived class for PLOG*() above.
1305 | class GOOGLE_GLOG_DLL_DECL ErrnoLogMessage : public LogMessage {
1306 | public:
1307 |
1308 | ErrnoLogMessage(const char* file, int line, LogSeverity severity, int ctr,
1309 | void (LogMessage::*send_method)());
1310 |
1311 | // Postpends ": strerror(errno) [errno]".
1312 | ~ErrnoLogMessage();
1313 |
1314 | private:
1315 | ErrnoLogMessage(const ErrnoLogMessage&);
1316 | void operator=(const ErrnoLogMessage&);
1317 | };
1318 |
1319 |
1320 | // This class is used to explicitly ignore values in the conditional
1321 | // logging macros. This avoids compiler warnings like "value computed
1322 | // is not used" and "statement has no effect".
1323 |
1324 | class GOOGLE_GLOG_DLL_DECL LogMessageVoidify {
1325 | public:
1326 | LogMessageVoidify() { }
1327 | // This has to be an operator with a precedence lower than << but
1328 | // higher than ?:
1329 | void operator&(std::ostream&) { }
1330 | };
1331 |
1332 |
1333 | // Flushes all log files that contains messages that are at least of
1334 | // the specified severity level. Thread-safe.
1335 | GOOGLE_GLOG_DLL_DECL void FlushLogFiles(LogSeverity min_severity);
1336 |
1337 | // Flushes all log files that contains messages that are at least of
1338 | // the specified severity level. Thread-hostile because it ignores
1339 | // locking -- used for catastrophic failures.
1340 | GOOGLE_GLOG_DLL_DECL void FlushLogFilesUnsafe(LogSeverity min_severity);
1341 |
1342 | //
1343 | // Set the destination to which a particular severity level of log
1344 | // messages is sent. If base_filename is "", it means "don't log this
1345 | // severity". Thread-safe.
1346 | //
1347 | GOOGLE_GLOG_DLL_DECL void SetLogDestination(LogSeverity severity,
1348 | const char* base_filename);
1349 |
1350 | //
1351 | // Set the basename of the symlink to the latest log file at a given
1352 | // severity. If symlink_basename is empty, do not make a symlink. If
1353 | // you don't call this function, the symlink basename is the
1354 | // invocation name of the program. Thread-safe.
1355 | //
1356 | GOOGLE_GLOG_DLL_DECL void SetLogSymlink(LogSeverity severity,
1357 | const char* symlink_basename);
1358 |
1359 | //
1360 | // Used to send logs to some other kind of destination
1361 | // Users should subclass LogSink and override send to do whatever they want.
1362 | // Implementations must be thread-safe because a shared instance will
1363 | // be called from whichever thread ran the LOG(XXX) line.
1364 | class GOOGLE_GLOG_DLL_DECL LogSink {
1365 | public:
1366 | virtual ~LogSink();
1367 |
1368 | // Sink's logging logic (message_len is such as to exclude '\n' at the end).
1369 | // This method can't use LOG() or CHECK() as logging system mutex(s) are held
1370 | // during this call.
1371 | virtual void send(LogSeverity severity, const char* full_filename,
1372 | const char* base_filename, int line,
1373 | const struct ::tm* tm_time,
1374 | const char* message, size_t message_len) = 0;
1375 |
1376 | // Redefine this to implement waiting for
1377 | // the sink's logging logic to complete.
1378 | // It will be called after each send() returns,
1379 | // but before that LogMessage exits or crashes.
1380 | // By default this function does nothing.
1381 | // Using this function one can implement complex logic for send()
1382 | // that itself involves logging; and do all this w/o causing deadlocks and
1383 | // inconsistent rearrangement of log messages.
1384 | // E.g. if a LogSink has thread-specific actions, the send() method
1385 | // can simply add the message to a queue and wake up another thread that
1386 | // handles real logging while itself making some LOG() calls;
1387 | // WaitTillSent() can be implemented to wait for that logic to complete.
1388 | // See our unittest for an example.
1389 | virtual void WaitTillSent();
1390 |
1391 | // Returns the normal text output of the log message.
1392 | // Can be useful to implement send().
1393 | static std::string ToString(LogSeverity severity, const char* file, int line,
1394 | const struct ::tm* tm_time,
1395 | const char* message, size_t message_len);
1396 | };
1397 |
1398 | // Add or remove a LogSink as a consumer of logging data. Thread-safe.
1399 | GOOGLE_GLOG_DLL_DECL void AddLogSink(LogSink *destination);
1400 | GOOGLE_GLOG_DLL_DECL void RemoveLogSink(LogSink *destination);
1401 |
1402 | //
1403 | // Specify an "extension" added to the filename specified via
1404 | // SetLogDestination. This applies to all severity levels. It's
1405 | // often used to append the port we're listening on to the logfile
1406 | // name. Thread-safe.
1407 | //
1408 | GOOGLE_GLOG_DLL_DECL void SetLogFilenameExtension(
1409 | const char* filename_extension);
1410 |
1411 | //
1412 | // Make it so that all log messages of at least a particular severity
1413 | // are logged to stderr (in addition to logging to the usual log
1414 | // file(s)). Thread-safe.
1415 | //
1416 | GOOGLE_GLOG_DLL_DECL void SetStderrLogging(LogSeverity min_severity);
1417 |
1418 | //
1419 | // Make it so that all log messages go only to stderr. Thread-safe.
1420 | //
1421 | GOOGLE_GLOG_DLL_DECL void LogToStderr();
1422 |
1423 | //
1424 | // Make it so that all log messages of at least a particular severity are
1425 | // logged via email to a list of addresses (in addition to logging to the
1426 | // usual log file(s)). The list of addresses is just a string containing
1427 | // the email addresses to send to (separated by spaces, say). Thread-safe.
1428 | //
1429 | GOOGLE_GLOG_DLL_DECL void SetEmailLogging(LogSeverity min_severity,
1430 | const char* addresses);
1431 |
1432 | // A simple function that sends email. dest is a commma-separated
1433 | // list of addressess. Thread-safe.
1434 | GOOGLE_GLOG_DLL_DECL bool SendEmail(const char *dest,
1435 | const char *subject, const char *body);
1436 |
1437 | GOOGLE_GLOG_DLL_DECL const std::vector& GetLoggingDirectories();
1438 |
1439 | // For tests only: Clear the internal [cached] list of logging directories to
1440 | // force a refresh the next time GetLoggingDirectories is called.
1441 | // Thread-hostile.
1442 | void TestOnly_ClearLoggingDirectoriesList();
1443 |
1444 | // Returns a set of existing temporary directories, which will be a
1445 | // subset of the directories returned by GetLogginDirectories().
1446 | // Thread-safe.
1447 | GOOGLE_GLOG_DLL_DECL void GetExistingTempDirectories(
1448 | std::vector* list);
1449 |
1450 | // Print any fatal message again -- useful to call from signal handler
1451 | // so that the last thing in the output is the fatal message.
1452 | // Thread-hostile, but a race is unlikely.
1453 | GOOGLE_GLOG_DLL_DECL void ReprintFatalMessage();
1454 |
1455 | // Truncate a log file that may be the append-only output of multiple
1456 | // processes and hence can't simply be renamed/reopened (typically a
1457 | // stdout/stderr). If the file "path" is > "limit" bytes, copy the
1458 | // last "keep" bytes to offset 0 and truncate the rest. Since we could
1459 | // be racing with other writers, this approach has the potential to
1460 | // lose very small amounts of data. For security, only follow symlinks
1461 | // if the path is /proc/self/fd/*
1462 | GOOGLE_GLOG_DLL_DECL void TruncateLogFile(const char *path,
1463 | int64 limit, int64 keep);
1464 |
1465 | // Truncate stdout and stderr if they are over the value specified by
1466 | // --max_log_size; keep the final 1MB. This function has the same
1467 | // race condition as TruncateLogFile.
1468 | GOOGLE_GLOG_DLL_DECL void TruncateStdoutStderr();
1469 |
1470 | // Return the string representation of the provided LogSeverity level.
1471 | // Thread-safe.
1472 | GOOGLE_GLOG_DLL_DECL const char* GetLogSeverityName(LogSeverity severity);
1473 |
1474 | // ---------------------------------------------------------------------
1475 | // Implementation details that are not useful to most clients
1476 | // ---------------------------------------------------------------------
1477 |
1478 | // A Logger is the interface used by logging modules to emit entries
1479 | // to a log. A typical implementation will dump formatted data to a
1480 | // sequence of files. We also provide interfaces that will forward
1481 | // the data to another thread so that the invoker never blocks.
1482 | // Implementations should be thread-safe since the logging system
1483 | // will write to them from multiple threads.
1484 |
1485 | namespace base {
1486 |
1487 | class GOOGLE_GLOG_DLL_DECL Logger {
1488 | public:
1489 | virtual ~Logger();
1490 |
1491 | // Writes "message[0,message_len-1]" corresponding to an event that
1492 | // occurred at "timestamp". If "force_flush" is true, the log file
1493 | // is flushed immediately.
1494 | //
1495 | // The input message has already been formatted as deemed
1496 | // appropriate by the higher level logging facility. For example,
1497 | // textual log messages already contain timestamps, and the
1498 | // file:linenumber header.
1499 | virtual void Write(bool force_flush,
1500 | time_t timestamp,
1501 | const char* message,
1502 | int message_len) = 0;
1503 |
1504 | // Flush any buffered messages
1505 | virtual void Flush() = 0;
1506 |
1507 | // Get the current LOG file size.
1508 | // The returned value is approximate since some
1509 | // logged data may not have been flushed to disk yet.
1510 | virtual uint32 LogSize() = 0;
1511 | };
1512 |
1513 | // Get the logger for the specified severity level. The logger
1514 | // remains the property of the logging module and should not be
1515 | // deleted by the caller. Thread-safe.
1516 | extern GOOGLE_GLOG_DLL_DECL Logger* GetLogger(LogSeverity level);
1517 |
1518 | // Set the logger for the specified severity level. The logger
1519 | // becomes the property of the logging module and should not
1520 | // be deleted by the caller. Thread-safe.
1521 | extern GOOGLE_GLOG_DLL_DECL void SetLogger(LogSeverity level, Logger* logger);
1522 |
1523 | }
1524 |
1525 | // glibc has traditionally implemented two incompatible versions of
1526 | // strerror_r(). There is a poorly defined convention for picking the
1527 | // version that we want, but it is not clear whether it even works with
1528 | // all versions of glibc.
1529 | // So, instead, we provide this wrapper that automatically detects the
1530 | // version that is in use, and then implements POSIX semantics.
1531 | // N.B. In addition to what POSIX says, we also guarantee that "buf" will
1532 | // be set to an empty string, if this function failed. This means, in most
1533 | // cases, you do not need to check the error code and you can directly
1534 | // use the value of "buf". It will never have an undefined value.
1535 | GOOGLE_GLOG_DLL_DECL int posix_strerror_r(int err, char *buf, size_t len);
1536 |
1537 |
1538 | // A class for which we define operator<<, which does nothing.
1539 | class GOOGLE_GLOG_DLL_DECL NullStream : public LogMessage::LogStream {
1540 | public:
1541 | // Initialize the LogStream so the messages can be written somewhere
1542 | // (they'll never be actually displayed). This will be needed if a
1543 | // NullStream& is implicitly converted to LogStream&, in which case
1544 | // the overloaded NullStream::operator<< will not be invoked.
1545 | NullStream() : LogMessage::LogStream(message_buffer_, 1, 0) { }
1546 | NullStream(const char* /*file*/, int /*line*/,
1547 | const CheckOpString& /*result*/) :
1548 | LogMessage::LogStream(message_buffer_, 1, 0) { }
1549 | NullStream &stream() { return *this; }
1550 | private:
1551 | // A very short buffer for messages (which we discard anyway). This
1552 | // will be needed if NullStream& converted to LogStream& (e.g. as a
1553 | // result of a conditional expression).
1554 | char message_buffer_[2];
1555 | };
1556 |
1557 | // Do nothing. This operator is inline, allowing the message to be
1558 | // compiled away. The message will not be compiled away if we do
1559 | // something like (flag ? LOG(INFO) : LOG(ERROR)) << message; when
1560 | // SKIP_LOG=WARNING. In those cases, NullStream will be implicitly
1561 | // converted to LogStream and the message will be computed and then
1562 | // quietly discarded.
1563 | template
1564 | inline NullStream& operator<<(NullStream &str, const T &) { return str; }
1565 |
1566 | // Similar to NullStream, but aborts the program (without stack
1567 | // trace), like LogMessageFatal.
1568 | class GOOGLE_GLOG_DLL_DECL NullStreamFatal : public NullStream {
1569 | public:
1570 | NullStreamFatal() { }
1571 | NullStreamFatal(const char* file, int line, const CheckOpString& result) :
1572 | NullStream(file, line, result) { }
1573 | ~NullStreamFatal() { _exit(1); }
1574 | };
1575 |
1576 | // Install a signal handler that will dump signal information and a stack
1577 | // trace when the program crashes on certain signals. We'll install the
1578 | // signal handler for the following signals.
1579 | //
1580 | // SIGSEGV, SIGILL, SIGFPE, SIGABRT, SIGBUS, and SIGTERM.
1581 | //
1582 | // By default, the signal handler will write the failure dump to the
1583 | // standard error. You can customize the destination by installing your
1584 | // own writer function by InstallFailureWriter() below.
1585 | //
1586 | // Note on threading:
1587 | //
1588 | // The function should be called before threads are created, if you want
1589 | // to use the failure signal handler for all threads. The stack trace
1590 | // will be shown only for the thread that receives the signal. In other
1591 | // words, stack traces of other threads won't be shown.
1592 | GOOGLE_GLOG_DLL_DECL void InstallFailureSignalHandler();
1593 |
1594 | // Installs a function that is used for writing the failure dump. "data"
1595 | // is the pointer to the beginning of a message to be written, and "size"
1596 | // is the size of the message. You should not expect the data is
1597 | // terminated with '\0'.
1598 | GOOGLE_GLOG_DLL_DECL void InstallFailureWriter(
1599 | void (*writer)(const char* data, int size));
1600 |
1601 | }
1602 |
1603 | #endif // _LOGGING_H_
1604 |
--------------------------------------------------------------------------------
/demo/demo/glog/logging.h:
--------------------------------------------------------------------------------
1 | // This file is automatically generated from src/glog/logging.h.in
2 | // using src/windows/preprocess.sh.
3 | // DO NOT EDIT!
4 |
5 | // Copyright (c) 1999, Google Inc.
6 | // All rights reserved.
7 | //
8 | // Redistribution and use in source and binary forms, with or without
9 | // modification, are permitted provided that the following conditions are
10 | // met:
11 | //
12 | // * Redistributions of source code must retain the above copyright
13 | // notice, this list of conditions and the following disclaimer.
14 | // * Redistributions in binary form must reproduce the above
15 | // copyright notice, this list of conditions and the following disclaimer
16 | // in the documentation and/or other materials provided with the
17 | // distribution.
18 | // * Neither the name of Google Inc. nor the names of its
19 | // contributors may be used to endorse or promote products derived from
20 | // this software without specific prior written permission.
21 | //
22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 | //
34 | // Author: Ray Sidney
35 | //
36 | // This file contains #include information about logging-related stuff.
37 | // Pretty much everybody needs to #include this file so that they can
38 | // log various happenings.
39 | //
40 | #ifndef _LOGGING_H_
41 | #define _LOGGING_H_
42 |
43 | #include
44 | #include
45 | #include
46 | #include
47 | #include
48 | #include
49 | #include
50 | #if 0
51 | # include
52 | #endif
53 | #include
54 |
55 | // Annoying stuff for windows -- makes sure clients can import these functions
56 | #ifndef GOOGLE_GLOG_DLL_DECL
57 | # if defined(_WIN32) && !defined(__CYGWIN__)
58 | # define GOOGLE_GLOG_DLL_DECL __declspec(dllimport)
59 | # else
60 | # define GOOGLE_GLOG_DLL_DECL
61 | # endif
62 | #endif
63 | #if defined(_MSC_VER)
64 | #define GLOG_MSVC_PUSH_DISABLE_WARNING(n) __pragma(warning(push)) \
65 | __pragma(warning(disable:n))
66 | #define GLOG_MSVC_POP_WARNING() __pragma(warning(pop))
67 | #else
68 | #define GLOG_MSVC_PUSH_DISABLE_WARNING(n)
69 | #define GLOG_MSVC_POP_WARNING()
70 | #endif
71 |
72 | // We care a lot about number of bits things take up. Unfortunately,
73 | // systems define their bit-specific ints in a lot of different ways.
74 | // We use our own way, and have a typedef to get there.
75 | // Note: these commands below may look like "#if 1" or "#if 0", but
76 | // that's because they were constructed that way at ./configure time.
77 | // Look at logging.h.in to see how they're calculated (based on your config).
78 | #if 0
79 | #include // the normal place uint16_t is defined
80 | #endif
81 | #if 0
82 | #include // the normal place u_int16_t is defined
83 | #endif
84 | #if 0
85 | #include // a third place for uint16_t or u_int16_t
86 | #endif
87 |
88 | #if 0
89 | #include
90 | #endif
91 |
92 | namespace google {
93 |
94 | #if 0 // the C99 format
95 | typedef int32_t int32;
96 | typedef uint32_t uint32;
97 | typedef int64_t int64;
98 | typedef uint64_t uint64;
99 | #elif 0 // the BSD format
100 | typedef int32_t int32;
101 | typedef u_int32_t uint32;
102 | typedef int64_t int64;
103 | typedef u_int64_t uint64;
104 | #elif 1 // the windows (vc7) format
105 | typedef __int32 int32;
106 | typedef unsigned __int32 uint32;
107 | typedef __int64 int64;
108 | typedef unsigned __int64 uint64;
109 | #else
110 | #error Do not know how to define a 32-bit integer quantity on your system
111 | #endif
112 |
113 | }
114 |
115 | // The global value of GOOGLE_STRIP_LOG. All the messages logged to
116 | // LOG(XXX) with severity less than GOOGLE_STRIP_LOG will not be displayed.
117 | // If it can be determined at compile time that the message will not be
118 | // printed, the statement will be compiled out.
119 | //
120 | // Example: to strip out all INFO and WARNING messages, use the value
121 | // of 2 below. To make an exception for WARNING messages from a single
122 | // file, add "#define GOOGLE_STRIP_LOG 1" to that file _before_ including
123 | // base/logging.h
124 | #ifndef GOOGLE_STRIP_LOG
125 | #define GOOGLE_STRIP_LOG 0
126 | #endif
127 |
128 | // GCC can be told that a certain branch is not likely to be taken (for
129 | // instance, a CHECK failure), and use that information in static analysis.
130 | // Giving it this information can help it optimize for the common case in
131 | // the absence of better information (ie. -fprofile-arcs).
132 | //
133 | #ifndef GOOGLE_PREDICT_BRANCH_NOT_TAKEN
134 | #if 0
135 | #define GOOGLE_PREDICT_BRANCH_NOT_TAKEN(x) (__builtin_expect(x, 0))
136 | #define GOOGLE_PREDICT_FALSE(x) (__builtin_expect(x, 0))
137 | #define GOOGLE_PREDICT_TRUE(x) (__builtin_expect(!!(x), 1))
138 | #else
139 | #define GOOGLE_PREDICT_BRANCH_NOT_TAKEN(x) x
140 | #define GOOGLE_PREDICT_FALSE(x) x
141 | #define GOOGLE_PREDICT_TRUE(x) x
142 | #endif
143 | #endif
144 |
145 | // Make a bunch of macros for logging. The way to log things is to stream
146 | // things to LOG(). E.g.,
147 | //
148 | // LOG(INFO) << "Found " << num_cookies << " cookies";
149 | //
150 | // You can capture log messages in a string, rather than reporting them
151 | // immediately:
152 | //
153 | // vector errors;
154 | // LOG_STRING(ERROR, &errors) << "Couldn't parse cookie #" << cookie_num;
155 | //
156 | // This pushes back the new error onto 'errors'; if given a NULL pointer,
157 | // it reports the error via LOG(ERROR).
158 | //
159 | // You can also do conditional logging:
160 | //
161 | // LOG_IF(INFO, num_cookies > 10) << "Got lots of cookies";
162 | //
163 | // You can also do occasional logging (log every n'th occurrence of an
164 | // event):
165 | //
166 | // LOG_EVERY_N(INFO, 10) << "Got the " << google::COUNTER << "th cookie";
167 | //
168 | // The above will cause log messages to be output on the 1st, 11th, 21st, ...
169 | // times it is executed. Note that the special google::COUNTER value is used
170 | // to identify which repetition is happening.
171 | //
172 | // You can also do occasional conditional logging (log every n'th
173 | // occurrence of an event, when condition is satisfied):
174 | //
175 | // LOG_IF_EVERY_N(INFO, (size > 1024), 10) << "Got the " << google::COUNTER
176 | // << "th big cookie";
177 | //
178 | // You can log messages the first N times your code executes a line. E.g.
179 | //
180 | // LOG_FIRST_N(INFO, 20) << "Got the " << google::COUNTER << "th cookie";
181 | //
182 | // Outputs log messages for the first 20 times it is executed.
183 | //
184 | // Analogous SYSLOG, SYSLOG_IF, and SYSLOG_EVERY_N macros are available.
185 | // These log to syslog as well as to the normal logs. If you use these at
186 | // all, you need to be aware that syslog can drastically reduce performance,
187 | // especially if it is configured for remote logging! Don't use these
188 | // unless you fully understand this and have a concrete need to use them.
189 | // Even then, try to minimize your use of them.
190 | //
191 | // There are also "debug mode" logging macros like the ones above:
192 | //
193 | // DLOG(INFO) << "Found cookies";
194 | //
195 | // DLOG_IF(INFO, num_cookies > 10) << "Got lots of cookies";
196 | //
197 | // DLOG_EVERY_N(INFO, 10) << "Got the " << google::COUNTER << "th cookie";
198 | //
199 | // All "debug mode" logging is compiled away to nothing for non-debug mode
200 | // compiles.
201 | //
202 | // We also have
203 | //
204 | // LOG_ASSERT(assertion);
205 | // DLOG_ASSERT(assertion);
206 | //
207 | // which is syntactic sugar for {,D}LOG_IF(FATAL, assert fails) << assertion;
208 | //
209 | // There are "verbose level" logging macros. They look like
210 | //
211 | // VLOG(1) << "I'm printed when you run the program with --v=1 or more";
212 | // VLOG(2) << "I'm printed when you run the program with --v=2 or more";
213 | //
214 | // These always log at the INFO log level (when they log at all).
215 | // The verbose logging can also be turned on module-by-module. For instance,
216 | // --vmodule=mapreduce=2,file=1,gfs*=3 --v=0
217 | // will cause:
218 | // a. VLOG(2) and lower messages to be printed from mapreduce.{h,cc}
219 | // b. VLOG(1) and lower messages to be printed from file.{h,cc}
220 | // c. VLOG(3) and lower messages to be printed from files prefixed with "gfs"
221 | // d. VLOG(0) and lower messages to be printed from elsewhere
222 | //
223 | // The wildcarding functionality shown by (c) supports both '*' (match
224 | // 0 or more characters) and '?' (match any single character) wildcards.
225 | //
226 | // There's also VLOG_IS_ON(n) "verbose level" condition macro. To be used as
227 | //
228 | // if (VLOG_IS_ON(2)) {
229 | // // do some logging preparation and logging
230 | // // that can't be accomplished with just VLOG(2) << ...;
231 | // }
232 | //
233 | // There are also VLOG_IF, VLOG_EVERY_N and VLOG_IF_EVERY_N "verbose level"
234 | // condition macros for sample cases, when some extra computation and
235 | // preparation for logs is not needed.
236 | // VLOG_IF(1, (size > 1024))
237 | // << "I'm printed when size is more than 1024 and when you run the "
238 | // "program with --v=1 or more";
239 | // VLOG_EVERY_N(1, 10)
240 | // << "I'm printed every 10th occurrence, and when you run the program "
241 | // "with --v=1 or more. Present occurence is " << google::COUNTER;
242 | // VLOG_IF_EVERY_N(1, (size > 1024), 10)
243 | // << "I'm printed on every 10th occurence of case when size is more "
244 | // " than 1024, when you run the program with --v=1 or more. ";
245 | // "Present occurence is " << google::COUNTER;
246 | //
247 | // The supported severity levels for macros that allow you to specify one
248 | // are (in increasing order of severity) INFO, WARNING, ERROR, and FATAL.
249 | // Note that messages of a given severity are logged not only in the
250 | // logfile for that severity, but also in all logfiles of lower severity.
251 | // E.g., a message of severity FATAL will be logged to the logfiles of
252 | // severity FATAL, ERROR, WARNING, and INFO.
253 | //
254 | // There is also the special severity of DFATAL, which logs FATAL in
255 | // debug mode, ERROR in normal mode.
256 | //
257 | // Very important: logging a message at the FATAL severity level causes
258 | // the program to terminate (after the message is logged).
259 | //
260 | // Unless otherwise specified, logs will be written to the filename
261 | // "...log..", followed
262 | // by the date, time, and pid (you can't prevent the date, time, and pid
263 | // from being in the filename).
264 | //
265 | // The logging code takes two flags:
266 | // --v=# set the verbose level
267 | // --logtostderr log all the messages to stderr instead of to logfiles
268 |
269 | // LOG LINE PREFIX FORMAT
270 | //
271 | // Log lines have this form:
272 | //
273 | // Lmmdd hh:mm:ss.uuuuuu threadid file:line] msg...
274 | //
275 | // where the fields are defined as follows:
276 | //
277 | // L A single character, representing the log level
278 | // (eg 'I' for INFO)
279 | // mm The month (zero padded; ie May is '05')
280 | // dd The day (zero padded)
281 | // hh:mm:ss.uuuuuu Time in hours, minutes and fractional seconds
282 | // threadid The space-padded thread ID as returned by GetTID()
283 | // (this matches the PID on Linux)
284 | // file The file name
285 | // line The line number
286 | // msg The user-supplied message
287 | //
288 | // Example:
289 | //
290 | // I1103 11:57:31.739339 24395 google.cc:2341] Command line: ./some_prog
291 | // I1103 11:57:31.739403 24395 google.cc:2342] Process id 24395
292 | //
293 | // NOTE: although the microseconds are useful for comparing events on
294 | // a single machine, clocks on different machines may not be well
295 | // synchronized. Hence, use caution when comparing the low bits of
296 | // timestamps from different machines.
297 |
298 | #ifndef DECLARE_VARIABLE
299 | #define MUST_UNDEF_GFLAGS_DECLARE_MACROS
300 | #define DECLARE_VARIABLE(type, shorttype, name, tn) \
301 | namespace fL##shorttype { \
302 | extern GOOGLE_GLOG_DLL_DECL type FLAGS_##name; \
303 | } \
304 | using fL##shorttype::FLAGS_##name
305 |
306 | // bool specialization
307 | #define DECLARE_bool(name) \
308 | DECLARE_VARIABLE(bool, B, name, bool)
309 |
310 | // int32 specialization
311 | #define DECLARE_int32(name) \
312 | DECLARE_VARIABLE(google::int32, I, name, int32)
313 |
314 | // Special case for string, because we have to specify the namespace
315 | // std::string, which doesn't play nicely with our FLAG__namespace hackery.
316 | #define DECLARE_string(name) \
317 | namespace fLS { \
318 | extern GOOGLE_GLOG_DLL_DECL std::string& FLAGS_##name; \
319 | } \
320 | using fLS::FLAGS_##name
321 | #endif
322 |
323 | // Set whether log messages go to stderr instead of logfiles
324 | DECLARE_bool(logtostderr);
325 |
326 | // Set whether log messages go to stderr in addition to logfiles.
327 | DECLARE_bool(alsologtostderr);
328 |
329 | // Set color messages logged to stderr (if supported by terminal).
330 | DECLARE_bool(colorlogtostderr);
331 |
332 | // Log messages at a level >= this flag are automatically sent to
333 | // stderr in addition to log files.
334 | DECLARE_int32(stderrthreshold);
335 |
336 | // Set whether the log prefix should be prepended to each line of output.
337 | DECLARE_bool(log_prefix);
338 |
339 | // Log messages at a level <= this flag are buffered.
340 | // Log messages at a higher level are flushed immediately.
341 | DECLARE_int32(logbuflevel);
342 |
343 | // Sets the maximum number of seconds which logs may be buffered for.
344 | DECLARE_int32(logbufsecs);
345 |
346 | // Log suppression level: messages logged at a lower level than this
347 | // are suppressed.
348 | DECLARE_int32(minloglevel);
349 |
350 | // If specified, logfiles are written into this directory instead of the
351 | // default logging directory.
352 | DECLARE_string(log_dir);
353 |
354 | // Sets the path of the directory into which to put additional links
355 | // to the log files.
356 | DECLARE_string(log_link);
357 |
358 | DECLARE_int32(v); // in vlog_is_on.cc
359 |
360 | // Sets the maximum log file size (in MB).
361 | DECLARE_int32(max_log_size);
362 |
363 | // Sets whether to avoid logging to the disk if the disk is full.
364 | DECLARE_bool(stop_logging_if_full_disk);
365 |
366 | #ifdef MUST_UNDEF_GFLAGS_DECLARE_MACROS
367 | #undef MUST_UNDEF_GFLAGS_DECLARE_MACROS
368 | #undef DECLARE_VARIABLE
369 | #undef DECLARE_bool
370 | #undef DECLARE_int32
371 | #undef DECLARE_string
372 | #endif
373 |
374 | // Log messages below the GOOGLE_STRIP_LOG level will be compiled away for
375 | // security reasons. See LOG(severtiy) below.
376 |
377 | // A few definitions of macros that don't generate much code. Since
378 | // LOG(INFO) and its ilk are used all over our code, it's
379 | // better to have compact code for these operations.
380 |
381 | #if GOOGLE_STRIP_LOG == 0
382 | #define COMPACT_GOOGLE_LOG_INFO google::LogMessage( \
383 | __FILE__, __LINE__)
384 | #define LOG_TO_STRING_INFO(message) google::LogMessage( \
385 | __FILE__, __LINE__, google::GLOG_INFO, message)
386 | #else
387 | #define COMPACT_GOOGLE_LOG_INFO google::NullStream()
388 | #define LOG_TO_STRING_INFO(message) google::NullStream()
389 | #endif
390 |
391 | #if GOOGLE_STRIP_LOG <= 1
392 | #define COMPACT_GOOGLE_LOG_WARNING google::LogMessage( \
393 | __FILE__, __LINE__, google::GLOG_WARNING)
394 | #define LOG_TO_STRING_WARNING(message) google::LogMessage( \
395 | __FILE__, __LINE__, google::GLOG_WARNING, message)
396 | #else
397 | #define COMPACT_GOOGLE_LOG_WARNING google::NullStream()
398 | #define LOG_TO_STRING_WARNING(message) google::NullStream()
399 | #endif
400 |
401 | #if GOOGLE_STRIP_LOG <= 2
402 | #define COMPACT_GOOGLE_LOG_ERROR google::LogMessage( \
403 | __FILE__, __LINE__, google::GLOG_ERROR)
404 | #define LOG_TO_STRING_ERROR(message) google::LogMessage( \
405 | __FILE__, __LINE__, google::GLOG_ERROR, message)
406 | #else
407 | #define COMPACT_GOOGLE_LOG_ERROR google::NullStream()
408 | #define LOG_TO_STRING_ERROR(message) google::NullStream()
409 | #endif
410 |
411 | #if GOOGLE_STRIP_LOG <= 3
412 | #define COMPACT_GOOGLE_LOG_FATAL google::LogMessageFatal( \
413 | __FILE__, __LINE__)
414 | #define LOG_TO_STRING_FATAL(message) google::LogMessage( \
415 | __FILE__, __LINE__, google::GLOG_FATAL, message)
416 | #else
417 | #define COMPACT_GOOGLE_LOG_FATAL google::NullStreamFatal()
418 | #define LOG_TO_STRING_FATAL(message) google::NullStreamFatal()
419 | #endif
420 |
421 | // For DFATAL, we want to use LogMessage (as opposed to
422 | // LogMessageFatal), to be consistent with the original behavior.
423 | #ifdef NDEBUG
424 | #define COMPACT_GOOGLE_LOG_DFATAL COMPACT_GOOGLE_LOG_ERROR
425 | #elif GOOGLE_STRIP_LOG <= 3
426 | #define COMPACT_GOOGLE_LOG_DFATAL google::LogMessage( \
427 | __FILE__, __LINE__, google::GLOG_FATAL)
428 | #else
429 | #define COMPACT_GOOGLE_LOG_DFATAL google::NullStreamFatal()
430 | #endif
431 |
432 | #define GOOGLE_LOG_INFO(counter) google::LogMessage(__FILE__, __LINE__, google::GLOG_INFO, counter, &google::LogMessage::SendToLog)
433 | #define SYSLOG_INFO(counter) \
434 | google::LogMessage(__FILE__, __LINE__, google::GLOG_INFO, counter, \
435 | &google::LogMessage::SendToSyslogAndLog)
436 | #define GOOGLE_LOG_WARNING(counter) \
437 | google::LogMessage(__FILE__, __LINE__, google::GLOG_WARNING, counter, \
438 | &google::LogMessage::SendToLog)
439 | #define SYSLOG_WARNING(counter) \
440 | google::LogMessage(__FILE__, __LINE__, google::GLOG_WARNING, counter, \
441 | &google::LogMessage::SendToSyslogAndLog)
442 | #define GOOGLE_LOG_ERROR(counter) \
443 | google::LogMessage(__FILE__, __LINE__, google::GLOG_ERROR, counter, \
444 | &google::LogMessage::SendToLog)
445 | #define SYSLOG_ERROR(counter) \
446 | google::LogMessage(__FILE__, __LINE__, google::GLOG_ERROR, counter, \
447 | &google::LogMessage::SendToSyslogAndLog)
448 | #define GOOGLE_LOG_FATAL(counter) \
449 | google::LogMessage(__FILE__, __LINE__, google::GLOG_FATAL, counter, \
450 | &google::LogMessage::SendToLog)
451 | #define SYSLOG_FATAL(counter) \
452 | google::LogMessage(__FILE__, __LINE__, google::GLOG_FATAL, counter, \
453 | &google::LogMessage::SendToSyslogAndLog)
454 | #define GOOGLE_LOG_DFATAL(counter) \
455 | google::LogMessage(__FILE__, __LINE__, google::DFATAL_LEVEL, counter, \
456 | &google::LogMessage::SendToLog)
457 | #define SYSLOG_DFATAL(counter) \
458 | google::LogMessage(__FILE__, __LINE__, google::DFATAL_LEVEL, counter, \
459 | &google::LogMessage::SendToSyslogAndLog)
460 |
461 | #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) || defined(__CYGWIN32__)
462 | // A very useful logging macro to log windows errors:
463 | #define LOG_SYSRESULT(result) \
464 | if (FAILED(HRESULT_FROM_WIN32(result))) { \
465 | LPSTR message = NULL; \
466 | LPSTR msg = reinterpret_cast(&message); \
467 | DWORD message_length = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | \
468 | FORMAT_MESSAGE_FROM_SYSTEM, \
469 | 0, result, 0, msg, 100, NULL); \
470 | if (message_length > 0) { \
471 | google::LogMessage(__FILE__, __LINE__, google::GLOG_ERROR, 0, \
472 | &google::LogMessage::SendToLog).stream() \
473 | << reinterpret_cast(message); \
474 | LocalFree(message); \
475 | } \
476 | }
477 | #endif
478 |
479 | // We use the preprocessor's merging operator, "##", so that, e.g.,
480 | // LOG(INFO) becomes the token GOOGLE_LOG_INFO. There's some funny
481 | // subtle difference between ostream member streaming functions (e.g.,
482 | // ostream::operator<<(int) and ostream non-member streaming functions
483 | // (e.g., ::operator<<(ostream&, string&): it turns out that it's
484 | // impossible to stream something like a string directly to an unnamed
485 | // ostream. We employ a neat hack by calling the stream() member
486 | // function of LogMessage which seems to avoid the problem.
487 | #define LOG(severity) COMPACT_GOOGLE_LOG_ ## severity.stream()
488 | #define SYSLOG(severity) SYSLOG_ ## severity(0).stream()
489 |
490 | namespace google {
491 |
492 | // They need the definitions of integer types.
493 | #include "glog/log_severity.h"
494 | #include "glog/vlog_is_on.h"
495 |
496 | // Initialize google's logging library. You will see the program name
497 | // specified by argv0 in log outputs.
498 | GOOGLE_GLOG_DLL_DECL void InitGoogleLogging(const char* argv0);
499 |
500 | // Shutdown google's logging library.
501 | GOOGLE_GLOG_DLL_DECL void ShutdownGoogleLogging();
502 |
503 | // Install a function which will be called after LOG(FATAL).
504 | GOOGLE_GLOG_DLL_DECL void InstallFailureFunction(void (*fail_func)());
505 |
506 | class LogSink; // defined below
507 |
508 | // If a non-NULL sink pointer is given, we push this message to that sink.
509 | // For LOG_TO_SINK we then do normal LOG(severity) logging as well.
510 | // This is useful for capturing messages and passing/storing them
511 | // somewhere more specific than the global log of the process.
512 | // Argument types:
513 | // LogSink* sink;
514 | // LogSeverity severity;
515 | // The cast is to disambiguate NULL arguments.
516 | #define LOG_TO_SINK(sink, severity) \
517 | google::LogMessage( \
518 | __FILE__, __LINE__, \
519 | google::GLOG_ ## severity, \
520 | static_cast(sink), true).stream()
521 | #define LOG_TO_SINK_BUT_NOT_TO_LOGFILE(sink, severity) \
522 | google::LogMessage( \
523 | __FILE__, __LINE__, \
524 | google::GLOG_ ## severity, \
525 | static_cast(sink), false).stream()
526 |
527 | // If a non-NULL string pointer is given, we write this message to that string.
528 | // We then do normal LOG(severity) logging as well.
529 | // This is useful for capturing messages and storing them somewhere more
530 | // specific than the global log of the process.
531 | // Argument types:
532 | // string* message;
533 | // LogSeverity severity;
534 | // The cast is to disambiguate NULL arguments.
535 | // NOTE: LOG(severity) expands to LogMessage().stream() for the specified
536 | // severity.
537 | #define LOG_TO_STRING(severity, message) \
538 | LOG_TO_STRING_##severity(static_cast(message)).stream()
539 |
540 | // If a non-NULL pointer is given, we push the message onto the end
541 | // of a vector of strings; otherwise, we report it with LOG(severity).
542 | // This is handy for capturing messages and perhaps passing them back
543 | // to the caller, rather than reporting them immediately.
544 | // Argument types:
545 | // LogSeverity severity;
546 | // vector *outvec;
547 | // The cast is to disambiguate NULL arguments.
548 | #define LOG_STRING(severity, outvec) \
549 | LOG_TO_STRING_##severity(static_cast*>(outvec)).stream()
550 |
551 | #define LOG_IF(severity, condition) \
552 | !(condition) ? (void) 0 : google::LogMessageVoidify() & LOG(severity)
553 | #define SYSLOG_IF(severity, condition) \
554 | !(condition) ? (void) 0 : google::LogMessageVoidify() & SYSLOG(severity)
555 |
556 | #define LOG_ASSERT(condition) \
557 | LOG_IF(FATAL, !(condition)) << "Assert failed: " #condition
558 | #define SYSLOG_ASSERT(condition) \
559 | SYSLOG_IF(FATAL, !(condition)) << "Assert failed: " #condition
560 |
561 | // CHECK dies with a fatal error if condition is not true. It is *not*
562 | // controlled by NDEBUG, so the check will be executed regardless of
563 | // compilation mode. Therefore, it is safe to do things like:
564 | // CHECK(fp->Write(x) == 4)
565 | #define CHECK(condition) \
566 | LOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN(!(condition))) \
567 | << "Check failed: " #condition " "
568 |
569 | // A container for a string pointer which can be evaluated to a bool -
570 | // true iff the pointer is NULL.
571 | struct CheckOpString {
572 | CheckOpString(std::string* str) : str_(str) { }
573 | // No destructor: if str_ is non-NULL, we're about to LOG(FATAL),
574 | // so there's no point in cleaning up str_.
575 | operator bool() const {
576 | return GOOGLE_PREDICT_BRANCH_NOT_TAKEN(str_ != NULL);
577 | }
578 | std::string* str_;
579 | };
580 |
581 | // Function is overloaded for integral types to allow static const
582 | // integrals declared in classes and not defined to be used as arguments to
583 | // CHECK* macros. It's not encouraged though.
584 | template
585 | inline const T& GetReferenceableValue(const T& t) { return t; }
586 | inline char GetReferenceableValue(char t) { return t; }
587 | inline unsigned char GetReferenceableValue(unsigned char t) { return t; }
588 | inline signed char GetReferenceableValue(signed char t) { return t; }
589 | inline short GetReferenceableValue(short t) { return t; }
590 | inline unsigned short GetReferenceableValue(unsigned short t) { return t; }
591 | inline int GetReferenceableValue(int t) { return t; }
592 | inline unsigned int GetReferenceableValue(unsigned int t) { return t; }
593 | inline long GetReferenceableValue(long t) { return t; }
594 | inline unsigned long GetReferenceableValue(unsigned long t) { return t; }
595 | inline long long GetReferenceableValue(long long t) { return t; }
596 | inline unsigned long long GetReferenceableValue(unsigned long long t) {
597 | return t;
598 | }
599 |
600 | // This is a dummy class to define the following operator.
601 | struct DummyClassToDefineOperator {};
602 |
603 | }
604 |
605 | // Define global operator<< to declare using ::operator<<.
606 | // This declaration will allow use to use CHECK macros for user
607 | // defined classes which have operator<< (e.g., stl_logging.h).
608 | inline std::ostream& operator<<(
609 | std::ostream& out, const google::DummyClassToDefineOperator&) {
610 | return out;
611 | }
612 |
613 | namespace google {
614 |
615 | // This formats a value for a failing CHECK_XX statement. Ordinarily,
616 | // it uses the definition for operator<<, with a few special cases below.
617 | template
618 | inline void MakeCheckOpValueString(std::ostream* os, const T& v) {
619 | (*os) << v;
620 | }
621 |
622 | // Overrides for char types provide readable values for unprintable
623 | // characters.
624 | template <> GOOGLE_GLOG_DLL_DECL
625 | void MakeCheckOpValueString(std::ostream* os, const char& v);
626 | template <> GOOGLE_GLOG_DLL_DECL
627 | void MakeCheckOpValueString(std::ostream* os, const signed char& v);
628 | template <> GOOGLE_GLOG_DLL_DECL
629 | void MakeCheckOpValueString(std::ostream* os, const unsigned char& v);
630 |
631 | // Build the error message string. Specify no inlining for code size.
632 | template
633 | std::string* MakeCheckOpString(const T1& v1, const T2& v2, const char* exprtext)
634 | ;
635 |
636 | namespace base {
637 | namespace internal {
638 |
639 | // If "s" is less than base_logging::INFO, returns base_logging::INFO.
640 | // If "s" is greater than base_logging::FATAL, returns
641 | // base_logging::ERROR. Otherwise, returns "s".
642 | LogSeverity NormalizeSeverity(LogSeverity s);
643 |
644 | } // namespace internal
645 |
646 | // A helper class for formatting "expr (V1 vs. V2)" in a CHECK_XX
647 | // statement. See MakeCheckOpString for sample usage. Other
648 | // approaches were considered: use of a template method (e.g.,
649 | // base::BuildCheckOpString(exprtext, base::Print, &v1,
650 | // base::Print, &v2), however this approach has complications
651 | // related to volatile arguments and function-pointer arguments).
652 | class GOOGLE_GLOG_DLL_DECL CheckOpMessageBuilder {
653 | public:
654 | // Inserts "exprtext" and " (" to the stream.
655 | explicit CheckOpMessageBuilder(const char *exprtext);
656 | // Deletes "stream_".
657 | ~CheckOpMessageBuilder();
658 | // For inserting the first variable.
659 | std::ostream* ForVar1() { return stream_; }
660 | // For inserting the second variable (adds an intermediate " vs. ").
661 | std::ostream* ForVar2();
662 | // Get the result (inserts the closing ")").
663 | std::string* NewString();
664 |
665 | private:
666 | std::ostringstream *stream_;
667 | };
668 |
669 | } // namespace base
670 |
671 | template
672 | std::string* MakeCheckOpString(const T1& v1, const T2& v2, const char* exprtext) {
673 | base::CheckOpMessageBuilder comb(exprtext);
674 | MakeCheckOpValueString(comb.ForVar1(), v1);
675 | MakeCheckOpValueString(comb.ForVar2(), v2);
676 | return comb.NewString();
677 | }
678 |
679 | // Helper functions for CHECK_OP macro.
680 | // The (int, int) specialization works around the issue that the compiler
681 | // will not instantiate the template version of the function on values of
682 | // unnamed enum type - see comment below.
683 | #define DEFINE_CHECK_OP_IMPL(name, op) \
684 | template \
685 | inline std::string* name##Impl(const T1& v1, const T2& v2, \
686 | const char* exprtext) { \
687 | if (GOOGLE_PREDICT_TRUE(v1 op v2)) return NULL; \
688 | else return MakeCheckOpString(v1, v2, exprtext); \
689 | } \
690 | inline std::string* name##Impl(int v1, int v2, const char* exprtext) { \
691 | return name##Impl(v1, v2, exprtext); \
692 | }
693 |
694 | // We use the full name Check_EQ, Check_NE, etc. in case the file including
695 | // base/logging.h provides its own #defines for the simpler names EQ, NE, etc.
696 | // This happens if, for example, those are used as token names in a
697 | // yacc grammar.
698 | DEFINE_CHECK_OP_IMPL(Check_EQ, ==) // Compilation error with CHECK_EQ(NULL, x)?
699 | DEFINE_CHECK_OP_IMPL(Check_NE, !=) // Use CHECK(x == NULL) instead.
700 | DEFINE_CHECK_OP_IMPL(Check_LE, <=)
701 | DEFINE_CHECK_OP_IMPL(Check_LT, < )
702 | DEFINE_CHECK_OP_IMPL(Check_GE, >=)
703 | DEFINE_CHECK_OP_IMPL(Check_GT, > )
704 | #undef DEFINE_CHECK_OP_IMPL
705 |
706 | // Helper macro for binary operators.
707 | // Don't use this macro directly in your code, use CHECK_EQ et al below.
708 |
709 | #if defined(STATIC_ANALYSIS)
710 | // Only for static analysis tool to know that it is equivalent to assert
711 | #define CHECK_OP_LOG(name, op, val1, val2, log) CHECK((val1) op (val2))
712 | #elif !defined(NDEBUG)
713 | // In debug mode, avoid constructing CheckOpStrings if possible,
714 | // to reduce the overhead of CHECK statments by 2x.
715 | // Real DCHECK-heavy tests have seen 1.5x speedups.
716 |
717 | // The meaning of "string" might be different between now and
718 | // when this macro gets invoked (e.g., if someone is experimenting
719 | // with other string implementations that get defined after this
720 | // file is included). Save the current meaning now and use it
721 | // in the macro.
722 | typedef std::string _Check_string;
723 | #define CHECK_OP_LOG(name, op, val1, val2, log) \
724 | while (google::_Check_string* _result = \
725 | google::Check##name##Impl( \
726 | google::GetReferenceableValue(val1), \
727 | google::GetReferenceableValue(val2), \
728 | #val1 " " #op " " #val2)) \
729 | log(__FILE__, __LINE__, \
730 | google::CheckOpString(_result)).stream()
731 | #else
732 | // In optimized mode, use CheckOpString to hint to compiler that
733 | // the while condition is unlikely.
734 | #define CHECK_OP_LOG(name, op, val1, val2, log) \
735 | while (google::CheckOpString _result = \
736 | google::Check##name##Impl( \
737 | google::GetReferenceableValue(val1), \
738 | google::GetReferenceableValue(val2), \
739 | #val1 " " #op " " #val2)) \
740 | log(__FILE__, __LINE__, _result).stream()
741 | #endif // STATIC_ANALYSIS, !NDEBUG
742 |
743 | #if GOOGLE_STRIP_LOG <= 3
744 | #define CHECK_OP(name, op, val1, val2) \
745 | CHECK_OP_LOG(name, op, val1, val2, google::LogMessageFatal)
746 | #else
747 | #define CHECK_OP(name, op, val1, val2) \
748 | CHECK_OP_LOG(name, op, val1, val2, google::NullStreamFatal)
749 | #endif // STRIP_LOG <= 3
750 |
751 | // Equality/Inequality checks - compare two values, and log a FATAL message
752 | // including the two values when the result is not as expected. The values
753 | // must have operator<<(ostream, ...) defined.
754 | //
755 | // You may append to the error message like so:
756 | // CHECK_NE(1, 2) << ": The world must be ending!";
757 | //
758 | // We are very careful to ensure that each argument is evaluated exactly
759 | // once, and that anything which is legal to pass as a function argument is
760 | // legal here. In particular, the arguments may be temporary expressions
761 | // which will end up being destroyed at the end of the apparent statement,
762 | // for example:
763 | // CHECK_EQ(string("abc")[1], 'b');
764 | //
765 | // WARNING: These don't compile correctly if one of the arguments is a pointer
766 | // and the other is NULL. To work around this, simply static_cast NULL to the
767 | // type of the desired pointer.
768 |
769 | #define CHECK_EQ(val1, val2) CHECK_OP(_EQ, ==, val1, val2)
770 | #define CHECK_NE(val1, val2) CHECK_OP(_NE, !=, val1, val2)
771 | #define CHECK_LE(val1, val2) CHECK_OP(_LE, <=, val1, val2)
772 | #define CHECK_LT(val1, val2) CHECK_OP(_LT, < , val1, val2)
773 | #define CHECK_GE(val1, val2) CHECK_OP(_GE, >=, val1, val2)
774 | #define CHECK_GT(val1, val2) CHECK_OP(_GT, > , val1, val2)
775 |
776 | // Check that the input is non NULL. This very useful in constructor
777 | // initializer lists.
778 |
779 | #define CHECK_NOTNULL(val) \
780 | google::CheckNotNull(__FILE__, __LINE__, "'" #val "' Must be non NULL", (val))
781 |
782 | // Helper functions for string comparisons.
783 | // To avoid bloat, the definitions are in logging.cc.
784 | #define DECLARE_CHECK_STROP_IMPL(func, expected) \
785 | GOOGLE_GLOG_DLL_DECL std::string* Check##func##expected##Impl( \
786 | const char* s1, const char* s2, const char* names);
787 | DECLARE_CHECK_STROP_IMPL(strcmp, true)
788 | DECLARE_CHECK_STROP_IMPL(strcmp, false)
789 | DECLARE_CHECK_STROP_IMPL(strcasecmp, true)
790 | DECLARE_CHECK_STROP_IMPL(strcasecmp, false)
791 | #undef DECLARE_CHECK_STROP_IMPL
792 |
793 | // Helper macro for string comparisons.
794 | // Don't use this macro directly in your code, use CHECK_STREQ et al below.
795 | #define CHECK_STROP(func, op, expected, s1, s2) \
796 | while (google::CheckOpString _result = \
797 | google::Check##func##expected##Impl((s1), (s2), \
798 | #s1 " " #op " " #s2)) \
799 | LOG(FATAL) << *_result.str_
800 |
801 |
802 | // String (char*) equality/inequality checks.
803 | // CASE versions are case-insensitive.
804 | //
805 | // Note that "s1" and "s2" may be temporary strings which are destroyed
806 | // by the compiler at the end of the current "full expression"
807 | // (e.g. CHECK_STREQ(Foo().c_str(), Bar().c_str())).
808 |
809 | #define CHECK_STREQ(s1, s2) CHECK_STROP(strcmp, ==, true, s1, s2)
810 | #define CHECK_STRNE(s1, s2) CHECK_STROP(strcmp, !=, false, s1, s2)
811 | #define CHECK_STRCASEEQ(s1, s2) CHECK_STROP(strcasecmp, ==, true, s1, s2)
812 | #define CHECK_STRCASENE(s1, s2) CHECK_STROP(strcasecmp, !=, false, s1, s2)
813 |
814 | #define CHECK_INDEX(I,A) CHECK(I < (sizeof(A)/sizeof(A[0])))
815 | #define CHECK_BOUND(B,A) CHECK(B <= (sizeof(A)/sizeof(A[0])))
816 |
817 | #define CHECK_DOUBLE_EQ(val1, val2) \
818 | do { \
819 | CHECK_LE((val1), (val2)+0.000000000000001L); \
820 | CHECK_GE((val1), (val2)-0.000000000000001L); \
821 | } while (0)
822 |
823 | #define CHECK_NEAR(val1, val2, margin) \
824 | do { \
825 | CHECK_LE((val1), (val2)+(margin)); \
826 | CHECK_GE((val1), (val2)-(margin)); \
827 | } while (0)
828 |
829 | // perror()..googly style!
830 | //
831 | // PLOG() and PLOG_IF() and PCHECK() behave exactly like their LOG* and
832 | // CHECK equivalents with the addition that they postpend a description
833 | // of the current state of errno to their output lines.
834 |
835 | #define PLOG(severity) GOOGLE_PLOG(severity, 0).stream()
836 |
837 | #define GOOGLE_PLOG(severity, counter) \
838 | google::ErrnoLogMessage( \
839 | __FILE__, __LINE__, google::GLOG_ ## severity, counter, \
840 | &google::LogMessage::SendToLog)
841 |
842 | #define PLOG_IF(severity, condition) \
843 | !(condition) ? (void) 0 : google::LogMessageVoidify() & PLOG(severity)
844 |
845 | // A CHECK() macro that postpends errno if the condition is false. E.g.
846 | //
847 | // if (poll(fds, nfds, timeout) == -1) { PCHECK(errno == EINTR); ... }
848 | #define PCHECK(condition) \
849 | PLOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN(!(condition))) \
850 | << "Check failed: " #condition " "
851 |
852 | // A CHECK() macro that lets you assert the success of a function that
853 | // returns -1 and sets errno in case of an error. E.g.
854 | //
855 | // CHECK_ERR(mkdir(path, 0700));
856 | //
857 | // or
858 | //
859 | // int fd = open(filename, flags); CHECK_ERR(fd) << ": open " << filename;
860 | #define CHECK_ERR(invocation) \
861 | PLOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN((invocation) == -1)) \
862 | << #invocation
863 |
864 | // Use macro expansion to create, for each use of LOG_EVERY_N(), static
865 | // variables with the __LINE__ expansion as part of the variable name.
866 | #define LOG_EVERY_N_VARNAME(base, line) LOG_EVERY_N_VARNAME_CONCAT(base, line)
867 | #define LOG_EVERY_N_VARNAME_CONCAT(base, line) base ## line
868 |
869 | #define LOG_OCCURRENCES LOG_EVERY_N_VARNAME(occurrences_, __LINE__)
870 | #define LOG_OCCURRENCES_MOD_N LOG_EVERY_N_VARNAME(occurrences_mod_n_, __LINE__)
871 |
872 | #define SOME_KIND_OF_LOG_EVERY_N(severity, n, what_to_do) \
873 | static int LOG_OCCURRENCES = 0, LOG_OCCURRENCES_MOD_N = 0; \
874 | ++LOG_OCCURRENCES; \
875 | if (++LOG_OCCURRENCES_MOD_N > n) LOG_OCCURRENCES_MOD_N -= n; \
876 | if (LOG_OCCURRENCES_MOD_N == 1) \
877 | google::LogMessage( \
878 | __FILE__, __LINE__, google::GLOG_ ## severity, LOG_OCCURRENCES, \
879 | &what_to_do).stream()
880 |
881 | #define SOME_KIND_OF_LOG_IF_EVERY_N(severity, condition, n, what_to_do) \
882 | static int LOG_OCCURRENCES = 0, LOG_OCCURRENCES_MOD_N = 0; \
883 | ++LOG_OCCURRENCES; \
884 | if (condition && \
885 | ((LOG_OCCURRENCES_MOD_N=(LOG_OCCURRENCES_MOD_N + 1) % n) == (1 % n))) \
886 | google::LogMessage( \
887 | __FILE__, __LINE__, google::GLOG_ ## severity, LOG_OCCURRENCES, \
888 | &what_to_do).stream()
889 |
890 | #define SOME_KIND_OF_PLOG_EVERY_N(severity, n, what_to_do) \
891 | static int LOG_OCCURRENCES = 0, LOG_OCCURRENCES_MOD_N = 0; \
892 | ++LOG_OCCURRENCES; \
893 | if (++LOG_OCCURRENCES_MOD_N > n) LOG_OCCURRENCES_MOD_N -= n; \
894 | if (LOG_OCCURRENCES_MOD_N == 1) \
895 | google::ErrnoLogMessage( \
896 | __FILE__, __LINE__, google::GLOG_ ## severity, LOG_OCCURRENCES, \
897 | &what_to_do).stream()
898 |
899 | #define SOME_KIND_OF_LOG_FIRST_N(severity, n, what_to_do) \
900 | static int LOG_OCCURRENCES = 0; \
901 | if (LOG_OCCURRENCES <= n) \
902 | ++LOG_OCCURRENCES; \
903 | if (LOG_OCCURRENCES <= n) \
904 | google::LogMessage( \
905 | __FILE__, __LINE__, google::GLOG_ ## severity, LOG_OCCURRENCES, \
906 | &what_to_do).stream()
907 |
908 | namespace glog_internal_namespace_ {
909 | template
910 | struct CompileAssert {
911 | };
912 | struct CrashReason;
913 | } // namespace glog_internal_namespace_
914 |
915 | #define GOOGLE_GLOG_COMPILE_ASSERT(expr, msg) \
916 | typedef google::glog_internal_namespace_::CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1]
917 |
918 | #define LOG_EVERY_N(severity, n) \
919 | GOOGLE_GLOG_COMPILE_ASSERT(google::GLOG_ ## severity < \
920 | google::NUM_SEVERITIES, \
921 | INVALID_REQUESTED_LOG_SEVERITY); \
922 | SOME_KIND_OF_LOG_EVERY_N(severity, (n), google::LogMessage::SendToLog)
923 |
924 | #define SYSLOG_EVERY_N(severity, n) \
925 | SOME_KIND_OF_LOG_EVERY_N(severity, (n), google::LogMessage::SendToSyslogAndLog)
926 |
927 | #define PLOG_EVERY_N(severity, n) \
928 | SOME_KIND_OF_PLOG_EVERY_N(severity, (n), google::LogMessage::SendToLog)
929 |
930 | #define LOG_FIRST_N(severity, n) \
931 | SOME_KIND_OF_LOG_FIRST_N(severity, (n), google::LogMessage::SendToLog)
932 |
933 | #define LOG_IF_EVERY_N(severity, condition, n) \
934 | SOME_KIND_OF_LOG_IF_EVERY_N(severity, (condition), (n), google::LogMessage::SendToLog)
935 |
936 | // We want the special COUNTER value available for LOG_EVERY_X()'ed messages
937 | enum PRIVATE_Counter {COUNTER};
938 |
939 | #ifdef GLOG_NO_ABBREVIATED_SEVERITIES
940 | // wingdi.h defines ERROR to be 0. When we call LOG(ERROR), it gets
941 | // substituted with 0, and it expands to COMPACT_GOOGLE_LOG_0. To allow us
942 | // to keep using this syntax, we define this macro to do the same thing
943 | // as COMPACT_GOOGLE_LOG_ERROR.
944 | #define COMPACT_GOOGLE_LOG_0 COMPACT_GOOGLE_LOG_ERROR
945 | #define SYSLOG_0 SYSLOG_ERROR
946 | #define LOG_TO_STRING_0 LOG_TO_STRING_ERROR
947 | // Needed for LOG_IS_ON(ERROR).
948 | const LogSeverity GLOG_0 = GLOG_ERROR;
949 | #else
950 | // Users may include windows.h after logging.h without
951 | // GLOG_NO_ABBREVIATED_SEVERITIES nor WIN32_LEAN_AND_MEAN.
952 | // For this case, we cannot detect if ERROR is defined before users
953 | // actually use ERROR. Let's make an undefined symbol to warn users.
954 | # define GLOG_ERROR_MSG ERROR_macro_is_defined_Define_GLOG_NO_ABBREVIATED_SEVERITIES_before_including_logging_h_See_the_document_for_detail
955 | # define COMPACT_GOOGLE_LOG_0 GLOG_ERROR_MSG
956 | # define SYSLOG_0 GLOG_ERROR_MSG
957 | # define LOG_TO_STRING_0 GLOG_ERROR_MSG
958 | # define GLOG_0 GLOG_ERROR_MSG
959 | #endif
960 |
961 | // Plus some debug-logging macros that get compiled to nothing for production
962 |
963 | #ifndef NDEBUG
964 |
965 | #define DLOG(severity) LOG(severity)
966 | #define DVLOG(verboselevel) VLOG(verboselevel)
967 | #define DLOG_IF(severity, condition) LOG_IF(severity, condition)
968 | #define DLOG_EVERY_N(severity, n) LOG_EVERY_N(severity, n)
969 | #define DLOG_IF_EVERY_N(severity, condition, n) \
970 | LOG_IF_EVERY_N(severity, condition, n)
971 | #define DLOG_ASSERT(condition) LOG_ASSERT(condition)
972 |
973 | // debug-only checking. not executed in NDEBUG mode.
974 | #define DCHECK(condition) CHECK(condition)
975 | #define DCHECK_EQ(val1, val2) CHECK_EQ(val1, val2)
976 | #define DCHECK_NE(val1, val2) CHECK_NE(val1, val2)
977 | #define DCHECK_LE(val1, val2) CHECK_LE(val1, val2)
978 | #define DCHECK_LT(val1, val2) CHECK_LT(val1, val2)
979 | #define DCHECK_GE(val1, val2) CHECK_GE(val1, val2)
980 | #define DCHECK_GT(val1, val2) CHECK_GT(val1, val2)
981 | #define DCHECK_NOTNULL(val) CHECK_NOTNULL(val)
982 | #define DCHECK_STREQ(str1, str2) CHECK_STREQ(str1, str2)
983 | #define DCHECK_STRCASEEQ(str1, str2) CHECK_STRCASEEQ(str1, str2)
984 | #define DCHECK_STRNE(str1, str2) CHECK_STRNE(str1, str2)
985 | #define DCHECK_STRCASENE(str1, str2) CHECK_STRCASENE(str1, str2)
986 |
987 | #else // NDEBUG
988 |
989 | #define DLOG(severity) \
990 | true ? (void) 0 : google::LogMessageVoidify() & LOG(severity)
991 |
992 | #define DVLOG(verboselevel) \
993 | (true || !VLOG_IS_ON(verboselevel)) ?\
994 | (void) 0 : google::LogMessageVoidify() & LOG(INFO)
995 |
996 | #define DLOG_IF(severity, condition) \
997 | (true || !(condition)) ? (void) 0 : google::LogMessageVoidify() & LOG(severity)
998 |
999 | #define DLOG_EVERY_N(severity, n) \
1000 | true ? (void) 0 : google::LogMessageVoidify() & LOG(severity)
1001 |
1002 | #define DLOG_IF_EVERY_N(severity, condition, n) \
1003 | (true || !(condition))? (void) 0 : google::LogMessageVoidify() & LOG(severity)
1004 |
1005 | #define DLOG_ASSERT(condition) \
1006 | true ? (void) 0 : LOG_ASSERT(condition)
1007 |
1008 | // MSVC warning C4127: conditional expression is constant
1009 | #define DCHECK(condition) \
1010 | GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
1011 | while (false) \
1012 | GLOG_MSVC_POP_WARNING() CHECK(condition)
1013 |
1014 | #define DCHECK_EQ(val1, val2) \
1015 | GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
1016 | while (false) \
1017 | GLOG_MSVC_POP_WARNING() CHECK_EQ(val1, val2)
1018 |
1019 | #define DCHECK_NE(val1, val2) \
1020 | GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
1021 | while (false) \
1022 | GLOG_MSVC_POP_WARNING() CHECK_NE(val1, val2)
1023 |
1024 | #define DCHECK_LE(val1, val2) \
1025 | GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
1026 | while (false) \
1027 | GLOG_MSVC_POP_WARNING() CHECK_LE(val1, val2)
1028 |
1029 | #define DCHECK_LT(val1, val2) \
1030 | GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
1031 | while (false) \
1032 | GLOG_MSVC_POP_WARNING() CHECK_LT(val1, val2)
1033 |
1034 | #define DCHECK_GE(val1, val2) \
1035 | GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
1036 | while (false) \
1037 | GLOG_MSVC_POP_WARNING() CHECK_GE(val1, val2)
1038 |
1039 | #define DCHECK_GT(val1, val2) \
1040 | GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
1041 | while (false) \
1042 | GLOG_MSVC_POP_WARNING() CHECK_GT(val1, val2)
1043 |
1044 | // You may see warnings in release mode if you don't use the return
1045 | // value of DCHECK_NOTNULL. Please just use DCHECK for such cases.
1046 | #define DCHECK_NOTNULL(val) (val)
1047 |
1048 | #define DCHECK_STREQ(str1, str2) \
1049 | GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
1050 | while (false) \
1051 | GLOG_MSVC_POP_WARNING() CHECK_STREQ(str1, str2)
1052 |
1053 | #define DCHECK_STRCASEEQ(str1, str2) \
1054 | GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
1055 | while (false) \
1056 | GLOG_MSVC_POP_WARNING() CHECK_STRCASEEQ(str1, str2)
1057 |
1058 | #define DCHECK_STRNE(str1, str2) \
1059 | GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
1060 | while (false) \
1061 | GLOG_MSVC_POP_WARNING() CHECK_STRNE(str1, str2)
1062 |
1063 | #define DCHECK_STRCASENE(str1, str2) \
1064 | GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
1065 | while (false) \
1066 | GLOG_MSVC_POP_WARNING() CHECK_STRCASENE(str1, str2)
1067 |
1068 | #endif // NDEBUG
1069 |
1070 | // Log only in verbose mode.
1071 |
1072 | #define VLOG(verboselevel) LOG_IF(INFO, VLOG_IS_ON(verboselevel))
1073 |
1074 | #define VLOG_IF(verboselevel, condition) \
1075 | LOG_IF(INFO, (condition) && VLOG_IS_ON(verboselevel))
1076 |
1077 | #define VLOG_EVERY_N(verboselevel, n) \
1078 | LOG_IF_EVERY_N(INFO, VLOG_IS_ON(verboselevel), n)
1079 |
1080 | #define VLOG_IF_EVERY_N(verboselevel, condition, n) \
1081 | LOG_IF_EVERY_N(INFO, (condition) && VLOG_IS_ON(verboselevel), n)
1082 |
1083 | namespace base_logging {
1084 |
1085 | // LogMessage::LogStream is a std::ostream backed by this streambuf.
1086 | // This class ignores overflow and leaves two bytes at the end of the
1087 | // buffer to allow for a '\n' and '\0'.
1088 | class LogStreamBuf : public std::streambuf {
1089 | public:
1090 | // REQUIREMENTS: "len" must be >= 2 to account for the '\n' and '\n'.
1091 | LogStreamBuf(char *buf, int len) {
1092 | setp(buf, buf + len - 2);
1093 | }
1094 | // This effectively ignores overflow.
1095 | virtual int_type overflow(int_type ch) {
1096 | return ch;
1097 | }
1098 |
1099 | // Legacy public ostrstream method.
1100 | size_t pcount() const { return pptr() - pbase(); }
1101 | char* pbase() const { return std::streambuf::pbase(); }
1102 | };
1103 |
1104 | } // namespace base_logging
1105 |
1106 | //
1107 | // This class more or less represents a particular log message. You
1108 | // create an instance of LogMessage and then stream stuff to it.
1109 | // When you finish streaming to it, ~LogMessage is called and the
1110 | // full message gets streamed to the appropriate destination.
1111 | //
1112 | // You shouldn't actually use LogMessage's constructor to log things,
1113 | // though. You should use the LOG() macro (and variants thereof)
1114 | // above.
1115 | class GOOGLE_GLOG_DLL_DECL LogMessage {
1116 | public:
1117 | enum {
1118 | // Passing kNoLogPrefix for the line number disables the
1119 | // log-message prefix. Useful for using the LogMessage
1120 | // infrastructure as a printing utility. See also the --log_prefix
1121 | // flag for controlling the log-message prefix on an
1122 | // application-wide basis.
1123 | kNoLogPrefix = -1
1124 | };
1125 |
1126 | // LogStream inherit from non-DLL-exported class (std::ostrstream)
1127 | // and VC++ produces a warning for this situation.
1128 | // However, MSDN says "C4275 can be ignored in Microsoft Visual C++
1129 | // 2005 if you are deriving from a type in the Standard C++ Library"
1130 | // http://msdn.microsoft.com/en-us/library/3tdb471s(VS.80).aspx
1131 | // Let's just ignore the warning.
1132 | #ifdef _MSC_VER
1133 | # pragma warning(disable: 4275)
1134 | #endif
1135 | class GOOGLE_GLOG_DLL_DECL LogStream : public std::ostream {
1136 | #ifdef _MSC_VER
1137 | # pragma warning(default: 4275)
1138 | #endif
1139 | public:
1140 | LogStream(char *buf, int len, int ctr)
1141 | : std::ostream(NULL),
1142 | streambuf_(buf, len),
1143 | ctr_(ctr),
1144 | self_(this) {
1145 | rdbuf(&streambuf_);
1146 | }
1147 |
1148 | int ctr() const { return ctr_; }
1149 | void set_ctr(int ctr) { ctr_ = ctr; }
1150 | LogStream* self() const { return self_; }
1151 |
1152 | // Legacy std::streambuf methods.
1153 | size_t pcount() const { return streambuf_.pcount(); }
1154 | char* pbase() const { return streambuf_.pbase(); }
1155 | char* str() const { return pbase(); }
1156 |
1157 | private:
1158 | base_logging::LogStreamBuf streambuf_;
1159 | int ctr_; // Counter hack (for the LOG_EVERY_X() macro)
1160 | LogStream *self_; // Consistency check hack
1161 | };
1162 |
1163 | public:
1164 | // icc 8 requires this typedef to avoid an internal compiler error.
1165 | typedef void (LogMessage::*SendMethod)();
1166 |
1167 | LogMessage(const char* file, int line, LogSeverity severity, int ctr,
1168 | SendMethod send_method);
1169 |
1170 | // Two special constructors that generate reduced amounts of code at
1171 | // LOG call sites for common cases.
1172 |
1173 | // Used for LOG(INFO): Implied are:
1174 | // severity = INFO, ctr = 0, send_method = &LogMessage::SendToLog.
1175 | //
1176 | // Using this constructor instead of the more complex constructor above
1177 | // saves 19 bytes per call site.
1178 | LogMessage(const char* file, int line);
1179 |
1180 | // Used for LOG(severity) where severity != INFO. Implied
1181 | // are: ctr = 0, send_method = &LogMessage::SendToLog
1182 | //
1183 | // Using this constructor instead of the more complex constructor above
1184 | // saves 17 bytes per call site.
1185 | LogMessage(const char* file, int line, LogSeverity severity);
1186 |
1187 | // Constructor to log this message to a specified sink (if not NULL).
1188 | // Implied are: ctr = 0, send_method = &LogMessage::SendToSinkAndLog if
1189 | // also_send_to_log is true, send_method = &LogMessage::SendToSink otherwise.
1190 | LogMessage(const char* file, int line, LogSeverity severity, LogSink* sink,
1191 | bool also_send_to_log);
1192 |
1193 | // Constructor where we also give a vector pointer
1194 | // for storing the messages (if the pointer is not NULL).
1195 | // Implied are: ctr = 0, send_method = &LogMessage::SaveOrSendToLog.
1196 | LogMessage(const char* file, int line, LogSeverity severity,
1197 | std::vector* outvec);
1198 |
1199 | // Constructor where we also give a string pointer for storing the
1200 | // message (if the pointer is not NULL). Implied are: ctr = 0,
1201 | // send_method = &LogMessage::WriteToStringAndLog.
1202 | LogMessage(const char* file, int line, LogSeverity severity,
1203 | std::string* message);
1204 |
1205 | // A special constructor used for check failures
1206 | LogMessage(const char* file, int line, const CheckOpString& result);
1207 |
1208 | ~LogMessage();
1209 |
1210 | // Flush a buffered message to the sink set in the constructor. Always
1211 | // called by the destructor, it may also be called from elsewhere if
1212 | // needed. Only the first call is actioned; any later ones are ignored.
1213 | void Flush();
1214 |
1215 | // An arbitrary limit on the length of a single log message. This
1216 | // is so that streaming can be done more efficiently.
1217 | static const size_t kMaxLogMessageLen;
1218 |
1219 | // Theses should not be called directly outside of logging.*,
1220 | // only passed as SendMethod arguments to other LogMessage methods:
1221 | void SendToLog(); // Actually dispatch to the logs
1222 | void SendToSyslogAndLog(); // Actually dispatch to syslog and the logs
1223 |
1224 | // Call abort() or similar to perform LOG(FATAL) crash.
1225 | static void Fail() ;
1226 |
1227 | std::ostream& stream();
1228 |
1229 | int preserved_errno() const;
1230 |
1231 | // Must be called without the log_mutex held. (L < log_mutex)
1232 | static int64 num_messages(int severity);
1233 |
1234 | struct LogMessageData;
1235 |
1236 | private:
1237 | // Fully internal SendMethod cases:
1238 | void SendToSinkAndLog(); // Send to sink if provided and dispatch to the logs
1239 | void SendToSink(); // Send to sink if provided, do nothing otherwise.
1240 |
1241 | // Write to string if provided and dispatch to the logs.
1242 | void WriteToStringAndLog();
1243 |
1244 | void SaveOrSendToLog(); // Save to stringvec if provided, else to logs
1245 |
1246 | void Init(const char* file, int line, LogSeverity severity,
1247 | void (LogMessage::*send_method)());
1248 |
1249 | // Used to fill in crash information during LOG(FATAL) failures.
1250 | void RecordCrashReason(glog_internal_namespace_::CrashReason* reason);
1251 |
1252 | // Counts of messages sent at each priority:
1253 | static int64 num_messages_[NUM_SEVERITIES]; // under log_mutex
1254 |
1255 | // We keep the data in a separate struct so that each instance of
1256 | // LogMessage uses less stack space.
1257 | LogMessageData* allocated_;
1258 | LogMessageData* data_;
1259 |
1260 | friend class LogDestination;
1261 |
1262 | LogMessage(const LogMessage&);
1263 | void operator=(const LogMessage&);
1264 | };
1265 |
1266 | // This class happens to be thread-hostile because all instances share
1267 | // a single data buffer, but since it can only be created just before
1268 | // the process dies, we don't worry so much.
1269 | class GOOGLE_GLOG_DLL_DECL LogMessageFatal : public LogMessage {
1270 | public:
1271 | LogMessageFatal(const char* file, int line);
1272 | LogMessageFatal(const char* file, int line, const CheckOpString& result);
1273 | ~LogMessageFatal() ;
1274 | };
1275 |
1276 | // A non-macro interface to the log facility; (useful
1277 | // when the logging level is not a compile-time constant).
1278 | inline void LogAtLevel(int const severity, std::string const &msg) {
1279 | LogMessage(__FILE__, __LINE__, severity).stream() << msg;
1280 | }
1281 |
1282 | // A macro alternative of LogAtLevel. New code may want to use this
1283 | // version since there are two advantages: 1. this version outputs the
1284 | // file name and the line number where this macro is put like other
1285 | // LOG macros, 2. this macro can be used as C++ stream.
1286 | #define LOG_AT_LEVEL(severity) google::LogMessage(__FILE__, __LINE__, severity).stream()
1287 |
1288 | // A small helper for CHECK_NOTNULL().
1289 | template
1290 | T* CheckNotNull(const char *file, int line, const char *names, T* t) {
1291 | if (t == NULL) {
1292 | LogMessageFatal(file, line, new std::string(names));
1293 | }
1294 | return t;
1295 | }
1296 |
1297 | // Allow folks to put a counter in the LOG_EVERY_X()'ed messages. This
1298 | // only works if ostream is a LogStream. If the ostream is not a
1299 | // LogStream you'll get an assert saying as much at runtime.
1300 | GOOGLE_GLOG_DLL_DECL std::ostream& operator<<(std::ostream &os,
1301 | const PRIVATE_Counter&);
1302 |
1303 |
1304 | // Derived class for PLOG*() above.
1305 | class GOOGLE_GLOG_DLL_DECL ErrnoLogMessage : public LogMessage {
1306 | public:
1307 |
1308 | ErrnoLogMessage(const char* file, int line, LogSeverity severity, int ctr,
1309 | void (LogMessage::*send_method)());
1310 |
1311 | // Postpends ": strerror(errno) [errno]".
1312 | ~ErrnoLogMessage();
1313 |
1314 | private:
1315 | ErrnoLogMessage(const ErrnoLogMessage&);
1316 | void operator=(const ErrnoLogMessage&);
1317 | };
1318 |
1319 |
1320 | // This class is used to explicitly ignore values in the conditional
1321 | // logging macros. This avoids compiler warnings like "value computed
1322 | // is not used" and "statement has no effect".
1323 |
1324 | class GOOGLE_GLOG_DLL_DECL LogMessageVoidify {
1325 | public:
1326 | LogMessageVoidify() { }
1327 | // This has to be an operator with a precedence lower than << but
1328 | // higher than ?:
1329 | void operator&(std::ostream&) { }
1330 | };
1331 |
1332 |
1333 | // Flushes all log files that contains messages that are at least of
1334 | // the specified severity level. Thread-safe.
1335 | GOOGLE_GLOG_DLL_DECL void FlushLogFiles(LogSeverity min_severity);
1336 |
1337 | // Flushes all log files that contains messages that are at least of
1338 | // the specified severity level. Thread-hostile because it ignores
1339 | // locking -- used for catastrophic failures.
1340 | GOOGLE_GLOG_DLL_DECL void FlushLogFilesUnsafe(LogSeverity min_severity);
1341 |
1342 | //
1343 | // Set the destination to which a particular severity level of log
1344 | // messages is sent. If base_filename is "", it means "don't log this
1345 | // severity". Thread-safe.
1346 | //
1347 | GOOGLE_GLOG_DLL_DECL void SetLogDestination(LogSeverity severity,
1348 | const char* base_filename);
1349 |
1350 | //
1351 | // Set the basename of the symlink to the latest log file at a given
1352 | // severity. If symlink_basename is empty, do not make a symlink. If
1353 | // you don't call this function, the symlink basename is the
1354 | // invocation name of the program. Thread-safe.
1355 | //
1356 | GOOGLE_GLOG_DLL_DECL void SetLogSymlink(LogSeverity severity,
1357 | const char* symlink_basename);
1358 |
1359 | //
1360 | // Used to send logs to some other kind of destination
1361 | // Users should subclass LogSink and override send to do whatever they want.
1362 | // Implementations must be thread-safe because a shared instance will
1363 | // be called from whichever thread ran the LOG(XXX) line.
1364 | class GOOGLE_GLOG_DLL_DECL LogSink {
1365 | public:
1366 | virtual ~LogSink();
1367 |
1368 | // Sink's logging logic (message_len is such as to exclude '\n' at the end).
1369 | // This method can't use LOG() or CHECK() as logging system mutex(s) are held
1370 | // during this call.
1371 | virtual void send(LogSeverity severity, const char* full_filename,
1372 | const char* base_filename, int line,
1373 | const struct ::tm* tm_time,
1374 | const char* message, size_t message_len) = 0;
1375 |
1376 | // Redefine this to implement waiting for
1377 | // the sink's logging logic to complete.
1378 | // It will be called after each send() returns,
1379 | // but before that LogMessage exits or crashes.
1380 | // By default this function does nothing.
1381 | // Using this function one can implement complex logic for send()
1382 | // that itself involves logging; and do all this w/o causing deadlocks and
1383 | // inconsistent rearrangement of log messages.
1384 | // E.g. if a LogSink has thread-specific actions, the send() method
1385 | // can simply add the message to a queue and wake up another thread that
1386 | // handles real logging while itself making some LOG() calls;
1387 | // WaitTillSent() can be implemented to wait for that logic to complete.
1388 | // See our unittest for an example.
1389 | virtual void WaitTillSent();
1390 |
1391 | // Returns the normal text output of the log message.
1392 | // Can be useful to implement send().
1393 | static std::string ToString(LogSeverity severity, const char* file, int line,
1394 | const struct ::tm* tm_time,
1395 | const char* message, size_t message_len);
1396 | };
1397 |
1398 | // Add or remove a LogSink as a consumer of logging data. Thread-safe.
1399 | GOOGLE_GLOG_DLL_DECL void AddLogSink(LogSink *destination);
1400 | GOOGLE_GLOG_DLL_DECL void RemoveLogSink(LogSink *destination);
1401 |
1402 | //
1403 | // Specify an "extension" added to the filename specified via
1404 | // SetLogDestination. This applies to all severity levels. It's
1405 | // often used to append the port we're listening on to the logfile
1406 | // name. Thread-safe.
1407 | //
1408 | GOOGLE_GLOG_DLL_DECL void SetLogFilenameExtension(
1409 | const char* filename_extension);
1410 |
1411 | //
1412 | // Make it so that all log messages of at least a particular severity
1413 | // are logged to stderr (in addition to logging to the usual log
1414 | // file(s)). Thread-safe.
1415 | //
1416 | GOOGLE_GLOG_DLL_DECL void SetStderrLogging(LogSeverity min_severity);
1417 |
1418 | //
1419 | // Make it so that all log messages go only to stderr. Thread-safe.
1420 | //
1421 | GOOGLE_GLOG_DLL_DECL void LogToStderr();
1422 |
1423 | //
1424 | // Make it so that all log messages of at least a particular severity are
1425 | // logged via email to a list of addresses (in addition to logging to the
1426 | // usual log file(s)). The list of addresses is just a string containing
1427 | // the email addresses to send to (separated by spaces, say). Thread-safe.
1428 | //
1429 | GOOGLE_GLOG_DLL_DECL void SetEmailLogging(LogSeverity min_severity,
1430 | const char* addresses);
1431 |
1432 | // A simple function that sends email. dest is a commma-separated
1433 | // list of addressess. Thread-safe.
1434 | GOOGLE_GLOG_DLL_DECL bool SendEmail(const char *dest,
1435 | const char *subject, const char *body);
1436 |
1437 | GOOGLE_GLOG_DLL_DECL const std::vector& GetLoggingDirectories();
1438 |
1439 | // For tests only: Clear the internal [cached] list of logging directories to
1440 | // force a refresh the next time GetLoggingDirectories is called.
1441 | // Thread-hostile.
1442 | void TestOnly_ClearLoggingDirectoriesList();
1443 |
1444 | // Returns a set of existing temporary directories, which will be a
1445 | // subset of the directories returned by GetLogginDirectories().
1446 | // Thread-safe.
1447 | GOOGLE_GLOG_DLL_DECL void GetExistingTempDirectories(
1448 | std::vector* list);
1449 |
1450 | // Print any fatal message again -- useful to call from signal handler
1451 | // so that the last thing in the output is the fatal message.
1452 | // Thread-hostile, but a race is unlikely.
1453 | GOOGLE_GLOG_DLL_DECL void ReprintFatalMessage();
1454 |
1455 | // Truncate a log file that may be the append-only output of multiple
1456 | // processes and hence can't simply be renamed/reopened (typically a
1457 | // stdout/stderr). If the file "path" is > "limit" bytes, copy the
1458 | // last "keep" bytes to offset 0 and truncate the rest. Since we could
1459 | // be racing with other writers, this approach has the potential to
1460 | // lose very small amounts of data. For security, only follow symlinks
1461 | // if the path is /proc/self/fd/*
1462 | GOOGLE_GLOG_DLL_DECL void TruncateLogFile(const char *path,
1463 | int64 limit, int64 keep);
1464 |
1465 | // Truncate stdout and stderr if they are over the value specified by
1466 | // --max_log_size; keep the final 1MB. This function has the same
1467 | // race condition as TruncateLogFile.
1468 | GOOGLE_GLOG_DLL_DECL void TruncateStdoutStderr();
1469 |
1470 | // Return the string representation of the provided LogSeverity level.
1471 | // Thread-safe.
1472 | GOOGLE_GLOG_DLL_DECL const char* GetLogSeverityName(LogSeverity severity);
1473 |
1474 | // ---------------------------------------------------------------------
1475 | // Implementation details that are not useful to most clients
1476 | // ---------------------------------------------------------------------
1477 |
1478 | // A Logger is the interface used by logging modules to emit entries
1479 | // to a log. A typical implementation will dump formatted data to a
1480 | // sequence of files. We also provide interfaces that will forward
1481 | // the data to another thread so that the invoker never blocks.
1482 | // Implementations should be thread-safe since the logging system
1483 | // will write to them from multiple threads.
1484 |
1485 | namespace base {
1486 |
1487 | class GOOGLE_GLOG_DLL_DECL Logger {
1488 | public:
1489 | virtual ~Logger();
1490 |
1491 | // Writes "message[0,message_len-1]" corresponding to an event that
1492 | // occurred at "timestamp". If "force_flush" is true, the log file
1493 | // is flushed immediately.
1494 | //
1495 | // The input message has already been formatted as deemed
1496 | // appropriate by the higher level logging facility. For example,
1497 | // textual log messages already contain timestamps, and the
1498 | // file:linenumber header.
1499 | virtual void Write(bool force_flush,
1500 | time_t timestamp,
1501 | const char* message,
1502 | int message_len) = 0;
1503 |
1504 | // Flush any buffered messages
1505 | virtual void Flush() = 0;
1506 |
1507 | // Get the current LOG file size.
1508 | // The returned value is approximate since some
1509 | // logged data may not have been flushed to disk yet.
1510 | virtual uint32 LogSize() = 0;
1511 | };
1512 |
1513 | // Get the logger for the specified severity level. The logger
1514 | // remains the property of the logging module and should not be
1515 | // deleted by the caller. Thread-safe.
1516 | extern GOOGLE_GLOG_DLL_DECL Logger* GetLogger(LogSeverity level);
1517 |
1518 | // Set the logger for the specified severity level. The logger
1519 | // becomes the property of the logging module and should not
1520 | // be deleted by the caller. Thread-safe.
1521 | extern GOOGLE_GLOG_DLL_DECL void SetLogger(LogSeverity level, Logger* logger);
1522 |
1523 | }
1524 |
1525 | // glibc has traditionally implemented two incompatible versions of
1526 | // strerror_r(). There is a poorly defined convention for picking the
1527 | // version that we want, but it is not clear whether it even works with
1528 | // all versions of glibc.
1529 | // So, instead, we provide this wrapper that automatically detects the
1530 | // version that is in use, and then implements POSIX semantics.
1531 | // N.B. In addition to what POSIX says, we also guarantee that "buf" will
1532 | // be set to an empty string, if this function failed. This means, in most
1533 | // cases, you do not need to check the error code and you can directly
1534 | // use the value of "buf". It will never have an undefined value.
1535 | GOOGLE_GLOG_DLL_DECL int posix_strerror_r(int err, char *buf, size_t len);
1536 |
1537 |
1538 | // A class for which we define operator<<, which does nothing.
1539 | class GOOGLE_GLOG_DLL_DECL NullStream : public LogMessage::LogStream {
1540 | public:
1541 | // Initialize the LogStream so the messages can be written somewhere
1542 | // (they'll never be actually displayed). This will be needed if a
1543 | // NullStream& is implicitly converted to LogStream&, in which case
1544 | // the overloaded NullStream::operator<< will not be invoked.
1545 | NullStream() : LogMessage::LogStream(message_buffer_, 1, 0) { }
1546 | NullStream(const char* /*file*/, int /*line*/,
1547 | const CheckOpString& /*result*/) :
1548 | LogMessage::LogStream(message_buffer_, 1, 0) { }
1549 | NullStream &stream() { return *this; }
1550 | private:
1551 | // A very short buffer for messages (which we discard anyway). This
1552 | // will be needed if NullStream& converted to LogStream& (e.g. as a
1553 | // result of a conditional expression).
1554 | char message_buffer_[2];
1555 | };
1556 |
1557 | // Do nothing. This operator is inline, allowing the message to be
1558 | // compiled away. The message will not be compiled away if we do
1559 | // something like (flag ? LOG(INFO) : LOG(ERROR)) << message; when
1560 | // SKIP_LOG=WARNING. In those cases, NullStream will be implicitly
1561 | // converted to LogStream and the message will be computed and then
1562 | // quietly discarded.
1563 | template
1564 | inline NullStream& operator<<(NullStream &str, const T &) { return str; }
1565 |
1566 | // Similar to NullStream, but aborts the program (without stack
1567 | // trace), like LogMessageFatal.
1568 | class GOOGLE_GLOG_DLL_DECL NullStreamFatal : public NullStream {
1569 | public:
1570 | NullStreamFatal() { }
1571 | NullStreamFatal(const char* file, int line, const CheckOpString& result) :
1572 | NullStream(file, line, result) { }
1573 | ~NullStreamFatal() { _exit(1); }
1574 | };
1575 |
1576 | // Install a signal handler that will dump signal information and a stack
1577 | // trace when the program crashes on certain signals. We'll install the
1578 | // signal handler for the following signals.
1579 | //
1580 | // SIGSEGV, SIGILL, SIGFPE, SIGABRT, SIGBUS, and SIGTERM.
1581 | //
1582 | // By default, the signal handler will write the failure dump to the
1583 | // standard error. You can customize the destination by installing your
1584 | // own writer function by InstallFailureWriter() below.
1585 | //
1586 | // Note on threading:
1587 | //
1588 | // The function should be called before threads are created, if you want
1589 | // to use the failure signal handler for all threads. The stack trace
1590 | // will be shown only for the thread that receives the signal. In other
1591 | // words, stack traces of other threads won't be shown.
1592 | GOOGLE_GLOG_DLL_DECL void InstallFailureSignalHandler();
1593 |
1594 | // Installs a function that is used for writing the failure dump. "data"
1595 | // is the pointer to the beginning of a message to be written, and "size"
1596 | // is the size of the message. You should not expect the data is
1597 | // terminated with '\0'.
1598 | GOOGLE_GLOG_DLL_DECL void InstallFailureWriter(
1599 | void (*writer)(const char* data, int size));
1600 |
1601 | }
1602 |
1603 | #endif // _LOGGING_H_
1604 |
--------------------------------------------------------------------------------