Skip to content

Add ability to redirect mono stdout logging to unity's vprintf function. #1093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions mono/eglib/goutput.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ static GLogLevelFlags fatal = G_LOG_LEVEL_ERROR;
static GLogFunc default_log_func;
static gpointer default_log_func_user_data;
static GPrintFunc stdout_handler, stderr_handler;
typedef void (*vprintf_func)(const char* msg, va_list args);
static vprintf_func our_vprintf = vprintf;

static void default_stdout_handler (const gchar *string);
static void default_stderr_handler (const gchar *string);
Expand Down Expand Up @@ -274,3 +276,31 @@ g_set_printerr_handler (GPrintFunc func)
return old;
}

void wrap_our_vprintf(const gchar *format, ...)
{
va_list args;
va_start (args, format);
our_vprintf (format, args);
va_end (args);
}

static void
unity_vprintf_GPrintFunc_adapter (const gchar *string)
{
wrap_our_vprintf ("%s", string);
}

static void
unity_vprintf_GLogFunc_adapter (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data)
{
wrap_our_vprintf ("%s", message);
}

// Redirect all stdout output to unity vprintf function
void set_vprintf_func(vprintf_func func)
{
our_vprintf = func;
g_set_print_handler (unity_vprintf_GPrintFunc_adapter);
g_log_set_default_handler (unity_vprintf_GLogFunc_adapter, NULL);
}

2 changes: 1 addition & 1 deletion mono/metadata/unity-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ mono_unity_socket_security_enabled_set (gboolean enabled)

void mono_unity_set_vprintf_func (vprintf_func func)
{
//set_vprintf_func (func);
set_vprintf_func (func);
}

MONO_API gboolean
Expand Down