Ejemplo n.º 1
0
		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);
		}
Ejemplo n.º 2
0
 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);
 }
Ejemplo n.º 3
0
		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);
		}
Ejemplo n.º 4
0
		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;
		}
Ejemplo n.º 5
0
		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);
		}
Ejemplo n.º 6
0
		/*
		 * 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);
		}
Ejemplo n.º 7
0
		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;
		}
Ejemplo n.º 8
0
		public static LogLevelFlags SetAlwaysFatal (LogLevelFlags fatalMask)
		{
			return g_log_set_always_fatal (fatalMask);
		}
Ejemplo n.º 9
0
		static extern void g_log_default_handler (IntPtr log_domain, LogLevelFlags log_level, IntPtr message, IntPtr unused_data);
Ejemplo n.º 10
0
		static extern uint g_log_set_handler (IntPtr log_domain, LogLevelFlags flags, LogFuncNative log_func, IntPtr user_data);
Ejemplo n.º 11
0
 public static LogLevelFlags SetAlwaysFatal(LogLevelFlags fatalMask)
 {
     return(g_log_set_always_fatal(fatalMask));
 }
Ejemplo n.º 12
0
		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");
		}
Ejemplo n.º 13
0
 static extern void g_log(IntPtr logDomain, LogLevelFlags logLevel, IntPtr format);
Ejemplo n.º 14
0
        /// <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);
        }
Ejemplo n.º 15
0
 /* <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);
Ejemplo n.º 16
0
 public static bool HasMessage(LogLevelFlags severity, string msg)
 {
     return m_DebugEntries.Find(x => (x.severity == severity) && (x.msg == msg)) != null;
 }
Ejemplo n.º 17
0
        public static LogWriterOutput Invoke(LogLevelFlags logLevel, LogField[] fields, UIntPtr nfields, IntPtr userData)
        {
            var logWriterFunc = (LogWriterFunc)GCHandle.FromIntPtr(userData).Target;

            return(logWriterFunc(logLevel, fields));
        }
Ejemplo n.º 18
0
 extern static LogLevelFlags g_log_set_fatal_mask(IntPtr log_domain, LogLevelFlags fatal_mask);
Ejemplo n.º 19
0
 extern static LogLevelFlags g_log_set_always_fatal(LogLevelFlags fatal_mask);
Ejemplo n.º 20
0
        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");
            }
        }
Ejemplo n.º 21
0
		static extern void g_logv (IntPtr log_domain, LogLevelFlags flags, IntPtr message);
Ejemplo n.º 22
0
 static extern void g_logv(IntPtr log_domain, LogLevelFlags flags, IntPtr message);
Ejemplo n.º 23
0
		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;
		}
Ejemplo n.º 24
0
 static extern uint g_log_set_handler(IntPtr log_domain, LogLevelFlags flags, LogFunc2 log_func, LogFunc user_data);
Ejemplo n.º 25
0
		extern static LogLevelFlags g_log_set_always_fatal (LogLevelFlags fatal_mask);
Ejemplo n.º 26
0
        /*
         * 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);
        }
Ejemplo n.º 27
0
		extern static LogLevelFlags g_log_set_fatal_mask (IntPtr log_domain, LogLevelFlags fatal_mask);
Ejemplo n.º 28
0
 public static void PrintTraceLogFunction(string domain, LogLevelFlags level, string message)
 {
     PrintLogFunction(domain, level, message);
     Console.WriteLine("Trace follows:\n{0}", new System.Diagnostics.StackTrace());
 }
Ejemplo n.º 29
0
			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);
			}
Ejemplo n.º 30
0
 private void SetFlag(bool active, LogLevelFlags flag)
 {
     _levels = active
         ? _levels | flag
         : _levels & (~flag);
 }
Ejemplo n.º 31
0
		public static void PrintTraceLogFunction (string domain, LogLevelFlags level, string message)
		{
			PrintLogFunction (domain, level, message);
			Console.WriteLine ("Trace follows:\n{0}", new System.Diagnostics.StackTrace ());
		}
Ejemplo n.º 32
0
 static extern void g_log_default_handler(IntPtr log_domain, LogLevelFlags log_level, IntPtr message, IntPtr unused_data);
Ejemplo n.º 33
0
 public UnityLogger()
 {
     _levels = LogLevelFlags.Critical | LogLevelFlags.Error | LogLevelFlags.Information;
 }
Ejemplo n.º 34
0
 private static LogType ToLogType(LogLevelFlags logLevelFlags)
 {
     return(logLevelFlags == LogLevelFlags.Error || logLevelFlags == LogLevelFlags.Critical
         ? LogType.Error
         : LogType.Log);
 }