ExitCode139 Posted June 7 Share Posted June 7 hi, I have this strange issue where I can easily print inside game console using RE::ConsoleLog::GetSingleton()->AddString("Message"); but when I use logger::info it doesn't print anything. I am using CommonLibF4. here is my code: void OnMessage(F4SE::MessagingInterface::Message* message) { logger::info("Received message type : {}", message->type); switch (message->type) { case F4SE::MessagingInterface::kGameDataReady: RE::ConsoleLog::GetSingleton()->AddString("Plugin loaded\n"); OnLoaded(); break; case F4SE::MessagingInterface::kPreLoadGame: logger::info("Loading a Save game from : {}", (const char*)message->data); RE::ConsoleLog::GetSingleton()->AddString("Loading Saved Game!\n"); break; case F4SE::MessagingInterface::kPostSaveGame: logger::info("Game Saved!"); RE::ConsoleLog::GetSingleton()->AddString("Game Saved!\n"); break; default: break; } } Link to comment Share on other sites More sharing options...
LarannKiar Posted June 7 Share Posted June 7 Have you set up the logger? namespace Version { inline constexpr std::size_t MAJOR = 1; inline constexpr std::size_t MINOR = 0; inline constexpr std::size_t PATCH = 0; inline constexpr auto NAME = "1.0"sv; inline constexpr auto AUTHORNAME = "Your name"sv; inline constexpr auto PROJECT = "My mod"sv; } static void InitLog() { auto path = logger::log_directory(); if (!path) { return; } *path /= fmt::format(FMT_STRING("{}.log"), Version::PROJECT); auto sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(path->string(), true); auto log = std::make_shared<spdlog::logger>("F4SE"s, std::move(sink)); log->set_level(spdlog::level::info); log->flush_on(spdlog::level::info); spdlog::set_default_logger(std::move(log)); logger::info("{} v{}", Version::PROJECT, Version::NAME); } void OnMessage(F4SE::MessagingInterface::Message* message) { InitLog(); } ..\Documents\My Games\Fallout4\F4SE\My mod.log [2024-06-07 11:01:57.700] [F4SE] [info] [main.cpp:1984] My mod v1.0 16 hours ago, ExitCode139 said: but when I use logger::info it doesn't print anything. I'm not sure if I understand correctly. logger::info is for file logging while RE::ConsoleLog is to print something in the console log ("console history"). Link to comment Share on other sites More sharing options...
ExitCode139 Posted June 10 Author Share Posted June 10 On 6/7/2024 at 11:16 PM, LarannKiar said: Have you set up the logger? Hi, I always thought that this was doing that since I use CommonLibF4 it comes with this piece of code, and when I add your code it will give me some errors regarding redefinitions. extern "C" DLLEXPORT bool F4SEAPI F4SEPlugin_Query(const F4SE::QueryInterface* a_f4se, F4SE::PluginInfo* a_info) { #ifndef NDEBUG auto sink = std::make_shared<spdlog::sinks::msvc_sink_mt>(); #else auto path = logger::log_directory(); if (!path) { return false; } *path /= fmt::format(FMT_STRING("{}.log"), Version::PROJECT); auto sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(path->string(), true); #endif auto log = std::make_shared<spdlog::logger>("global log"s, std::move(sink)); #ifndef NDEBUG log->set_level(spdlog::level::trace); #else log->set_level(spdlog::level::info); log->flush_on(spdlog::level::warn); #endif spdlog::set_default_logger(std::move(log)); spdlog::set_pattern("%g(%#): [%^%l%$] %v"s); logger::info("{} v{}", Version::PROJECT, Version::NAME); a_info->infoVersion = F4SE::PluginInfo::kVersion; a_info->name = Version::PROJECT.data(); a_info->version = Version::MAJOR; if (a_f4se->IsEditor()) { logger::critical("loaded in editor"); return false; } const auto ver = a_f4se->RuntimeVersion(); if (ver < F4SE::RUNTIME_1_10_162) { logger::critical("unsupported runtime v{}", ver.string()); return false; } return true; } Link to comment Share on other sites More sharing options...
LarannKiar Posted June 10 Share Posted June 10 If the log is set up with log->set_level(spdlog::level::info); log->flush_on(spdlog::level::warn); then spdlog would flush the log after you call logger::warn (or higher log_levels; namely logger::error and logger::critical). So, log->set_level(spdlog::level::info); log->flush_on(spdlog::level::warn); logger::info("this won't be in the log."); logger::warn("this should be in the log AND the above logger::info too because the on log_level warn, spdlog flushes the log."); logger::info("this won't be in the log."); logger::error("this should be in the log AND all logger::XXXXX calls above because spdlog flushes the log again."); Check out the spdlog library for the details. If you still can't see anything written in the log the issue could be somewhere in the projects, I'm not sure. 10 hours ago, ExitCode139 said: and when I add your code it will give me some errors regarding redefinitions. You can only use the InitLog() I wrote if you don't have another code to set up the logger. Link to comment Share on other sites More sharing options...
Recommended Posts