-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathLog.cs
More file actions
172 lines (127 loc) · 7.32 KB
/
Copy pathLog.cs
File metadata and controls
172 lines (127 loc) · 7.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#nullable enable
using System;
namespace Immutable.Audience
{
internal static class Log
{
private const string Prefix = "[ImmutableAudience]";
internal static bool Enabled { get; set; }
// Tests set this to capture output; AudienceUnityHooks sets it to Debug.Log.
internal static Action<string>? Writer { get; set; }
internal static void Debug(string message)
{
if (!Enabled) return;
Emit($"{Prefix} {message}");
}
internal static void Warn(string message) =>
Emit($"{Prefix} WARN: {message}");
private static void Emit(string line)
{
// Swallow anything the Writer or Console throws so Log.Warn and
// Log.Debug never throw themselves. If they did, an exception from
// logging inside a catch block would reach the background timer
// and crash the game on modern .NET.
try
{
if (Writer != null)
{
Writer(line);
return;
}
Console.WriteLine(line);
}
catch
{
}
}
}
internal static class AudienceLogs
{
// ---- Init / config validation ----
internal const string InitCalledTwice =
"Init called more than once. Ignoring; original config retained. " +
"Call Shutdown() first if reconfiguring is intended.";
internal static readonly string TestKeyAgainstProduction =
$"Publishable key has the test prefix ({Constants.TestKeyPrefix}) but BaseUrl points to production. " +
"The backend will reject events with 401. Either remove the BaseUrl override (test keys " +
"default to sandbox) or use a non-test publishable key.";
internal static readonly string NonTestKeyAgainstSandbox =
"Publishable key is not a test key but BaseUrl points to sandbox. " +
"The backend will reject events with 401. Either remove the BaseUrl override (non-test " +
$"keys default to production) or use a test publishable key ({Constants.TestKeyPrefix}).";
// ---- Track ----
internal const string TrackIEventNull =
"Track(IEvent) called with null event. Dropping.";
internal const string TrackStringEmptyName =
"Track(string) called with null or empty event name. Dropping.";
internal static string TrackIEventThrew(string evtTypeName, Exception ex) =>
$"Track(IEvent): {evtTypeName}.ToProperties()/EventName threw {ex.GetType().Name}: {ex.Message}. Dropping.";
internal static string TrackIEventEmptyName(string evtTypeName) =>
$"Track(IEvent): {evtTypeName}.EventName returned null or empty. Dropping.";
// ---- Identify / Alias ----
internal const string IdentifyEmptyUserId =
"Identify called with null or empty userId. Dropping.";
internal const string AliasEmptyIds =
"Alias called with null or empty fromId/toId. Dropping.";
internal static string IdentifyDiscarded(ConsentLevel current) =>
$"Identify discarded. Requires Full consent, current is {current}.";
internal static string AliasDiscarded(ConsentLevel current) =>
$"Alias discarded. Requires Full consent, current is {current}.";
// ---- Consent / Shutdown ----
internal static string ConsentPersistFailed(Exception ex) =>
$"SetConsent: failed to persist consent level. {ex.GetType().Name}: {ex.Message}. " +
"In-memory level is updated but will revert on next launch.";
internal static string ShutdownFlushExceeded(int timeoutMs) =>
$"Shutdown flush exceeded {timeoutMs}ms. Abandoning. " +
"Queued events remain on disk and will retry on next startup.";
internal static string ShutdownFlushThrew(Exception ex) =>
$"Shutdown flush threw: {ex.GetType().Name}: {ex.Message}";
// ---- onError handler swallow ----
internal static string OnErrorThrew(Exception ex) =>
$"onError threw {ex.GetType().Name}: {ex.Message}";
// ---- Send loop ----
internal static string SendBatchUnexpected(Exception ex) =>
$"SendBatch unexpected exception: {ex.GetType().Name}: {ex.Message}";
internal static string ParseRejectedCountThrew(Exception ex) =>
$"ParseRejectedCount threw {ex.GetType().Name}: {ex.Message}";
// ---- Session ----
internal const string SessionPauseAlreadyPaused =
"Session: Pause while already paused. Ignoring.";
internal const string SessionHeartbeatTimeout =
"Session: heartbeat callback did not complete within 1s on timer stop. " +
"A trailing session_heartbeat may race with the next session lifecycle event.";
internal static string SessionTrackCallbackThrew(string eventName, Exception ex) =>
$"Session: {eventName} track callback threw {ex.GetType().Name}. Event dropped.";
// ---- Context providers ----
internal static string ContextProviderThrew(Exception ex) =>
$"ContextProvider threw {ex.GetType().Name}: {ex.Message}. " +
"Event ships with base context only.";
internal static string LaunchContextProviderThrew(Exception ex) =>
$"LaunchContextProvider threw {ex.GetType().Name}: {ex.Message}. " +
"game_launch will ship without auto-detected Unity context.";
internal static string MobileAttributionProviderThrew(Exception ex) =>
$"MobileAttributionProvider threw {ex.GetType().Name}: {ex.Message}. " +
"game_launch will ship without skanRegistered.";
internal static string MobileAttributionContextProviderThrew(Exception ex) =>
$"MobileAttributionContextProvider threw {ex.GetType().Name}: {ex.Message}. " +
"game_launch will ship without iOS attribution context.";
internal static string TrackingAuthorizationRequestThrew(Exception ex) =>
$"RequestTrackingAuthorizationAsync threw {ex.GetType().Name}: {ex.Message}. " +
"Returning NotDetermined.";
internal static string MobileInstallReferrerProviderThrew(Exception ex) =>
$"MobileInstallReferrerProvider threw {ex.GetType().Name}: {ex.Message}. " +
"install_referrer_received will not fire on this launch.";
internal static string InstallReferrerSentMarkerWriteFailed(Exception ex) =>
$"Failed to write install_referrer_sent marker: {ex.GetType().Name}: {ex.Message}. " +
"install_referrer_received may re-fire on the next launch.";
internal static string ATTStatusProviderThrew(Exception ex) =>
$"MobileATTStatusProvider threw {ex.GetType().Name}: {ex.Message}. " +
"tracking_authorization_changed check skipped.";
internal static string ATTIDFAProviderThrew(Exception ex) =>
$"MobileIDFAProvider threw {ex.GetType().Name}: {ex.Message}. " +
"tracking_authorization_changed will ship without idfa.";
internal static string GAIDFetchThrew(Exception ex) =>
$"GAID fetch threw {ex.GetType().Name}: {ex.Message}. " +
"gaid will not ship on game_launch this session; next launch retries.";
}
}