Search Feedback

25
votes

Debug Log in Development Build Only.

Profiling & Optimization

-

-

When coding in C++ I often create a debug log macro so that I can place log statements dedicated to debugging in my code which I can leave there. In a non-debug build the macro will just result in no-op so there is no cost. Would it be possible to achieve a similar feature in C# and Unity?

Perhaps something like this in Debug:

partial void DevLog(string message);

#if DEVELOPMENT_BUILD
partial void DevLog(string message)
{
Debug.Log(message);
}
#endif

I believe that should be optimized out by the compiler in a non-development build.

Comments (1)

  1. F7de125aece210bc91228e1d80bff49d?d=mm

    p_025

    Aug 18, 2016 17:53

    If you don't mind having a go-between function like your DevLog up there, you could always use the Conditional attribute.

    using System.Diagnostics;

    [Conditional("DEVELOPMENT_BUILD")]
    public void DevLog(string message)
    {
    UnityEngine.Debug.Log(message);
    }

    More info: https://msdn.microsoft.com/en-us/library/system.diagnostics.conditionalattribute(v=vs.110).aspx

Your opinion counts

Help us make things better. Share your great idea for improving Unity or vote for other people’s.

Log in to post a new idea

Categories

All

(11030)

2D

(290)

Ads

(63)

AI & Navigation

(83)

Analytics

(130)

Animation

(413)

Asset Store

(370)

Asset Store Publisher

(21)

Assets

(557)

Audio

(185)

Cloud Build

(154)

Collaborate

(70)

Docs & Tutorials

(251)

Editor

(2579)

Everyplay

(17)

Game Performance Reporting

(22)

General

(1003)

Graphics

(903)

GUI

(447)

Input

(173)

Licensing

(93)

Networking

(192)

Physics

(392)

Platforms

(448)

Profiling & Optimization

(84)

Runtime

(188)

Scripting

(1154)

Terrain

(177)

WebGL

(145)