static void GLibLogFunc (string domain, LogLevelFlags level, string message) { LogLevel docky_log_level; switch (level) { case LogLevelFlags.Critical: docky_log_level = LogLevel.Fatal; break; case LogLevelFlags.Error: docky_log_level = LogLevel.Error; break; case LogLevelFlags.Warning: docky_log_level = LogLevel.Warn; break; case LogLevelFlags.Info: case LogLevelFlags.Message: docky_log_level = LogLevel.Info; break; case LogLevelFlags.Debug: docky_log_level = LogLevel.Debug; break; default: docky_log_level = LogLevel.Warn; break; } Write (docky_log_level, "[{0}] {1}", domain, message); }
public static void DefaultHandler(string logDomain, LogLevelFlags logLevel, string message) { IntPtr ndom = Marshaller.StringToPtrGStrdup (logDomain); IntPtr nmess = Marshaller.StringToPtrGStrdup (message); g_log_default_handler (ndom, logLevel, nmess, IntPtr.Zero); Marshaller.Free (ndom); Marshaller.Free (nmess); }
public void WriteLog (string logDomain, LogLevelFlags flags, string format, params object [] args) { IntPtr ndom = Marshaller.StringToPtrGStrdup (logDomain); IntPtr nmessage = Marshaller.StringToPtrGStrdup (String.Format (format, args)); g_logv (ndom, flags, nmessage); Marshaller.Free (ndom); Marshaller.Free (nmessage); }
public static uint SetLogHandler (string logDomain, LogLevelFlags flags, LogFunc logFunc) { IntPtr ndom = Marshaller.StringToPtrGStrdup (logDomain); uint result = g_log_set_handler (ndom, flags, logFunc, IntPtr.Zero); Marshaller.Free (ndom); EnsureHash (); handlers [result] = logFunc; return result; }
static void NativeCallback (IntPtr log_domain_native, LogLevelFlags flags, IntPtr message_native, IntPtr user_data) { if (user_data == IntPtr.Zero) return; string log_domain = Marshaller.Utf8PtrToString (log_domain_native); string message = Marshaller.Utf8PtrToString (message_native); GCHandle gch = (GCHandle) user_data; LogFunc func = gch.Target as LogFunc; if (func != null) func (log_domain, flags, message); }
/* * Some common logging methods. * * Sample usage: * * // Print the messages for the NULL domain * LogFunc logFunc = new LogFunc (Log.PrintLogFunction); * Log.SetLogHandler (null, LogLevelFlags.All, logFunc); * * // Print messages and stack trace for Gtk critical messages * logFunc = new LogFunc (Log.PrintTraceLogFunction); * Log.SetLogHandler ("Gtk", LogLevelFlags.Critical, logFunc); * */ public static void PrintLogFunction (string domain, LogLevelFlags level, string message) { Console.WriteLine ("Domain: '{0}' Level: {1}", domain, level); Console.WriteLine ("Message: {0}", message); }
public static LogLevelFlags SetAlwaysFatal (string logDomain, LogLevelFlags fatalMask) { IntPtr ndom = Marshaller.StringToPtrGStrdup (logDomain); LogLevelFlags result = g_log_set_fatal_mask (ndom, fatalMask); Marshaller.Free (ndom); return result; }
public static LogLevelFlags SetAlwaysFatal (LogLevelFlags fatalMask) { return g_log_set_always_fatal (fatalMask); }
static extern void g_log_default_handler (IntPtr log_domain, LogLevelFlags log_level, IntPtr message, IntPtr unused_data);
static extern uint g_log_set_handler (IntPtr log_domain, LogLevelFlags flags, LogFuncNative log_func, IntPtr user_data);
public static LogLevelFlags SetAlwaysFatal(LogLevelFlags fatalMask) { return(g_log_set_always_fatal(fatalMask)); }
static void LoggerMethod (string logDomain, LogLevelFlags logLevel, string message) { if (RemainingBytes < 0) return; System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace (2, true); string msg = string.Format ("{0}-{1}: {2}\nStack trace: \n{3}", logDomain, logLevel, message, trace.ToString ()); switch (logLevel) { case LogLevelFlags.Debug: LoggingService.LogDebug (msg); break; case LogLevelFlags.Info: LoggingService.LogInfo (msg); break; case LogLevelFlags.Warning: LoggingService.LogWarning (msg); break; case LogLevelFlags.Error: case LogLevelFlags.Critical: default: LoggingService.LogError (msg); break; } RemainingBytes -= msg.Length; if (RemainingBytes < 0) LoggingService.LogError ("Disabling glib logging for the rest of the session"); }
static extern void g_log(IntPtr logDomain, LogLevelFlags logLevel, IntPtr format);
/// <summary> /// Sets the message levels which are always fatal, in any log domain. /// When a message with any of these levels is logged the program terminates. /// You can only set the levels defined by GLib to be fatal. /// <see cref="LogLevelFlags.Error"/> is always fatal. /// </summary> /// <remarks> /// You can also make some message levels fatal at runtime by setting /// the <c>G_DEBUG</c> environment variable (see /// [Running GLib Applications](glib-running.html)). /// /// Libraries should not call this function, as it affects all messages logged /// by a process, including those from other libraries. /// /// Structured log messages (using g_log_structured() and /// g_log_structured_array()) are fatal only if the default log writer is used; /// otherwise it is up to the writer function to determine which log messages /// are fatal. See [Using Structured Logging][using-structured-logging]. /// </remarks> /// <param name="fatalMask"> /// the mask containing bits set for each level /// of error which is to be fatal /// </param> /// <returns> /// the old fatal mask /// </returns> public static LogLevelFlags SetAlwaysFatal(LogLevelFlags fatalMask) { var ret = g_log_set_always_fatal(fatalMask); return(ret); }
/* <type name="LogLevelFlags" type="GLogLevelFlags" managed-name="LogLevelFlags" /> */ /* transfer-ownership:none */ static extern LogLevelFlags g_log_set_always_fatal( /* <type name="LogLevelFlags" type="GLogLevelFlags" managed-name="LogLevelFlags" /> */ /* transfer-ownership:none */ LogLevelFlags fatalMask);
public static bool HasMessage(LogLevelFlags severity, string msg) { return m_DebugEntries.Find(x => (x.severity == severity) && (x.msg == msg)) != null; }
public static LogWriterOutput Invoke(LogLevelFlags logLevel, LogField[] fields, UIntPtr nfields, IntPtr userData) { var logWriterFunc = (LogWriterFunc)GCHandle.FromIntPtr(userData).Target; return(logWriterFunc(logLevel, fields)); }
extern static LogLevelFlags g_log_set_fatal_mask(IntPtr log_domain, LogLevelFlags fatal_mask);
extern static LogLevelFlags g_log_set_always_fatal(LogLevelFlags fatal_mask);
static void LoggerMethod(IntPtr logDomainPtr, LogLevelFlags logLevel, IntPtr messagePtr) { if (RemainingBytes < 0) { return; } string logDomain = GLib.Marshaller.Utf8PtrToString(logDomainPtr); string message; try { // Marshal message manually, because the text can contain invalid UTF-8. // Specifically, with zh_CN, pango fails to render some characters and // pango's error message contains the broken UTF-8, thus on marshalling // we need to catch the exception, otherwise we end up in a recursive // glib exception handling. message = GLib.Marshaller.Utf8PtrToString(messagePtr); } catch (Exception e) { message = "Failed to convert message"; LoggingService.LogError(message, e); } var stackTraceString = new System.Diagnostics.StackTrace(2, true).ToString(); string msg = string.Format("{0}-{1}: {2}", logDomain, logLevel, message); switch (logLevel) { case LogLevelFlags.Debug: LoggingService.LogDebug(msg); break; case LogLevelFlags.Info: LoggingService.LogInfo(msg); break; case LogLevelFlags.Warning: LoggingService.LogWarning(msg); break; case LogLevelFlags.Error: case LogLevelFlags.Critical: default: var exception = new CriticalGtkException(message, stackTraceString); if (logLevel.HasFlag(LogLevelFlags.FlagFatal)) { LoggingService.LogFatalError("Fatal GLib error", exception); } else { LoggingService.LogInternalError("Critical GLib error", exception); } break; } RemainingBytes -= msg.Length; if (RemainingBytes < 0) { LoggingService.LogError("Disabling glib logging for the rest of the session"); } }
static extern void g_logv (IntPtr log_domain, LogLevelFlags flags, IntPtr message);
static extern void g_logv(IntPtr log_domain, LogLevelFlags flags, IntPtr message);
public static uint SetLogHandler (string logDomain, LogLevelFlags flags, LogFunc logFunc) { if (native_handler == null) native_handler = new LogFuncNative (NativeCallback); IntPtr ndom = Marshaller.StringToPtrGStrdup (logDomain); GCHandle gch = GCHandle.Alloc (logFunc); uint result = g_log_set_handler (ndom, flags, native_handler, (IntPtr) gch); Marshaller.Free (ndom); EnsureHash (); handlers [result] = gch; return result; }
static extern uint g_log_set_handler(IntPtr log_domain, LogLevelFlags flags, LogFunc2 log_func, LogFunc user_data);
extern static LogLevelFlags g_log_set_always_fatal (LogLevelFlags fatal_mask);
/* * Some common logging methods. * * Sample usage: * * // Print the messages for the NULL domain * LogFunc logFunc = new LogFunc (Log.PrintLogFunction); * Log.SetLogHandler (null, LogLevelFlags.All, logFunc); * * // Print messages and stack trace for Gtk critical messages * logFunc = new LogFunc (Log.PrintTraceLogFunction); * Log.SetLogHandler ("Gtk", LogLevelFlags.Critical, logFunc); * */ public static void PrintLogFunction(string domain, LogLevelFlags level, string message) { Console.WriteLine("Domain: '{0}' Level: {1}", domain, level); Console.WriteLine("Message: {0}", message); }
extern static LogLevelFlags g_log_set_fatal_mask (IntPtr log_domain, LogLevelFlags fatal_mask);
public static void PrintTraceLogFunction(string domain, LogLevelFlags level, string message) { PrintLogFunction(domain, level, message); Console.WriteLine("Trace follows:\n{0}", new System.Diagnostics.StackTrace()); }
void Invoke (string log_domain, LogLevelFlags flags, string message) { IntPtr ndom = Marshaller.StringToPtrGStrdup (log_domain); IntPtr nmess = Marshaller.StringToPtrGStrdup (message); native (ndom, flags, nmess, IntPtr.Zero); Marshaller.Free (ndom); Marshaller.Free (nmess); }
private void SetFlag(bool active, LogLevelFlags flag) { _levels = active ? _levels | flag : _levels & (~flag); }
public static void PrintTraceLogFunction (string domain, LogLevelFlags level, string message) { PrintLogFunction (domain, level, message); Console.WriteLine ("Trace follows:\n{0}", new System.Diagnostics.StackTrace ()); }
static extern void g_log_default_handler(IntPtr log_domain, LogLevelFlags log_level, IntPtr message, IntPtr unused_data);
public UnityLogger() { _levels = LogLevelFlags.Critical | LogLevelFlags.Error | LogLevelFlags.Information; }
private static LogType ToLogType(LogLevelFlags logLevelFlags) { return(logLevelFlags == LogLevelFlags.Error || logLevelFlags == LogLevelFlags.Critical ? LogType.Error : LogType.Log); }