Table of Contents
The std::clog object is the standard logging output stream in C++. It is intended for writing informational messages, debugging information, and program logs. Unlike std::cerr, which is typically reserved for error messages, std::clog is used for general logging purposes.
The std::clog stream is buffered, meaning that output may be stored temporarily before being written to the output device. Buffering improves performance when writing large amounts of log data.
Source Code #
#include <iostream>
int main()
{
std::cout << "Application started.\n";
std::clog << "Log: Initializing resources.\n";
std::clog << "Log: Loading configuration.\n";
std::cout << "Application running.\n";
return 0;
}
Output #
Application started.
Log: Initializing resources.
Log: Loading configuration.
Application running.
Explanation #
std::clogis the standard logging output stream defined in the<iostream>library.- It is commonly used to display diagnostic messages, debugging information, and application logs.
- Unlike
std::cerr,std::clogis buffered, allowing multiple log messages to be grouped before they are written to the output device. - Buffering generally improves output performance, especially when producing large amounts of logging information.
- The stream insertion operator (
<<) is used withstd::clogin the same way as withstd::coutandstd::cerr. - Using
std::cloghelps separate logging information from normal program output and error messages. return 0;terminates the program successfully.