File Scanner 1.0.0
A high-performance C++ malicious file scanner.
Loading...
Searching...
No Matches
scanner::FileLogger Class Referencefinal

An implementation of ILogger that writes detections to a file. More...

#include <file_logger.h>

Inheritance diagram for scanner::FileLogger:
Inheritance graph
Collaboration diagram for scanner::FileLogger:
Collaboration graph

Public Member Functions

 FileLogger (const std::filesystem::path &log_path)
 Constructs a FileLogger and opens the specified log file.
 
void LogDetection (const std::filesystem::path &path, const std::string &hash, const std::string &verdict) override
 Logs a malicious file detection to the file in a thread-safe manner.
 
- Public Member Functions inherited from scanner::ILogger
virtual ~ILogger ()=default
 

Private Attributes

std::ofstream log_stream_
 
std::mutex mutex_
 

Detailed Description

An implementation of ILogger that writes detections to a file.

This class is thread-safe. It uses a std::mutex to synchronize access to the output file stream, ensuring that log messages from concurrent threads are not interleaved or corrupted. The file is opened upon construction and closed upon destruction.

Constructor & Destructor Documentation

◆ FileLogger()

scanner::FileLogger::FileLogger ( const std::filesystem::path &  log_path)
explicit

Constructs a FileLogger and opens the specified log file.

Parameters
log_pathThe path to the log file.
Exceptions
std::runtime_errorif the file cannot be opened for writing.

Member Function Documentation

◆ LogDetection()

void scanner::FileLogger::LogDetection ( const std::filesystem::path &  path,
const std::string &  hash,
const std::string &  verdict 
)
overridevirtual

Logs a malicious file detection to the file in a thread-safe manner.

Parameters
pathThe path to the detected file.
hashThe calculated hash of the file.
verdictThe verdict from the hash database.

Implements scanner::ILogger.

Member Data Documentation

◆ log_stream_

std::ofstream scanner::FileLogger::log_stream_
private

◆ mutex_

std::mutex scanner::FileLogger::mutex_
private

The documentation for this class was generated from the following files: