https://github.com/rbento/cpp-visual-studio-log
Quick logging to the Visual Studio Output window.
https://github.com/rbento/cpp-visual-studio-log
cpp visual-studio
Last synced: about 1 year ago
JSON representation
Quick logging to the Visual Studio Output window.
- Host: GitHub
- URL: https://github.com/rbento/cpp-visual-studio-log
- Owner: rbento
- License: mit
- Created: 2021-01-05T11:07:48.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-07-11T16:49:12.000Z (almost 2 years ago)
- Last Synced: 2025-03-24T13:51:22.349Z (about 1 year ago)
- Topics: cpp, visual-studio
- Language: C++
- Homepage:
- Size: 28.3 KB
- Stars: 2
- Watchers: 0
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# OutputDebug.h
Convenience debug logging macros for C++ projects.
Based on the [OutputDebugStringA](https://learn.microsoft.com/en-us/windows/win32/api/debugapi/nf-debugapi-outputdebugstringa) that sends a string to the debugger for display, which then shows up in the Visual Studio Output window.
### Usage
---
```
#include "OutputDebug.h"
int main()
{
Info("GameObject.Id %d", 42);
}
```
###### The Visual Studio flag `_DEBUG` controls whether OutputDebug is enabled
This flag is present by default in Visual Studio C/C++ projects in Debug configuration and not present in Release, so nothing has to be configured.
Just in case, it is set at `Project Properties` > `Configuration Properties` > `C/C++` > `Preprocessor` > `Preprocessor Definitions`.
When disabled, calls are replaced with a noop version of the logging function.
###### Customize the output debug string and format length
```
#define _OUTPUT_DEBUG_FORMAT_LENGTH 384
#define _OUTPUT_DEBUG_STRING_LENGTH 1024
```
### Disable the external Command Prompt Console Window in Visual Studio
---
For a C++ project on Visual Studio, one can avoid launching the separate Command prompt and keeping all log in the Visual Studio Output window with the following Project Properties:
##### Linker > System > SubSystem
```
/SUBSYSTEM:WINDOWS
```
##### Linker > Command Line > Additional Options
```
/ENTRY:mainCRTStartup
```
##### Or alternatively add the preprocessor comment
```
#pragma comment(linker, "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
```
See: [https://docs.microsoft.com/en-us/cpp/build/reference/entry-entry-point-symbol][1]
[1]: https://docs.microsoft.com/en-us/cpp/build/reference/entry-entry-point-symbol