Agrarsense
SimulatorLog.cpp
Go to the documentation of this file.
1// Copyright (c) 2024 FrostBit Software Lab at the Lapland University of Applied Sciences
2//
3// This work is licensed under the terms of the MIT license.
4// For a copy, see <https://opensource.org/licenses/MIT>.
5
6#include "SimulatorLog.h"
7#include "LogFile.h"
9
10#include "Async/Async.h"
11
13
14void SimulatorLog::Log(const FString& Message, bool LogToTextFile, bool LogToROS)
15{
16 if (!IsInGameThread())
17 {
18 // If not in game thread, call itself back within the game thread.
19 AsyncTask(ENamedThreads::GameThread, [Message, LogToTextFile, LogToROS]()
20 {
21 Log(Message, LogToTextFile, LogToROS);
22 });
23 return;
24 }
25
26 if (SimulatorLogFile && SimulatorLogFile->IsValidLowLevel() && LogToTextFile)
27 {
28 SimulatorLogFile->Write(Message);
29 }
30
31 if (LogToROS)
32 {
34 }
35
36#if WITH_EDITOR
37 UE_LOG(LogTemp, Warning, TEXT("SimulatorLog.cpp: %s"), *Message);
38#endif
39}
40
42{
43 if (!IsValid(SimulatorLogFile))
44 {
45 // Find or create Agrarsense.txt file
46 FLogFileSettings Settings;
49 Settings.QueueLength = 10;
50 Settings.KeepFileOpen = false;
51 SimulatorLogFile = ULogFile::CreateLogFile("Agrarsense", Settings);
52 }
53}
54
56{
57 if (IsValid(SimulatorLogFile))
58 {
60 SimulatorLogFile = nullptr;
61 }
62}
static void Log(const FString &Message, bool LogToTextFile=true, bool LogToROS=true)
static void Shutdown()
static void Create()
static ULogFile * SimulatorLogFile
Definition: SimulatorLog.h:47
static void SendMessage(const FString &Message)
Definition: InfoTopic.cpp:129
void Destroy()
Definition: LogFile.cpp:170
void Write(const FString &Text)
Definition: LogFile.cpp:119
static ULogFile * CreateLogFile(const FString &FileNameWithoutExtension, FLogFileSettings Settings=FLogFileSettings())
Definition: LogFile.cpp:17
bool KeepFileOpen
Definition: LogFile.h:42
FFileWriteOptions FileWriteOptions
Definition: LogFile.h:45
int32 QueueLength
Definition: LogFile.h:48
FFileCreationOptions FileCreationOptions
Definition: LogFile.h:36