Log
How to do logs in Console
You still can call Debug.Log()
or print()
Also you can use TIM.Console.Log()
Here is an example:
TIM.Console.Log("Game started");

Also you can change the MessageType of your message:
TIM.Console.Log("Server started", MessageType.Network);

Logchain
Example
You are downloading an image from Internet in 3 stages:
Web request
Downloading
Converting downloaded data to Texture2D
You can group all these messages into one Logchain. Just give it name.
For example: "Image downloading". Here is how you can print a message:
Console.Log("Your log", MessageType.Default, "Image downloading");
So how our method can look like:
IEnumerator DownloadImage(string imageUrl)
{
WWW www = new WWW(imageUrl);
string logchain = "Image downloading";
Console.Log("Web request sent", MessageType.Network, logchain);
yield return www;
if (www.error != null)
{
Console.Log(www.error, MessageType.Error, logchain);
}
else
{
Console.Log("data has been downloaded", MessageType.Network, logchain);
Texture2D texture = www.texture;
if (texture == null)
{
Console.Log("Data doesn't contant a texture!", MessageType.Error, logchain);
}
else
{
Console.Log("Success!", MessageType.Default, logchain);
}
}
}
Lets try it!
Execute our coroutine by StartCoroutine() method. And paste image URL as argument.
private void Start()
{
// I found random image from internet and copied the URL:
StartCoroutine(DownloadImage("https://www.sunhome.ru/i/wallpapers/221/frukti-oboi.orig.jpg"));
}
Open console by ` and you can see that messages are displayed in Console window and in Logchain window as well

Hidden messages
Lets take our last example with downloading image. If we will download images many times we will have many messages in Console. But we can organize it better! We can hide logs in Console but keep them visible in Logchain window. You just need to set last argument hidden
of TIM.Console.Log()
function to true:
Console.Log("Web request sent", MessageType.Network, "Logchain name", true);
And how our function looks like now:
IEnumerator DownloadImage(string imageUrl)
{
WWW www = new WWW(imageUrl);
string logchain = "Image downloading";
Console.Log("Web request sent", MessageType.Network, logchain, true);
yield return www;
if (www.error != null)
{
Console.Log(www.error, MessageType.Error, logchain); // we don't want to hide errors
}
else
{
Console.Log("data has been downloaded", MessageType.Network, logchain, true);
Texture2D texture = www.texture;
if (texture == null)
{
Console.Log("Data doesn't contant a texture!", MessageType.Error, logchain); // we don't want to hide errors
}
else
{
Console.Log("Success!", MessageType.Default, logchain, true);
}
}
}
What we will see in Console:

You can enable visibility of hidden messages by clicking this button:

Toggle it and what you can see now:

Last updated