Skip to content

ILog interface

wvdvegt edited this page Nov 5, 2017 · 2 revisions

ILog interface

An ILog interface can be implemented like:

    /// <summary>
    /// Executes the log operation.
    ///
    /// Implement this in Game Engine Code.
    /// </summary>
    ///
    /// <param name="severity"> The severity. </param>
    /// <param name="msg">      The message. </param>
    public void Log(Severity severity, string msg)
    {
        Debug.WriteLine(String.Format("{0}: {1}", severity, msg));
    }
  • In Unity Debug.LogFormat can also be used.

  • Assets using this interface will prevent platform dependencies in the .Net Debug class on the various development platforms.

  • The method should log to whatever logging method the game uses (Debug.WriteLine is just an example).

      /// <summary>
      /// Executes the log operation.
      ///
      /// Implement this in Game Engine Code.
      /// </summary>
      ///
      /// <param name="severity"> The severity. </param>
      /// <param name="msg">      The message. </param>
      public void Log(Severity severity, string msg)
      {
          if (((int)LogLevel.Info & (int)severity) == (int)severity)
          {
              Debug.WriteLine(String.Format("{0}: {1}", severity, msg));
          }
      }
    
  • Using Severity correctly in assets will allow for easy filtering.

  • The code only shows LogLevel.Info (i.e. Severity.Critical..Severity.Information) or higher logging messages and removes Severity.Verbose messages.

      /// <summary>
      /// Executes the log operation.
      ///
      /// Implement this in Game Engine Code.
      /// </summary>
      ///
      /// <param name="severity"> The severity. </param>
      /// <param name="msg">      The message. </param>
      public void Log(Severity severity, string msg)
      {
          //
      }
    
  • An empty method will suppress all debug logging.

Clone this wiki locally