Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

Logging

Kenneth Pouncey edited this page Apr 10, 2015 · 3 revisions

CCLog

CocosSharp's implementation of logging uses System.Diagnostics.Debug.WriteLine so that it is more cross platform. Some platforms do not implement System.Console.WriteLine so using System.Diagnostics.Debug.WriteLine allows the code to work across all platforms.

Another advantage of using System.Diagnostics.Debug.WriteLine is that it is automatically conditioned to be compiled between Debug and Release compiles.

The problem for developers is that the NuGet packages that are released for CocosSharp are compiled using Release so developers will never see the internal messages that are output by CocosSharp.

To allow developers to obtain these messages we have implemented a delegate within our CCLog class that allows them to provide their own implementation if they feel the need. This way they can control how messages are output themselves.

We previously, prior to v1.4.0.0, added an interface called ICCLog that the developer would need to implement. This was an attempt at meeting developers needs rapidly and was a quick fix. In hindsight is quite awkward.

So starting in v1.4.0.0 of CocosSharp we simplified this and developers can replace the default internal logging with their own implementation a lot easier now.

Simple usage:

    CCLog.Logger = Console.WriteLine;

Simple Usage using Lambda:

    // Example of using a custom log action as a Lambda.
    CCLog.Logger = (format, args) =>
    {
        System.Diagnostics.Debug.WriteLine("CocosSharpTests: " + format, args);
    };

Usage by creating a method as follows:

// Example of using a custom log action as a method with optional parameters;
void MyLoggingFunction (string format, params object[] args)
{
    System.Diagnostics.Debug.WriteLine("MyLogger: " + format, args);
}

Using the custom MyLoggingFunction:

// Example of using a custom log action.
CCLog.Logger = MyLoggingFunction;
Clone this wiki locally