mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2026-04-26 12:55:14 -06:00
Removed read/write from VirtualFile (no use since reading via fptr requires handle) Note to self regarding stat()
53 lines
1.2 KiB
C++
53 lines
1.2 KiB
C++
// SPDX-FileCopyrightText: Copyright 2025 shadPS4 Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#include "common/logging/log.h"
|
|
#include "core/file_sys/devices/logger.h"
|
|
#include "core/libraries/kernel/file_system.h"
|
|
|
|
namespace Core::Devices {
|
|
|
|
Logger::Logger(std::string prefix, bool is_err) : prefix(std::move(prefix)), is_err(is_err) {}
|
|
|
|
Logger::~Logger() = default;
|
|
|
|
s64 Logger::write(const void* buf, u64 nbytes) {
|
|
log(static_cast<const char*>(buf), nbytes);
|
|
return nbytes;
|
|
}
|
|
|
|
s32 Logger::fsync() {
|
|
log_flush();
|
|
return 0;
|
|
}
|
|
|
|
void Logger::log(const char* buf, u64 nbytes) {
|
|
std::scoped_lock lock{mtx};
|
|
const char* end = buf + nbytes;
|
|
for (const char* it = buf; it < end; ++it) {
|
|
char c = *it;
|
|
if (c == '\r') {
|
|
continue;
|
|
}
|
|
if (c == '\n') {
|
|
log_flush();
|
|
continue;
|
|
}
|
|
buffer.push_back(c);
|
|
}
|
|
}
|
|
|
|
void Logger::log_flush() {
|
|
std::scoped_lock lock{mtx};
|
|
if (buffer.empty()) {
|
|
return;
|
|
}
|
|
if (is_err) {
|
|
LOG_ERROR(Tty, "[{}] {}", prefix, std::string_view{buffer});
|
|
} else {
|
|
LOG_INFO(Tty, "[{}] {}", prefix, std::string_view{buffer});
|
|
}
|
|
buffer.clear();
|
|
}
|
|
|
|
} // namespace Core::Devices
|