• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
18
Question by NinjaSquirrel · Jun 01, 2011 at 09:11 PM · builddebugdebuggingconsole

Is there any way to view the console in a build?

Hello, I always have issues debugging my multilayer games becuase I don't know how to view console debug logs and log-errors in a Unity build.

Is there any way to do this? Or simply a way to access existing debug log messages through runtime scripts?

Thanks.

Comment
Add comment · Show 10
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Wolfram · Jun 01, 2011 at 11:33 PM 0
Share

For standalone builds, the console output is dumped to the file ..._Data/output_log.txt It looks a bit more unintuitive than the editor's console log, since for every message printed, the callstack is also dumped.

Or you could use http://wiki.unity3d.com/index.php/DebugConsole which lets you print normal debug messages (DebugConsole.Log("...");) in the GUI layer of your game view.

EDIT: for a very convenient way that works in-app on all platforms, see @cybervaldez' answer

avatar image Fattie Wolfram · Aug 29, 2020 at 04:26 PM 0
Share

FYI the file locations have moved since this very old post, and vary by platform, and change w/ unity versions; the wiki item mentioned did not show the console (and is for years broken and was deleted for that reason, heh!)

avatar image kolmich · Oct 13, 2012 at 03:31 PM 0
Share

A very comfortable way of displaying your logs at runtime is KGFDebug. Check it out.

avatar image superme2012 kolmich · Sep 01, 2013 at 10:12 AM 0
Share

nice, should be a fee version.

avatar image hickna · Mar 25, 2016 at 11:27 PM 0
Share

Hi @NinjaSquirrel !

The easiest way is to use the Debug.LogAssertion.

 Debug.LogAssertion("$$anonymous$$essage to show in Development Build/Console");

If you want you can also create a simple log file to save your debug using some WebService or even saving in your computer (if standalone builds).

You do something like:

 private void $$anonymous$$yDebug(string message){
         Debug.Log(message);
         Debug.LogAssertion (message); //you can see in game console
 
         WWWForm form = new WWWForm();
         form.AddField("new$$anonymous$$essage", message);
         string url = "http://yourserver/saveUnityLog.php";
         WWW download = new WWW(url, form);
 }


In the file saveUnityLog.php you just need to add a new line in some file like myLog.txt. ;)

NOTE: If in standalone you can use the localhost for sure. Also is a good idea add a datetime for each message.

Good luck.

avatar image jolasman · Mar 14, 2018 at 08:00 PM 0
Share

I have a solution in my new video :)

https://youtu.be/55rkbsjhA3U

avatar image meat5000 ♦ jolasman · Mar 14, 2018 at 08:58 PM 0
Share

There was a quicker way to give that information.

LOGCAT

avatar image ashwin_dinesh · Feb 22, 2019 at 12:34 PM 0
Share

If you have Android Studio installed, then you see all the logs in the Android Studio's Logcat.

Show more comments

5 Replies

· Add your reply
  • Sort: 
avatar image
11
Best Answer

Answer by bboysil · Mar 18, 2015 at 03:55 PM

An even simpler way to do it.

Just attach this script to any scene gameObject:

This works perfectly with ANY build (debug, production) and ANY platform.

It shows EXACTLY what you would see on the console (Debug.Log, Debug.Error, errors, crashes etc)



     using UnityEngine;
     
     namespace DebugStuff
     {
         public class ConsoleToGUI : MonoBehaviour
         {
     //#if !UNITY_EDITOR
             static string myLog = "";
             private string output;
             private string stack;
     
             void OnEnable()
             {
                 Application.logMessageReceived += Log;
             }
     
             void OnDisable()
             {
                 Application.logMessageReceived -= Log;
             }
     
             public void Log(string logString, string stackTrace, LogType type)
             {
                 output = logString;
                 stack = stackTrace;
                 myLog = output + "\n" + myLog;
                 if (myLog.Length > 5000)
                 {
                     myLog = myLog.Substring(0, 4000);
                 }
             }
     
             void OnGUI()
             {
                 //if (!Application.isEditor) //Do not display in editor ( or you can use the UNITY_EDITOR macro to also disable the rest)
                 {
                     myLog = GUI.TextArea(new Rect(10, 10, Screen.width - 10, Screen.height - 10), myLog);
                 }
             }
     //#endif
         }
     }
 



Here's another version in which you can

toggle with the space bar

it also creates a full log file anywhere you want (in the example, on the desktop)

it "corrects" the simple GUI window so the text size is always readable on all screens and all platforms

 using UnityEngine;
 
 public class ConsoleToGUI : MonoBehaviour
 {
     string myLog = "*begin log";
     string filename = "";
     bool doShow = true;
     int kChars = 700;
     void OnEnable() { Application.logMessageReceived += Log; }
     void OnDisable() { Application.logMessageReceived -= Log; }
     void Update() { if (Input.GetKeyDown(KeyCode.Space)) { doShow = !doShow; } }
     public void Log(string logString, string stackTrace, LogType type)
     {
        // for onscreen...
         myLog = myLog + "\n" + logString;
         if (myLog.Length > kChars) { myLog = myLog.Substring(myLog.Length - kChars); }
 
         // for the file ...
         if (filename == "")
         {
             string d = System.Environment.GetFolderPath(
                System.Environment.SpecialFolder.Desktop) + "/YOUR_LOGS";
             System.IO.Directory.CreateDirectory(d);
             string r = Random.Range(1000, 9999).ToString();
             filename = d + "/log-" + r + ".txt";
         }
         try { System.IO.File.AppendAllText(filename, logString + "\n"); }
         catch { }
     }
 
     void OnGUI()
     {
         if (!doShow) { return; }
         GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity,
            new Vector3(Screen.width / 1200.0f, Screen.height / 800.0f, 1.0f));
         GUI.TextArea(new Rect(10, 10, 540, 370), myLog);
     }
 }



Obviously, if you prefer to use Unity.UI rather than the legacy "GUI", it is completely trivial to write it to a UI.Text in your Canvas.



Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fattie · Aug 27, 2020 at 01:53 PM 0
Share

It's amazing this doesn't have 100,000,000 votes

avatar image Owlbear_Headspin · Oct 24, 2020 at 04:05 PM 0
Share

Game changer. Thanks so much!

avatar image Sheffield · Nov 04, 2020 at 11:13 AM 0
Share

This is good, however it does not capture logs produced on a thread. Is there a solution for this?

avatar image
13

Answer by justinl · Apr 19, 2013 at 05:21 PM

An easy way is to set your build to a Development Build (in the build settings) and then use Debug.LogError(). This will show up in the console build.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fredsa · Aug 28, 2016 at 07:54 PM 0
Share

Note that you indeed have to log an error to make the console visible, i.e. Debug.LogError("This message will make the console appear in Development Builds"); Although you can hide the console using Debug.developerConsoleVisible = false it's not possible to show the console by settings the value to true. This is documented in https://docs.unity3d.com/ScriptReference/Debug-developerConsoleVisible.html

avatar image
3

Answer by shcipwa · Apr 09, 2014 at 08:49 AM

Came looking for this answer, none of these answers are correct, found the correct answer in the uLinkConsoleGUI script:

UnityEngine.Application.RegisterLogCallback(CaptureLog); https://docs.unity3d.com/ScriptReference/Application.LogCallback.html

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Wolfram · Apr 09, 2014 at 10:34 AM 3
Share

Three of the answers presented here (including the accepted one) are "correct", they all provide methods and tips on how to access debug output. What is not differentiated, however, is the build platform. For example, you'll only find the output_log.txt in standalone builds, not on mobile builds.

The RegisterLogCallback() you mentioned does not answer the question, as it does not show you any "console debug log", it just gives you an in-game method to access the most recent log message. If you want to log that into a physical file (or even just display it on-screen), you would have to write additional code, which you neither presented, nor mentioned.

avatar image shcipwa · Apr 14, 2014 at 04:06 AM 2
Share

I came looking for the same information as the original post, none of the answers were what I was looking for. Which was a specific API that gives "a way to access existing debug log messages through runtime scripts". The accepted solution proposes to completely bypass the built in logging engine. This is bad practice in my opinion

avatar image Wolfram · Jan 29, 2015 at 12:01 PM 0
Share

Hm, the current wiki version of DebugConsole does indeed log on-screen only, not in the actual console, which doesn't make much sense. In the version we're using, there's a simple call to Debug.Log to fix this. I'd update the wiki myself, but I don't have my login with me, and registering a new account apparently is a buggy PITA...

avatar image Fattie · Aug 29, 2020 at 04:31 PM 0
Share

Obviously this is the correct answer - fortunately it's now easy to do this in Unity, at last.

avatar image
25

Answer by 5argon · Aug 06, 2017 at 04:57 AM

Sorry for necro-ing the post but in Unity 2017.1 you can connect your device to Unity and then look at the log from your computer. I found this better than trying to print the log on your device's screen. On the downside it prints a bit more than you want (it includes Android system message sometimes, for example.)

alt text


screenshot-2017-08-06-115534.png (64.4 kB)
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image huulong · Dec 02, 2018 at 01:47 AM 0
Share

If you Build and Run a development build, it will also automatically connect to it. Won't work with Release build. On Windows, you may need to confirm that you accept private network connections in the warning popup that appears on launch.

avatar image
1

Answer by Fattie · Sep 23, 2020 at 04:52 PM

Fortunately nowadays (2020) it is now quite easy to do this

toggle with the space bar

it also creates a full log file anywhere you want (in the example, on the desktop)

it "corrects" the simple GUI window so the text size is always readable on all screens and all platforms

 using UnityEngine;
 
 public class ConsoleToGUI : MonoBehaviour
 {
     string myLog = "*begin log";
     string filename = "";
     bool doShow = true;
     int kChars = 700;
     void OnEnable() { Application.logMessageReceived += Log; }
     void OnDisable() { Application.logMessageReceived -= Log; }
     void Update() { if (Input.GetKeyDown(KeyCode.Space)) { doShow = !doShow; } }
     public void Log(string logString, string stackTrace, LogType type)
     {
        // for onscreen...
         myLog = myLog + "\n" + logString;
         if (myLog.Length > kChars) { myLog = myLog.Substring(myLog.Length - kChars); }
 
         // for the file ...
         if (filename == "")
         {
             string d = System.Environment.GetFolderPath(
                System.Environment.SpecialFolder.Desktop) + "/YOUR_LOGS";
             System.IO.Directory.CreateDirectory(d);
             string r = Random.Range(1000, 9999).ToString();
             filename = d + "/log-" + r + ".txt";
         }
         try { System.IO.File.AppendAllText(filename, logString + "\n"); }
         catch { }
     }
 
     void OnGUI()
     {
         if (!doShow) { return; }
         GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity,
            new Vector3(Screen.width / 1200.0f, Screen.height / 800.0f, 1.0f));
         GUI.TextArea(new Rect(10, 10, 540, 370), myLog);
     }
 }



Obviously, if you prefer to use Unity.UI rather than the legacy "GUI", it is completely trivial to write it to a UI.Text in your Canvas.



Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image glenneroo · Jan 09 at 04:58 AM 0
Share

This is 100% plagiarized from the accepted answer (2nd code snippet), even including the info preceding and following the code snippet! I don't understand what value this brings.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

33 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Double clicking console output does not take me to the corresponding line in code. 1 Answer

Developer Console doesn't show up when using BuildOptions.Developer 0 Answers

Unity Debug Console - I want to input things during Runtime 1 Answer

Is there a way to see what unity is building as it builds. 0 Answers

How to use Webgl Debug Symbols? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges