In addition to the core structure, Google-glog also provides unified and concise interfaces for use through macro techniques.
At the same time, the namespace should be used to minimize name conflicts and provide a brief logstore.
Macro Assistant
- Provides a unified and concise log output interface through macros
- Simple use of log output interfaces such as log (Info) and log (error)
- Rich log output extensions through macros
- Provides helper macros such as if and check to simplify code.
Programming Skills
- Namespace usage
- Because it is used as a library, namespace classes are used in glog to avoid name conflicts.
- The glog library interface space is provided through the Google namespace, and the internal implementation is further encapsulated into the nested namespace
- Macro skills: shunting
- The debug macro can be used to locate the log output to the logmessage or the nullstream with nothing to output.
- Macro tips: Hide
- The core of log output is implemented through logmessage and other classes, and rich interfaces such as conditional logs and check logs are provided through macros.
- Macro tips: clean
- When using macros, the # UNDEF operation will be performed after use to ensure that the macro of the library will not interfere with the Program of using the library.
- Macro skills: assertions
- In mutex. H, # define mutexlock (x)... is defined to ensure that the synchronization lock will not encounter errors such as mutexlock * Lock = new mutexlock (& mu ).
- Macro skills: skills
- 1. Use # error, there is... in the # If condition to directly output the macro of the error message. The error prompt is displayed during compilation.
- 2. Use do {...} while (0) in macro definition to ensure macro content as a whole and avoid macro expansion problems:
- For example, when # define call () A (); B () is called if (1 <0) Call (), it is extended to if (1 <0) (); B () and B () will always be called
Summary
The above is just a summary of my reference to online materials and reading Source Code. It has not been applied in actual projects.
Reading the source code is also a pleasure.