Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
7
Question by mhardy · Oct 13, 2011 at 11:28 PM · debuglogging

Debug Wrapper Class

I'd like to create a class that wraps Debug.Log so I can enhance logging. To start, I created something very simple:

public static class Log  
{  
  public static void Format(string format, params object[] args)  
  {  
    Debug.Log(string.Format(format, args));  
  }  
}  

The problem is, when the log message appears in the console, double clicking it will bring you to this classes Debug.Log statement rather than the actual code where Log.Format was called.

Anyone found a way around this? That is, a way to wrap Debug.Log such that when clicked in the console you're taken to the source line that called the wrapper, and not to the wrapper itself.

Comment
Add comment · Show 3
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 da_chinese · Nov 14, 2011 at 06:15 PM 0
Share

I've got the same issue - Anyone ?

avatar image Yannik · Apr 30, 2012 at 06:44 PM 0
Share

Same here. Anything?

avatar image yoyo · Aug 15, 2013 at 06:48 PM 0
Share

I did something similar on a project, but ended up creating my own log window to take the place of the Unity console, and handling double-click myself.

6 Replies

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

Answer by andy_t · Dec 03, 2013 at 09:17 AM

You can move your logging code to a separate assembly. In this case double click will ignore all stack frames on the top not from the current assembly so you'll be navigated to a proper file/line.

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 mhardy · Jan 29, 2014 at 04:18 PM 0
Share

That worked brilliantly! Thanks much andy_t.

avatar image tigertrussell · Mar 21, 2015 at 10:53 PM 0
Share

How did you move it to a "separate assembly?" I am looking to do the same thing.

avatar image yoyo · Mar 22, 2015 at 01:23 AM 1
Share

You can set up a Visual Studio project outside of the Unity Assets folder and build your code as a standalone C# project, with a reference to the UnityEngine assembly. This will create a separate assembly (DLL file) that you can copy into the Unity Assets folder (or make it build there in the first place). See http://docs.unity3d.com/$$anonymous$$anual/UsingDLL.html for details.

avatar image tigertrussell · Mar 22, 2015 at 01:35 AM 0
Share

Awesome - thank you very much @yoyo!

avatar image IC_ · Jan 28, 2019 at 02:38 AM 0
Share

I have a sub project in its own asmdef but I still navigating to the logger sources ins$$anonymous$$d of my main project. Generating dll manually every single change looks like hell

avatar image
2

Answer by szi_johnr · Jun 06, 2012 at 01:35 PM

 public static void Log(object format, params object[] paramList)
 {
     System.Diagnostics.StackFrame f = stackTrace.GetFrame(2);

     string log = string.Format("[{3}.{4}] == ",
         f.GetFileName(),        
         f.GetFileLineNumber(),      // always reports 0
         f.GetFileColumnNumber(),    // always reports 0
         f.GetMethod().ReflectedType.Name,
         f.GetMethod().Name);

     // if the last parameter is a unity object, lets feed it in as the context 
     UnityEngine.Object newContext = null;
     if(paramList.Length > 0 && paramList[paramList.Length - 1] is UnityEngine.Object)
          newContext = paramList[paramList.Length - 1] as UnityEngine.Object;
     //UnityEngine.Object context = f.GetMethod().ReflectedType;
     if (format is string)
     {
         log += format as string;
         Debug.Log(string.Format(log, paramList), newContext);
     }
     else
     {
         log += format.ToString();
         UnityEngine.Debug.Log(log, newContext);
     }
 }
 

This is the closest i've come to doing that exact thing. It when double clicking, it still takes you to the debug proxy but when you select them in the editor, it will flash the object that signaled the log statement.

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
1

Answer by DaveA · Oct 13, 2011 at 11:41 PM

I think you should be able to use this: http://msdn.microsoft.com/en-us/library/system.diagnostics.stacktrace.aspx

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 mhardy · Oct 14, 2011 at 05:40 AM 0
Share

Close. That does get me the file and line number. Still can't double click it in the console window and be taken directly to the line though.

avatar image
1

Answer by wubak · Oct 31, 2015 at 12:42 PM

This is an old thread, but came up as I was searching for a solution.

Unity now supports this internally via a logging event, for which you can designate handlers.

So try:

Application.logMessageReceived += HandlerMethodName;

The handler signature must be: HandlerMethodName(string logString, string stackTrace, LogType type)

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 mhardy · Jan 07, 2016 at 07:04 PM 0
Share

Interesting. But here you can't change the log message that's output or change the logging signatures - which is key.

avatar image wubak · Jan 07, 2016 at 10:47 PM 0
Share

Ah, you're right. I missed the crux of the question. This lets you tack additional enhancements on to logging, but doesn't let you change the log message which is sent to the console. Presumably, there's a way to do so if you have access to the source itself.

avatar image Gwom · Nov 12, 2020 at 06:26 PM 0
Share

Still helped me do exactly what i needed, never even knew such an awesome thing existed :)

avatar image
1

Answer by Inhuman Games · Jan 11, 2016 at 05:31 PM

I created a console replacement for Unity. My console lets you open any row of the callstack with a double-click. The free version is limited in that it only lets you open the top couple rows of the callstack. For some projects this is enough.

The pro version also lets you mark methods as "wrappers". The console knows to automatically ignore your wrapper functions. When you click on an entry, it walks the callstack, skipping past wrappers, opening the first non-wrapper row. It works well, and it also works with externally built DLLs as long as you include your .mdb file with your .dll file.

Check it out: http://unityconsole.com

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 amzin7000 · Sep 17, 2016 at 08:09 PM 0
Share

Had Econsole for a while, was delighted to see It had support for wrapper functions!

  • 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

14 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

Related Questions

Debug.Log results in no output? 6 Answers

How do you get OutputDebugString to show up in the Visual Studio output window? 0 Answers

Is it possible to access the previous UnityPlayer.log file at runtime before it get's overwritten? 0 Answers

Why am I seeing: error CS0117: `Debug' does not contain a definition for `LogWarning' 1 Answer

How to use Application.logMessageReceived for logging ? 3 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