_INITIALIZE_EASYLOGGINGPP int main(void) { std::fstream f("a file that does not exist", std::ifstream::in); PLOG(INFO) << "A message with plog"; PLOG_IF(true, INFO) << "A message with plog"; PLOG_IF(false, INFO) << "A message with plog"; PCHECK(true) << "This is good"; LOG(INFO) << "This is normal info log after plog"; return 0; }
void PLogTest() { PLOG(ERROR) << "Couldn't do foo"; DPLOG(ERROR) << "Couldn't do foo"; PLOG_IF(ERROR, 1) << "Couldn't do foo"; DPLOG_IF(ERROR, 0) << "Couldn't do foo"; PCHECK(1) << "Couldn't do foo"; DPCHECK(1) << "Couldn't do foo"; }
Sock(int fd_in, int fd_out) : iostream_(fd_in, fd_out) , us_addr_len_(sizeof us_addr_) , them_addr_len_(sizeof them_addr_) , us_addr_str_{ '\0' } , them_addr_str_{ '\0' } { // Get our local IP address as "us". if (-1 != getsockname(fd_in, reinterpret_cast<struct sockaddr*>(&us_addr_), &us_addr_len_)) { switch (us_addr_len_) { case sizeof(sockaddr_in) : PCHECK(inet_ntop(AF_INET, &(reinterpret_cast<struct sockaddr_in*>( &us_addr_)->sin_addr), us_addr_str_, sizeof us_addr_str_) != nullptr); break; case sizeof(sockaddr_in6) : PCHECK(inet_ntop(AF_INET6, &(reinterpret_cast<struct sockaddr_in6*>( &us_addr_)->sin6_addr), us_addr_str_, sizeof us_addr_str_) != nullptr); break; default: LOG(ERROR) << "bogus address length (" << us_addr_len_ << ") returned from getsockname"; } } else { CHECK_EQ(ENOTSOCK, errno); // only acceptable error from getsockname } // Get the remote IP address as "them". if (-1 != getpeername(fd_out, reinterpret_cast<struct sockaddr*>(&them_addr_), &them_addr_len_)) { switch (them_addr_len_) { case sizeof(sockaddr_in) : PCHECK(inet_ntop(AF_INET, &(reinterpret_cast<struct sockaddr_in*>( &them_addr_)->sin_addr), them_addr_str_, sizeof them_addr_str_) != nullptr); break; case sizeof(sockaddr_in6) : PCHECK(inet_ntop(AF_INET6, &(reinterpret_cast<struct sockaddr_in6*>( &them_addr_)->sin6_addr), them_addr_str_, sizeof them_addr_str_) != nullptr); break; default: LOG(ERROR) << "bogus address length (" << them_addr_len_ << ") returned from getpeername"; } } else { // Ignore ENOTSOCK errors from getpeername, useful for testing. PLOG_IF(WARNING, ENOTSOCK != errno) << "getpeername failed"; } }
void CommandLine::ParseFromString(const std::wstring& command_line) { std::wstring command_line_string; TrimWhitespace(command_line, TRIM_ALL, &command_line_string); if(command_line_string.empty()) { return; } int num_args = 0; wchar_t** args = NULL; args = ::CommandLineToArgvW(command_line_string.c_str(), &num_args); PLOG_IF(FATAL, !args) << "CommandLineToArgvW failed on command line: " << command_line; InitFromArgv(num_args, args); LocalFree(args); }