How about getting HideInCallstack to work right?

Suppose that you have the following method to relieve you from typing source and context over and over:

    public static class ObjectExtensions
    {
        [HideInCallstack]
        public static void Log(this Object source, LogType logType, object message, Object? context = null)
        {
            Debug.unityLogger.Log(logType, source.GetType().Name, message, context ? context : source);
        }
    }

While this does work, the Unity console is terribly stupid; when you double-click the log entry, it will open that very method on your IDE which kind of defeats the purpose of Strip logging callstack setting.

From usability standpoint, it would make a lot of sense that, when double-clicking a log entry that it opens the actual method where that message was logged in first instance, and not another method; don’t you agree? :slight_smile:

7 Likes

Actually it doesn’t work at all for me anymore (2022.2.18f1) :frowning:

1 Like

Just encountered this as well in the 2022 LTS, pretty disappointed. I thought the main use-case would be wrapper classes for logging, json, etc…
The option in the console settings for “Strip logging calls” seemed broken until I toggled it on and off and restarted the editor.

Reported as IN-49697.

I wrote a logging solution and realized how broken this attribute is - it doesn’t work at all anymore in 2022.3 LTS.

3 Likes

Was hoping for the same behaviour as well.

I’ve been writing my own log wrapper for my new project, and this problem bothered me a lot. I’ve found a solution, though it would be nice if Unity added this functionality to the attribute because it makes sense that the double click would move to the top line from the call stack that is visible in the console, not just hide the text.

Anyway, the solution that might work very well depending on the structure of your project is to make your log wrapper into a non-static class with additional logic for your logs and then call functions on the instance of this class.

I’ve base classes for both MonoBehaviours and SO so in my case I just needed to write one line in each of those files to have all of the existing logs in my project use my custom system:

public abstract class RSMonoBehaviour : SerializedMonoBehaviour
{
    protected RSLogger Debug { get; } = new RSLogger();
}

RSLogger has the same functions as the default Unity logger with some additional, optional parameters, and because the name of the property is the same as Unity’s class the usage looks exactly the same as in the default logger.

1 Like

Does this still work in Unity 6? I cannot get it to ignore methods on the callstack when double clicking exceptions in the log.

This has been discussed before. HideInCallstack will hide the method from the log (if you check “Strip logging callstack”), but wont prevent opening it with double click on the console.
image

If you really want this right now, the way to go is wrapping your Logging class or extension, into a separated, pre-compiled DLL.

it seems obvious not to open it through double click, but take into account that this was probably designed to hide intermediate systems that might pollute the callstack without providing relevant context, not to directly hide direct Debug.Log calls.

Would be nice to have it though

1 Like

Just name your logger class with XXLogger

6 Likes

I can confirm that this does work, although it doesn’t seem to be officially supported by Unity. It seems to work because internally they check for the specific string Logger.Log in the callstack, which corresponds to their internal logging APIs. Buuut if you happen to have your own class and methods called, say, MyMagicLogger.LogAllTheThings(), that still contains Logger.Log, so that will become the function that the IDE opens to when you double-click in the console. So it does work for now, but it’s kinda sketch and I wouldn’t be surprised if it breaks in the future.

2 Likes