Panoptes 1.0.0
Endpoint Detection and Response
Loading...
Searching...
No Matches
Functions
pano_log.h File Reference
#include <string>

Go to the source code of this file.

Functions

void WriteToLogFile (const std::string &message)
 

Function Documentation

◆ WriteToLogFile()

void WriteToLogFile ( const std::string &  message)

Definition at line 32 of file pano_log.cpp.

32 {
33 static DWORD currentFileNumber = 0;
34 static HANDLE hFile = INVALID_HANDLE_VALUE;
35
36 std::wstring fullPath;
37 DWORD bytesWritten;
38
39 // Ensure the log directory exists
41 std::wcerr << L"Failed to create log directory" << std::endl;
42 return;
43 }
44
45 if (hFile == INVALID_HANDLE_VALUE || GetFileSize(hFile, NULL) >= MAX_FILE_SIZE) {
46 if (hFile != INVALID_HANDLE_VALUE) {
47 CloseHandle(hFile);
48 currentFileNumber++;
49 }
50
51 std::wostringstream oss;
52 oss << LOG_FOLDER << BASE_FILENAME;
53 if (currentFileNumber > 0) {
54 oss << currentFileNumber;
55 }
56 oss << FILE_EXTENSION;
57 fullPath = oss.str();
58
59 hFile = CreateFileW(
60 fullPath.c_str(),
61 FILE_APPEND_DATA, // Changed from GENERIC_WRITE to FILE_APPEND_DATA
62 FILE_SHARE_READ,
63 NULL,
64 OPEN_ALWAYS, // Changed from CREATE_ALWAYS to OPEN_ALWAYS
65 FILE_ATTRIBUTE_NORMAL,
66 NULL
67 );
68
69 if (hFile == INVALID_HANDLE_VALUE) {
70 std::wcerr << L"Failed to open log file: " << fullPath << std::endl;
71 return;
72 }
73
74 // Move file pointer to the end of the file
75 SetFilePointer(hFile, 0, NULL, FILE_END);
76 }
77
78 if (!WriteFile(hFile, message.c_str(), message.length() * sizeof(char), &bytesWritten, NULL)) {
79 std::wcerr << L"Failed to write to log file" << std::endl;
80 }
81}
unsigned long DWORD
Definition inject.h:2
bool EnsureDirectoryExists(const std::wstring &path)
Definition pano_log.cpp:6
#define BASE_FILENAME
#define LOG_FOLDER
#define MAX_FILE_SIZE
#define FILE_EXTENSION

References BASE_FILENAME, EnsureDirectoryExists(), FILE_EXTENSION, LOG_FOLDER, and MAX_FILE_SIZE.

Referenced by DisplayEventInfo().