Skip to content

Commit 095adfd

Browse files
committed
adding note for logging
1 parent e14700d commit 095adfd

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

Packages/com.unity.multiplayer.samples.coop/Utilities/Net/DedicatedServer/DedicatedServerUtilities.cs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,34 @@ public static bool IsServerBuildTarget
2222
}
2323
}
2424

25-
// todo improve perf on this, don't do string concatenation everywhere, especially if log level is too high
26-
// TODO use json structure for log analysis tools (kibana, elasticsearch, etc)
27-
// todo find a way to disable full stack trace if needed, this could take a lot of resources.
28-
// Logging format should change following which logging analytics service you use. Elasticsearch could
29-
// require a different format than splunk for example.
25+
/// <summary>
26+
/// With dedicated server, you don't have a view into your game like you'd have with other types of platforms. You'll rely on logging a lot to get
27+
/// insights into what's happening on your server.
28+
/// Unity's default logging isn't usable for dedicated server use cases. The following requirements are missing:
29+
/// - Structured logging: with 1000+ server fleets, you don't want to look at log files individually. You'll need log ingestion/analysis tools to be able
30+
/// to parse all that data (think tools like elasticsearch for example). Making your logs structured so they are machine friendly (for example
31+
/// having each log entry be a json object) makes this easier to integrate with those tools
32+
/// - Log levels: most of the time, you won't want to receive info logs, only warnings and errors (so you don't spam your analysis tools and so they don't
33+
/// cost your a fortune). However, you'll also want to enable info and debug logs for specific servers when debugging them. Having a logger that
34+
/// manages this for you is better than wrapping your logs yourself and managing this yourself.
35+
/// - Log file rotation: Dedicated servers can run for days and days, while normal games will run for a few play sessions before being closed. This means your
36+
/// log file will grow and grow. Rotation is an automated way to swap log files each x hours/days. This allows deleting older log files and allows for more manageable
37+
/// log files in general.
38+
/// - Performance: logging can be a performance costly operation, which contributes to your CPU perf costs, which in turn are translated to hosting monetary costs.
39+
/// Having a logging library that's optimized for these scenarios is essential (burstable, threaded, etc).
40+
/// This also includes not having to print full stack traces (not needed for most devops operations, but could be enabled for debugging)
41+
///
42+
/// A few solutions exists for this. ZLogger https://github.com/Cysharp/ZLogger and serilog https://www.nuget.org/packages/serilog/ for example
43+
/// Unity also has an experimental package com.unity.logging that answers the above needs as well. Once this is out of experimental, this will be
44+
/// integrated in boss room.
45+
/// </summary>
46+
/// <param name="message"></param>
3047
public static void Log(string message)
3148
{
32-
Debug.LogFormat($"<b>===[{DateTime.UtcNow}]|{Time.realtimeSinceStartup}|{Time.time}|pid[{Process.GetCurrentProcess().Id}]</b> - {message}");
49+
// IMPORTANT FOR LOGGING READ ABOVE. The following isn't recommended for production use with dedicated game servers.
50+
Debug.Log($"[{DateTime.UtcNow}] {Time.realtimeSinceStartup} {Time.time} pid[{Process.GetCurrentProcess().Id}] - {message}");
3351
}
3452

35-
// [MenuItem("Debug/GetAll")]
3653
public static void PrintSceneHierarchy()
3754
{
3855
List<GameObject> rootObjects = new List<GameObject>();
@@ -71,4 +88,4 @@ private static string GetInfoForObject(GameObject obj)
7188
return $"{obj.name}\tnb null {nullCount}/{allComponents.Count}";
7289
}
7390
}
74-
}
91+
}

0 commit comments

Comments
 (0)