Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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
24
Question by duggulous · Aug 17, 2010 at 10:05 PM · consolelog

How do I write to the console?

I'm writing some C# scripts for a Windows Standalone application in Unity. I'd like to print some debug messages to the Unity console, but I can't figure out how. I've read that I should be able to do this using print(), Debug.Log, or System.Console.WriteLine(), but the first two just output to the log file, not the console, and the last doesn't appear to do anything at all.

I'm new to both Unity and C#, so don't hesitate to mention potential solutions that should be obvious enough for me to already have tried them :)

For the consolation prize...

As a workaround, I've been using BareTail to watch the log file, but it kinda sucks because Unity outputs the whole stack trace every time I print(). Any way for me to suppress that?

Comment
Add comment
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

5 Replies

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

Answer by duggulous · Aug 26, 2010 at 09:18 PM

It seems that the key piece of information I was missing was that Debug.Log writes to the console only when you run the game from within unity by pressing the "play" button above the game view.

I was running my game by pressing Ctrl-B, or pressing "Build & Run" in the Build Settings window. In that case, it will only output to the log file.

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 hyliandanny · Apr 18, 2013 at 04:56 PM 1
Share

Where is the log file?

avatar image Bunny83 · Apr 18, 2013 at 06:13 PM -3
Share

They are here

or here

avatar image hyliandanny · Apr 18, 2013 at 06:34 PM 24
Share

They are here

or here

Is there really a need to be a jerk? Your suggestions are how I ended up here. Please consider consolidating useful information to a single location in the future ins$$anonymous$$d of endorsing a distributed mess of incomplete steps.

For future searchers: the following link describes the location of the log file on multiple platforms. Worked for me on a mac.

http://answers.unity3d.com/questions/9739/how-can-i-find-editor-log-file.html

avatar image spolglase · Jun 18, 2013 at 06:33 PM 1
Share

Unity has created a helpful page for where to find the log files on all the different platforms. You can find that page here:

http://docs.unity3d.com/Documentation/$$anonymous$$anual/LogFiles.html

avatar image Jimmyborofan · Apr 25, 2018 at 04:42 PM 4
Share

8 years later, when looking (and Googling') for a simple answer this is what comes up, and yet still you get *'s giving crap answers, a simple 'I don't know' or a pointer in the right direction is the decent response, not sarcastic links. I really hope that that person left the Unity forums and went back to Stackexchange where comments like that are the norm

avatar image
11

Answer by Eric5h5 · Aug 17, 2010 at 10:28 PM

print is an alias for Debug.Log, which does appear in the Unity console. There's also Debug.LogWarning and Debug.LogError, which (strangely enough) print lines labeled as warning and error messages. The latter is particularly useful if you have Error Pause selected in the console.

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 duggulous · Aug 17, 2010 at 10:54 PM 1
Share

I'm not getting any output in the Unity console when I call Debug.Log

avatar image Tetrad · Aug 18, 2010 at 01:00 AM 3
Share

Then your code probably isn't getting called.

avatar image duggulous · Aug 18, 2010 at 02:10 PM 1
Share

The output IS showing up in the log file, so I know the code is being called.

avatar image mikesx · Jan 16, 2014 at 04:02 PM 2
Share

If is showing in log file and not showing in console you might have filters turned on (top right of console)

avatar image Kastenessen · Jan 16, 2015 at 10:05 PM 1
Share

I'm having the same problem. Neither debug.log nor console.writeline have ever worked for me. I use print, cause it works every time. I don't know why.

avatar image
3

Answer by rainbow_design · Sep 12, 2015 at 07:12 PM

It seems that the debug.log and console.writeline is routed who knows where.

There is a little snippet to reroute console.writeline it to the real Unity console. I tried it it does work:

http://jacksondunstan.com/articles/2986

 using System;
 using System.IO;
 using System.Text;
  
 using UnityEngine;
  
 /// <summary>
 /// Redirects writes to System.Console to Unity3D's Debug.Log.
 /// </summary>
 /// <author>
 /// Jackson Dunstan, http://jacksondunstan.com/articles/2986
 /// </author>
 public static class UnitySystemConsoleRedirector
 {
     private class UnityTextWriter : TextWriter
     {
         private StringBuilder buffer = new StringBuilder();
  
         public override void Flush()
         {
             Debug.Log(buffer.ToString());
             buffer.Length = 0;
         }
  
         public override void Write(string value)
         {
             buffer.Append(value);
             if (value != null)
             {
                 var len = value.Length;
                 if (len > 0)
                 {
                     var lastChar = value [len - 1];
                     if (lastChar == '\n')
                     {
                         Flush();
                     }
                 }
             }
         }
  
         public override void Write(char value)
         {
             buffer.Append(value);
             if (value == '\n')
             {
                 Flush();
             }
         }
  
         public override void Write(char[] value, int index, int count)
         {
             Write(new string (value, index, count));
         }
  
         public override Encoding Encoding
         {
             get { return Encoding.Default; }
         }
     }
  
     public static void Redirect()
     {
         Console.SetOut(new UnityTextWriter());
     }
 }

To use it put the sample in assets and write UnitySystemConsoleRedirector.Redirect(); in your c# file

Comment
Add comment · 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
2

Answer by wesfrank_ · Oct 25, 2020 at 04:36 PM

This video explains it well: How To Print To The Unity Console

Comment
Add comment · 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
0

Answer by DSivtsov · Dec 16, 2021 at 07:25 PM

You can use Workaround when you use the System.Console.WriteLine() In reality the Unity editor save it to it log file. but doesn't show it in the standard Unity Debug.Console Common place of this log is C:\Users\\AppData\Local\Unity\Editor (Editor.log). You can watch it by every text Editor (more helpful Notepad++, because it can automatically update the showing content). Unity Editor also send to this file the all output of its Debug.Console (in summary its look little weird but for short checking is normal)

Comment
Add comment · 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

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

13 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

Related Questions

How do you get console messages in order? 0 Answers

How to disable errors in the console? 1 Answer

Spam at Log console 2 Answers

How do I change the default application used to open logs from the Unity editor? (on Mac) 1 Answer

command-line build: output to stdout instead of log ? 2 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