Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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
20
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 Ricna · 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

7 Replies

· Add your reply
  • Sort: 
avatar image
30
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 5 · 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 azmi_unity · Aug 24, 2021 at 11:53 AM 0
Share

It don't work with logs produced by Unity Jobs threads. (and ECS)

avatar image OnatKorucu · Nov 30, 2021 at 12:06 AM 0
Share

While a good starting point, I believe this solution is inferior to my answer which is more performant, able to silence duplicate log messages, able to hold the most recent N logs in memory while not causing memory overload, and able to collect all logs, even from different threads.

avatar image
28

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
16

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
4

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 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 glenneroo · Jan 09, 2021 at 04:58 AM 2
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.

avatar image Bunny83 glenneroo · May 15, 2021 at 08:50 AM 1
Share

Well, it's not ^^. Fattie himself did edit the accepted answer to insert his answer into the accepted one since the original author of the accepted answer hasn't been seen since 2019. When you check the revision history, you will notice that the last changes of the accepted answer were done by Fattie. (Note the revision history is a bit messy, but should record any changes made).

avatar image glenneroo Bunny83 · May 15, 2021 at 02:48 PM 0
Share

Thanks for clarification, I do admit I was confused as everyone who frequents the forums knows Fattie and you are domain experts so to plagiarize someone else's answer would be very weird! I don't appear to have access to revision history or the button is hidden. Unity could really take some tips from StackOverflow. Either way, I still don't understand the point of keeping this answer up if Fattie already edited the accepted answer - there are now 2 identical answers.

avatar image
3

Answer by BTables · 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 BTables · 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.

  • 1
  • 2
  • ›

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.

Follow this Question

Answers Answers and Comments

36 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 avatar image avatar image avatar image

Related Questions

How to use Webgl Debug Symbols? 0 Answers

libil2cpp.sym, libil2cpp.so.debug, libunity.sym.so... What should i use for il2cpp debugging? 1 Answer

Distribute terrain in zones 3 Answers

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges