[Tutorial]C++ How to log file without printing while making plugins

Started by habi, Sep 04, 2023, 10:04 AM

Previous topic - Next topic


My error is
Module_Name: failed on handle: 000002E205F75BC0 CURLcode: 6
which when printed on console makes it rather ugly. But at the same time, i want to let the user know what happened. So if he opens our 'server_log.txt', he can know about details of error.
Here is a fix for windows:
//File: main.cpp
#ifdef WIN32
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csb);

char msg[256]; char newmsg[512];
sprintf(msg, "Module: failed on handle: %p CURLcode: %d\r", e, result);
sprintf(newmsg, "%s%s", msg, std::string(strlen(msg), ' ').c_str());
csb.dwCursorPosition.Y == csb.srWindow.Bottom ?
csb.dwCursorPosition.Y-- : NULL;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), csb.dwCursorPosition);

It simply uses '\r' to go back to beginning of line, then print some white spaces. Finally it set cursor position to where it was before. it uses string.h