Skip to content

Commit 4234dde

Browse files
committed
feat/chore: Allow logging to be output to console application.
1 parent b0f8a54 commit 4234dde

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

lib/NativeCode/DynamicLibraryLoaderHelper/ConsoleApplication/ConsoleApplication.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@
2323
#include <iostream>
2424

2525
#include "include/config_legacy.h"
26+
#include "include/logging.h"
2627

2728
int main()
2829
{
30+
// Instruct the logging to mirror output to stdout.
31+
pew::eos::logging::set_mirror_to_stdout(true);
32+
2933
pew::eos::config_legacy::EOSConfig eos_config;
3034
if(pew::eos::config_legacy::try_get_eos_config(eos_config))
3135
{
@@ -36,14 +40,3 @@ int main()
3640
std::cout << "Could not load EOSConfig.";
3741
}
3842
}
39-
40-
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
41-
// Debug program: F5 or Debug > Start Debugging menu
42-
43-
// Tips for Getting Started:
44-
// 1. Use the Solution Explorer window to add/manage files
45-
// 2. Use the Team Explorer window to connect to source control
46-
// 3. Use the Output window to see build output and other messages
47-
// 4. Use the Error List window to view errors
48-
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
49-
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file

lib/NativeCode/DynamicLibraryLoaderHelper/NativeRender/include/logging.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ namespace pew::eos::logging
3838
{
3939
typedef void (*log_flush_function_t)(const char* str);
4040

41+
/**
42+
* \brief Allows an option to be set that will mirror the log messages to
43+
* stdout.
44+
* \param mirror Whether to mirror log statements to stdout.
45+
*/
46+
PEW_EOS_API_FUNC(void) set_mirror_to_stdout(const bool& mirror);
47+
4148
/**
4249
* @brief Converts an EOS log level to its corresponding string representation.
4350
*

lib/NativeCode/DynamicLibraryLoaderHelper/NativeRender/src/logging.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@
2525
#include <eos_logging.h>
2626
#include "string_helpers.h"
2727
#include <unordered_map>
28+
#include <iostream>
2829

2930
namespace pew::eos::logging
3031
{
3132
FILE* s_log_file = nullptr;
3233
std::vector<std::string> buffered_output;
34+
bool s_mirror_to_stdout = false;
3335

3436
const std::unordered_map<std::string, EOS_ELogLevel> LOGLEVEL_STR_MAP =
3537
{
@@ -87,6 +89,16 @@ namespace pew::eos::logging
8789
return EOS_ELogLevel::EOS_LOG_Verbose;
8890
}
8991

92+
/**
93+
* \brief Allows an option to be set that will mirror the log messages to
94+
* stdout.
95+
* \param mirror Whether to mirror log statements to stdout.
96+
*/
97+
PEW_EOS_API_FUNC(void) set_mirror_to_stdout(const bool& mirror)
98+
{
99+
s_mirror_to_stdout = mirror;
100+
}
101+
90102
void show_log_as_dialog(const char* log_string)
91103
{
92104
#if PLATFORM_WINDOWS
@@ -178,6 +190,11 @@ namespace pew::eos::logging
178190
{
179191
global_logf("NativePlugin (%s): %s", header, message);
180192
}
193+
194+
if (s_mirror_to_stdout)
195+
{
196+
std::cout << "NativePlugin (" << header << "): " << message << std::endl;
197+
}
181198
}
182199

183200
//-------------------------------------------------------------------------

0 commit comments

Comments
 (0)