Giter Site home page Giter Site logo

uberlogger's Introduction

UberLogger

UberLogger is a free, modular, opensource replacement for Unity's Debug.Log system. It also includes UberConsole, a replacement for Unity's editor console, an in game console version of UberConsole, and a file logger.

UberConsole looks like this:

And the in-game version looks like this:

Core Features

  • Drop in replacement for Unity's Debug.Log() methods. No code changes needed.
  • A threadsafe, modular backend that supports any number of loggers, so Debug.Log can be routed to multiple locations. The supplied file logger should work on mobile devices.
  • Included are a replacement editor console, an in-game console and a file logger.
  • Support for named debug channels - UberDebug.LogChannel("Boot", "Some message") can be filtered based on the channel name.
  • Methods may be marked as excluded from callstacks by tagging them with '[StackTraceIgnore]', to keep your logs tidy.

UberConsole Features

  • More compact view shows more errors in the same space.
  • Supports debug log channels.
  • Messages can be filtered by regular expressions.
  • Timestamps.
  • Source code can be shown inline with the callstack.
  • An in-game version of UberConsole is also provided.

Installation

  • Stick the UberLogger folder somewhere under your Unity project Assets folder.
  • To use additional features like channels, use UberDebug instead of Debug - it contains methods like Log, LogChannel, etc.
  • To view the editor UberConsole, go to Window->Show Uber Console.
  • To use UberConsole in your game, drag the UberAppConsole prefab into your scene.
  • Usage examples can be seen in the Examples folder.

Notes

  • Tested in Unity 5.x, 2017.x, free and Pro.
  • Logging disabled in non-debug builds. To force it on, define ENABLE_UBERLOGGING.
  • Due to file incompatibilities, the in-game console skin doesn't work in Unity 4 and would need to be set up again. Same with the prefab. That said, the code works, and so does the editor UberConsole.
  • Pull requests welcome!

Extensions

  • UberLogger-StructuredFile adds a structured log file format with timestamps, channel names, and control over which log messages are printed with callstacks and which are printed without.
  • UberLogger-Stackdriver adds centralized logging. Log messages will be sent from game clients to Google's Stackdriver service. The collected logs can be browsed and searched in the Stackdriver web UI.
  • UberLogger-LogChannels adds compile-time resolution and muting of log channels. This is useful for very large projects where logging to muted channels causes performance problems.

UberLogger: https://github.com/bbbscarter/UberLogger

uberlogger's People

Contributors

astruyk avatar bbbscarter avatar chugiau avatar ewanmellor avatar gunjambi avatar kalmalyzer avatar sinbad avatar wgnf avatar xrix4096 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

uberlogger's Issues

UberLogger does not show full callstack for unhandled exceptions

With the current version of UberLogger, the callstack shown for unhandled exceptions is not very useful.

Example when I raise a NotImplementedException() deep within the codebase:

Unity callstack:
callstack-unity

UberLogger callstack:
callstack-uberlogger

The UberLogger callstack is not helpful for diagnosing where things went wrong.

I'll look into this myself in some days.

Error when parsing invalid linenumber to int32

When parsing an invalid linenumber in ExtractInfoFromUnityMessage to int32 Uberlogger is throwing an error. Happened with logs from the Oculus SDK for some reason. To fix this issue I just changed this line.

//lineNumber = Convert.ToInt32(firstMatch.Groups[2].Value);
int.TryParse(firstMatch.Groups[2].Value, out lineNumber);

Multi-line messages make last entry on screen not display properly

The message display renders correctly if there only are single-line messages in it.

If there is at least one multi-line message, however, the display will not always render the bottom-most element. Example screenshot attached. Notice the dark-grey region at the bottom of the messages pane; that region should display the first line of a partially-visible log message. The bottom-most message begins displaying when the invisible section is less than 1 line of text in height.

image

UberDebug.Log() uses Warning severity instead of Message

This is easy to fix but I'm questioning whether it has been done deliberately. The UberDebug.LogChannel() methods use the Message severity level as I expect but non-channel ones use Warning. This seems odd since I have LogWarning() methods to use if I want that severity.

Code change appears to be just changing from Warning to Message in the first two methods in UberDebug.cs, can pull request if required

Message element height is controlled by largest message

Currently, the editor computes the size of all message elements, and applies the size of the largest to all elements in the message view. This makes the maths for scrolling and selection easy, but it is disturbing from a presentation aspect.

One way to work around this without incurring a large performance hit would be to calculate the starting Y-offset and height of each individual element and store this in two arrays when updating the layout. Operations which used to translate between pixels and element IDs would then do weighted binary searches in these arrays to find the exact locations of elements, and use the information from the table when rendering the elements.

Would this be acceptable from a performance standpoint? Is there something particular that would need to be done to avoid lots of memory allocations/frees, like, always doubling the sizes of the arrays and never shrinking them?

Editor Console window has poor performance with 1000+ lines in window

When there are 1000+ lines visible in the window, and a new Debug.Log occurs, the Editor will hitch noticeably.

Scrolling up/down does not make it hitch. Debug.Log when most messages are filtered out (by enabling the message filter in the top-right corner of the window) does not make it hitch.

Unity 2017.x remote-machine streamed logs display poorly in UberLogger

Starting with Unity 2017, when you run a standalone Windows executable on a machine where the Unity editor is active, the standalone executable will connect to the editor and stream log messages to the Console feed.

The look like this in the regular console:
image

However, they are not formatted properly in the UberLogger console:

image

... UberLogger interprets the entire payload as a single message. The severity level is ignored too.

This needs both some investigation (how to handle the messages properly) and also some decisions, like, does UberLogger (or plugins) need to know whether a message is coming from a remote machine? Does UberLogger (or plugins) need the remote machine name as a separate element of LogInfo?

Keyboard navigation in message & callstack views in the Editor window

It is possible to click in the Editor's Uber Console window and mark individual messages, but there is no keyboard navigation (up-arrow/down-arrow, page up/down, home/end). I miss this a lot.

If we were to combine this with the filter window then I think the following design could work. What do you think? Suggestions welcome!

There are three views which are keyboard controllable -- the search filter input field, the list of messages, and the list of stackframes. The user should be able to switch focus (and keyboard input) between the three.

Visual representation of selection
For the filter view, there are just two styles -- active (this is when you can edit the filter string) and inactive.

For the message and stack frame views, elements can have one out of three visual presentations: not selected (today's grey), selected-but-inactive (a new, different grey), and selected-and-active (today's blue). Clicking on an entry in the message or stack frame view will move focus to that view and select the entry that was clicked on. Clicking on an entry in the other view will make the selected entry in the first view display as selected-but-inactive mode.

Keyboard navigation will change which entry in the view is currently selected; the view will scroll as needed to ensure that the entire entry is visible (or if the entry is higher than the view, the top portion of the entry should be visible).

Keyboard bindings
It should ideally be possible to navigate between the three views using the keyboard (tab + shift-tab?).

Pressing Return on a message could be used to open source file externally.

Single-clicking on an entry in the callstack view has no effect; there is double-clicking to open file externally and right-clicking to show/hide nearby code. These operations could map to space (for hiding/showing nearby code) and Return (for opening file externally).

Editor Console Window works poorly with many filters

The console window is currently fitting all filter buttons into a fixed-size region. This works poorly when using 10+ filters; the text on individual filter buttons gets cropped.
image

Suggestions to solve this:

  1. Compute a minimum width per filter. This should be based on the length of the text within. Change the fitting algorithm to never size a button smaller than its computed minimum width. (Enlarging is OK.)
  2. Handle overflow... Two common solutions:
    a. Allow scrolling the set of buttons. Have scroll left/right buttons at the edges of the region. Jump either one button or a fixed number of pixels at each click on the scroll buttons.
    b. Expand region to multiple rows as necessary to fit all buttons onto the screen at once.

Also, perhaps sort the buttons in alphabetical order? Makes it easier to find the one you're looking for.

In-game window does not work properly when there are too many filters

With more than a half-dozen filters, the in-game window will flicker between rendering at two different widths: The normal console width (which is about half a screen at 1920x1080), and a greater width which is determined by the total number of buttons. This is ugly.

With lots of filters, the scrollbar is no longer usable.

Clicking on a log doesn't jump to the code line but to ForwardToUnity() - Unity 2019.2.1

We recently upgraded from Unity 2018 to 2019.2.1. Before, when I clicked on a log, it used to go to the line in the code. Now it goes to else if(severity==LogSeverity.Error) UnityEngine.Debug.LogError(showObject); instead

`[LogUnityOnly()]
static void ForwardToUnity(UnityEngine.Object source, LogSeverity severity, object message, params object[] par)
{
object showObject = null;
if(message!=null)
{
var messageAsString = message as string;
if(messageAsString!=null)
{
if(par.Length>0)
{
showObject = String.Format(messageAsString, par);
}
else
{
showObject = message;
}
}
else
{
showObject = message;
}
}

        if(source==null)
        {
			if(severity==LogSeverity.Message) UnityEngine.Debug.Log(showObject);
            else if(severity==LogSeverity.Warning) UnityEngine.Debug.LogWarning(showObject);
            else if(severity==LogSeverity.Error) UnityEngine.Debug.LogError(showObject);
        }
        else
        {
            if(severity==LogSeverity.Message) UnityEngine.Debug.Log(showObject, source);
            else if(severity==LogSeverity.Warning) UnityEngine.Debug.LogWarning(showObject, source);
            else if(severity==LogSeverity.Error) UnityEngine.Debug.LogError(showObject, source);
        }
    }`

We are using a simple "middleman" class called CustomDebug:

`public static class CustomDebug
{

private const bool USE_UBER_LOGGER = true;

[UberLogger.StackTraceIgnore]
public static void LogWarning(string message, DebugType debugType = DebugType.Temp, UnityEngine.Object obj = null)
{
    string log = "";

    if (Application.isEditor)
        log = $"{message} [{obj?.name}] [{debugType}]";
    else
        log = $"{message} [{obj?.name}] [{debugType}] [{UnityEngine.SceneManagement.SceneManager.GetActiveScene().path}] [Frame {UnityEngine.Time.frameCount}] [{System.DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss")}]";

    if (USE_UBER_LOGGER)
        UberDebug.LogWarningChannel(obj, debugType.ToString(), log);
    else
        Debug.LogWarning(log, obj);

}

}`

TypeLoadException

Any idea why UberLogger might be causing a TypeLoadException? My project just recently starting crashing the editor constantly leaving errors in the log similar to:

TypeLoadException: Could not load type 'UnityEngine.Networking.NetworkLobbyManager' from assembly 'UnityEngine.Networking, Version=1.0.0.0, Culture=neutral, PublicKeyToken=
null'.

Although the class it mentions that it could not load varies and is not always the same. Once I remove UberLogger from the project it runs fine =/

I am using Unity 5.5.3p2 on macOS.

Multi-column layout for messages in message pane

Currently there are two columns in the message pane: The message type indicator column, and then the text column.

The text column contains either just the message, or it contains timestamp + message.

Formatting becomes weird when timestamps are visible, and a multiline message is printed (see screenshot).

I think it would be preferable to divide the message pane into columns like this:

  • message type
  • timestamp (can be disabled/enabled via buttons on the UberLogger toolbar)
  • channel (can be disabled/enabled via buttons on the UberLogger toolbar)
  • message text

This would either require a heading row for the message pane, so that the user can adjust the relative width of each column -- or the message pane would need to analyze strings as they get added, find the maximum width for each column widths, and automatically adjust the display of all message entries accordingly.

Copy messages and stacktrace into clipboard

As far as I could tell there is no support for copying/pasting from the message & stacktrace windows into the clipboard. This would also be highly useful.

Suggested designs below. UI feedback appreciated!

Always copy everything
At its simplest, pressing Ctrl-C when either the messages window or stacktrace window is active, the entire contents of the window would be copied to the clipboard (with current filter applied).

Copy 1 line or everything
A more advanced implementation would allow for different selection modes: either one entry (the currently-selected) or all. Pressing Ctrl-A would mark everything in the window, and copying when all is selected would copy the entire window contents. Performing any kind of navigation in the window when all is selected, results in just a single line being selected again.

Copy 1 line, one or more ranges, or everything
This could be taken yet further by supporting shift-click and ctrl-click to mark/unmark which entries are part of the selection. Shift-clicking is the more useful of the two; it allows for copy/pasting a range from the window.

Hangs on long log lines.

When logging a long line, UberLogger appears to hang. On my machine, logging new string('a', 100000) takes a bit over 3 minutes. This is due to ExtractInfoFromUnityMessage parsing the filepath(lineno) with the UnityMessageRegex that backtracks like crazy.

See the PR.

Own namespace for UberLogger

Please put all UberLogger classes in their own namespace.
Otherwise you will get problems with bigger unity projects.

"Register" info message from UberLogger

Sometimes this log entry appears (just in the unity console):

Register
UnityEngine.Debug:Log(Object)
UberDebug:UnityLog(Object) (at Assets/UberLogger/UberDebug.cs:85)
UberLogger.Logger:.cctor() (at Assets/UberLogger/UberLogger.cs:204)
UberLoggerEditorWindow:OnEnable() (at Assets/UberLogger/Editor/UberLoggerEditorWindow.cs:81)
UberLoggerEditorWindow:OnEnable() (at Assets/UberLogger/Editor/UberLoggerEditorWindow.cs:60)

Can this be removed?

Debug static class conflicts with other uses

Thanks for UberLogger!

I had one issue which is that making it a drop-in replacement with the global static class Debug conflicts with several use cases for me, including dropping in the standard Unity Test Tools.

There are 2 issues I've seen and the test tools trigger both of them:

  1. Anything which tries to access the property Debug.isDebugBuild fails and I don't believe it's possible to fix that by proxying since C# doesn't allow properties on static classes, or global variables which you'd need to proxy it with an instance.
  2. using Debug = UnityEngine.Debug; because you're also importing System.Diagnostics conflicts with the global namespace Debug

I've fixed this in my projects by just renaming the Debug class UberDebug because I don't really mind that it's not a drop-in replacement and that I need to use it specifically (it's still a nice shortcut over UberLogger.Logger.Log). I don't know if you want a PR for this though since one of the highlighted features is that it's a drop-in replacement - although sometimes it isn't if your code has either of the 2 issues above ๐Ÿ˜‰ Maybe you can think of a better way to mitigate this, or maybe this could just be in the docs as a gotcha.

Thanks again!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.