diff options
author | Ludovic Henry <luhenry@microsoft.com> | 2017-11-28 00:37:11 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-28 00:37:11 +0300 |
commit | 984f6484666c2ee6fefec949c81fdff1189c9488 (patch) | |
tree | c73bd36899c94bbdefc0835d003b1a37c592ebf0 /mcs/class/corlib | |
parent | 20de41832a4ee7a393e432700182b01c9e775fe6 (diff) |
[sdks] Use runtime logging features to intercept Console.{Out,Error} and runtime logs for instrumentation (#6083)
* [sdks] Fix Android pick of mono runtime
* [android] Have Console.{Out,Error} go through the runtime log mechanism to ease their interception
* [sdks] Intercept runtime logs instead of Console to send back for instrumentation
* [sdks] Intercept Android test runner logging
Diffstat (limited to 'mcs/class/corlib')
-rw-r--r-- | mcs/class/corlib/System.IO/LogcatTextWriter.cs | 34 |
1 files changed, 12 insertions, 22 deletions
diff --git a/mcs/class/corlib/System.IO/LogcatTextWriter.cs b/mcs/class/corlib/System.IO/LogcatTextWriter.cs index 3d9787957be..d80638e8f23 100644 --- a/mcs/class/corlib/System.IO/LogcatTextWriter.cs +++ b/mcs/class/corlib/System.IO/LogcatTextWriter.cs @@ -3,6 +3,7 @@ using System; using System.IO; using System.Text; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace System.IO { @@ -12,13 +13,14 @@ namespace System.IO { const string LibLog = "/system/lib/liblog.so"; const string LibLog64 = "/system/lib64/liblog.so"; + readonly byte[] appname; + TextWriter stdout; - readonly string appname; StringBuilder line = new StringBuilder (); public LogcatTextWriter (string appname, TextWriter stdout) { - this.appname = appname; + this.appname = Encoding.UTF8.GetBytes (appname); this.stdout = stdout; } @@ -46,34 +48,22 @@ namespace System.IO { var o = line.ToString (); line.Clear (); - Log (LogLevel.Info, appname, o); + unsafe { + fixed (byte *b_appname = appname) + fixed (byte *b_message = Encoding.UTF8.GetBytes(o)) { + Log (b_appname, 1 << 5 /* G_LOG_LEVEL_MESSAGE */, b_message); + } + } stdout.WriteLine (o); } - enum LogLevel { - Unknown, - Default, - Verbose, - Debug, - Info, - Warn, - Error, - Fatal, - Silent - } - public static bool IsRunningOnAndroid () { return File.Exists (LibLog) || File.Exists (LibLog64); } - [DllImport ("liblog")] - static extern void __android_log_print (LogLevel level, string appname, string format, string args, IntPtr zero); - - static void Log (LogLevel level, string appname, string log) - { - __android_log_print (level, appname, "%s", log, IntPtr.Zero); - } + [MethodImpl(MethodImplOptions.InternalCall)] + static unsafe extern void Log (byte *appname, int level, byte *message); } } |