Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This product includes software developed by Amazon Technologies, Inc (http://www
*************************************
THIRD PARTY COMPONENTS

** log4net; version 2.0.15 -- https://logging.apache.org/log4net/
** log4net; version 3.3.0 -- https://logging.apache.org/log4net/

Apache License
Version 2.0, January 2004
Expand Down
2 changes: 2 additions & 0 deletions release-notes/5.5.1-release-notes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Fixes SDK logging on Unity IL2CPP builds.
- Upgrades log4net dependency to 3.3.0.
2 changes: 1 addition & 1 deletion src/GameLiftServerSDK/GameLiftServerSDK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<CodeAnalysisRuleSet>..\..\GameLiftServerSDK.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="log4net" Version="2.0.15" />
<PackageReference Include="log4net" Version="3.3.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="Polly" Version="7.2.3" />
<PackageReference Include="websocketsharp.core" Version="1.0.0" />
Expand Down
2 changes: 1 addition & 1 deletion src/GameLiftServerSDK/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly: AssemblyVersion("5.5.0")]
[assembly: AssemblyVersion("5.5.1")]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
Expand Down
4 changes: 4 additions & 0 deletions src/GameLiftServerSDK/Server/CrashReporterClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ public sealed class CrashReporterClient : IDisposable

private readonly HttpClient httpClient;

#if ENABLE_IL2CPP
private static ILog Log { get; } = new UnityDebugLog();
#else
private static ILog Log { get; } = LogManager.GetLogger(typeof(ServerState));
#endif

public CrashReporterClient(string host, int port)
{
Expand Down
2 changes: 1 addition & 1 deletion src/GameLiftServerSDK/Server/GameLiftServerAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Aws.GameLift.Server
public static class GameLiftServerAPI
#pragma warning restore S101
{
private const string SdkVersion = "5.5.0";
private const string SdkVersion = "5.5.1";

/// <summary>
/// Returns the current version number of the SDK built into the server process.
Expand Down
4 changes: 4 additions & 0 deletions src/GameLiftServerSDK/Server/GameLiftWebSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ public class GameLiftWebSocket : IGameLiftWebSocket
private const string IdempotencyTokenKey = "IdempotencyToken";
private const string SocketClosingErrorMessage = "An error has occurred in closing the connection";

#if ENABLE_IL2CPP
private static readonly ILog Log = new UnityDebugLog();
#else
private static readonly ILog Log = LogManager.GetLogger(typeof(GameLiftWebSocket));
#endif

private readonly int maxConnectRetries;
private readonly int maxWaitForConnectedRetries;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ public class GameLiftWebSocketRequestHandler

private readonly IGameLiftWebSocket gameLiftWebSocket;

#if ENABLE_IL2CPP
public static ILog Log { get; } = new UnityDebugLog();
#else
public static ILog Log { get; } = LogManager.GetLogger(typeof(GameLiftWebSocketRequestHandler));
#endif

// Empty constructor needed for testing.
public GameLiftWebSocketRequestHandler()
Expand Down
4 changes: 4 additions & 0 deletions src/GameLiftServerSDK/Server/Metrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ public class Metrics : IDisposable
/// </summary>
private bool isDisposing;

#if ENABLE_IL2CPP
private static readonly ILog Log = new UnityDebugLog();
#else
private static readonly ILog Log = LogManager.GetLogger(typeof(Metrics));
#endif

/// <summary>
/// Maintains the 'up' gauge to indicate if the server is up (1) or down (0).
Expand Down
4 changes: 4 additions & 0 deletions src/GameLiftServerSDK/Server/MetricsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ public class MetricsBuilder
private const int DefaultStatsdDPortNumber = 8125; // Default StatsD port
private const int DefaultPacketSize = 512; // Default StatsD packet size

#if ENABLE_IL2CPP
private static readonly ILog Log = new UnityDebugLog();
#else
private static readonly ILog Log = LogManager.GetLogger(typeof(MetricsBuilder));
#endif

// Suppress IDE0028: Collection initialization can be simplified
// We need to use explicit type initialization for .NET Framework 4.6.2 compatibility
Expand Down
4 changes: 4 additions & 0 deletions src/GameLiftServerSDK/Server/Model/MatchmakerData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ public enum BackfillMode
/// </summary>
public class MatchmakerData
{
#if ENABLE_IL2CPP
public static ILog Log { get; set; } = new UnityDebugLog();
#else
public static ILog Log { get; set; } = LogManager.GetLogger(typeof(MatchmakerData));
#endif

public string MatchId { get; set; }

Expand Down
4 changes: 4 additions & 0 deletions src/GameLiftServerSDK/Server/Model/Metrics/MetricBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ namespace Aws.GameLift.Server.Model.Metrics
/// </summary>
public class MetricBase : IMetric
{
#if ENABLE_IL2CPP
private static readonly ILog Log = new UnityDebugLog();
#else
private static readonly ILog Log = LogManager.GetLogger(typeof(MetricBase));
#endif

private readonly Dictionary<string, Tag> tags;
private readonly object sampleLock = new object();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ public class DescribePlayerSessionsResult
{
private const int MaxPlayerSessions = 1024;

#if ENABLE_IL2CPP
public static ILog Log { get; } = new UnityDebugLog();
#else
public static ILog Log { get; } = LogManager.GetLogger(typeof(ServerState));
#endif

public string NextToken { get; set; }

Expand Down
4 changes: 4 additions & 0 deletions src/GameLiftServerSDK/Server/ServerState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ public sealed class ServerState : IWebSocketMessageHandler

public static ServerState Instance { get; } = new ServerState();

#if ENABLE_IL2CPP
public static ILog Log { get; } = new UnityDebugLog();
#else
public static ILog Log { get; } = LogManager.GetLogger(typeof(ServerState));
#endif

public ServerState(IGameLiftWebSocket webSocket, GameLiftWebSocketRequestHandler requestHandler, IEnvironmentWrapper envWrapper)
{
Expand Down
4 changes: 4 additions & 0 deletions src/GameLiftServerSDK/Server/StatsDClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ public class StatsDClient : IStatsDClient
private const string GaugeMetricType = "g";
private const string TimingMetricType = "ms";

#if ENABLE_IL2CPP
private static readonly ILog Log = new UnityDebugLog();
#else
private static readonly ILog Log = LogManager.GetLogger(typeof(StatsDClient));
#endif

private readonly IUdpClientWrapper udpClient;
private const string FixedPrefix = "server"; // All metrics share this fixed prefix.
Expand Down
201 changes: 201 additions & 0 deletions src/GameLiftServerSDK/Server/UnityDebugLog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/

#if ENABLE_IL2CPP
namespace Aws.GameLift.Server
{
using System;
using log4net;
using log4net.Core;

/// <summary>
/// ILog substitute for IL2CPP builds, where log4net cannot initialize because
/// System.Configuration.ConfigurationManager is unsupported. Debug/Info are
/// dropped; Warn/Error/Fatal are forwarded to UnityEngine.Debug.
/// </summary>
public sealed class UnityDebugLog : ILog
{
public bool IsDebugEnabled => false;

public bool IsInfoEnabled => false;

public bool IsWarnEnabled => true;

public bool IsErrorEnabled => true;

public bool IsFatalEnabled => true;

public ILogger Logger => null;

public void Debug(object message)
{
}

public void Debug(object message, Exception exception)
{
}

public void DebugFormat(string format, params object[] args)
{
}

public void DebugFormat(string format, object arg0)
{
}

public void DebugFormat(string format, object arg0, object arg1)
{
}

public void DebugFormat(string format, object arg0, object arg1, object arg2)
{
}

public void DebugFormat(IFormatProvider provider, string format, params object[] args)
{
}

public void Info(object message)
{
}

public void Info(object message, Exception exception)
{
}

public void InfoFormat(string format, params object[] args)
{
}

public void InfoFormat(string format, object arg0)
{
}

public void InfoFormat(string format, object arg0, object arg1)
{
}

public void InfoFormat(string format, object arg0, object arg1, object arg2)
{
}

public void InfoFormat(IFormatProvider provider, string format, params object[] args)
{
}

public void Warn(object message)
{
UnityEngine.Debug.LogWarning(message);
}

public void Warn(object message, Exception exception)
{
UnityEngine.Debug.LogWarning($"{message}\n{exception}");
}

public void WarnFormat(string format, params object[] args)
{
UnityEngine.Debug.LogWarningFormat(format, args);
}

public void WarnFormat(string format, object arg0)
{
UnityEngine.Debug.LogWarningFormat(format, arg0);
}

public void WarnFormat(string format, object arg0, object arg1)
{
UnityEngine.Debug.LogWarningFormat(format, arg0, arg1);
}

public void WarnFormat(string format, object arg0, object arg1, object arg2)
{
UnityEngine.Debug.LogWarningFormat(format, arg0, arg1, arg2);
}

public void WarnFormat(IFormatProvider provider, string format, params object[] args)
{
UnityEngine.Debug.LogWarningFormat(format, args);
}

public void Error(object message)
{
UnityEngine.Debug.LogError(message);
}

public void Error(object message, Exception exception)
{
UnityEngine.Debug.LogError($"{message}\n{exception}");
}

public void ErrorFormat(string format, params object[] args)
{
UnityEngine.Debug.LogErrorFormat(format, args);
}

public void ErrorFormat(string format, object arg0)
{
UnityEngine.Debug.LogErrorFormat(format, arg0);
}

public void ErrorFormat(string format, object arg0, object arg1)
{
UnityEngine.Debug.LogErrorFormat(format, arg0, arg1);
}

public void ErrorFormat(string format, object arg0, object arg1, object arg2)
{
UnityEngine.Debug.LogErrorFormat(format, arg0, arg1, arg2);
}

public void ErrorFormat(IFormatProvider provider, string format, params object[] args)
{
UnityEngine.Debug.LogErrorFormat(format, args);
}

public void Fatal(object message)
{
UnityEngine.Debug.LogError(message);
}

public void Fatal(object message, Exception exception)
{
UnityEngine.Debug.LogError($"{message}\n{exception}");
}

public void FatalFormat(string format, params object[] args)
{
UnityEngine.Debug.LogErrorFormat(format, args);
}

public void FatalFormat(string format, object arg0)
{
UnityEngine.Debug.LogErrorFormat(format, arg0);
}

public void FatalFormat(string format, object arg0, object arg1)
{
UnityEngine.Debug.LogErrorFormat(format, arg0, arg1);
}

public void FatalFormat(string format, object arg0, object arg1, object arg2)
{
UnityEngine.Debug.LogErrorFormat(format, arg0, arg1, arg2);
}

public void FatalFormat(IFormatProvider provider, string format, params object[] args)
{
UnityEngine.Debug.LogErrorFormat(format, args);
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void GIVEN_validSdkVersion_WHEN_GetSdkVersion_THEN_returnsVersion()

// Then
Assert.IsTrue(outcome.Success);
Assert.AreEqual("5.5.0", outcome.Result);
Assert.AreEqual("5.5.1", outcome.Result);
}
}
}
2 changes: 1 addition & 1 deletion tests/GameLiftServerSDK.Tests/Server/ServerStateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Aws.GameLift.Tests.Server
[TestFixture]
public class ServerStateTest
{
private const string SdkVersion = "5.5.0";
private const string SdkVersion = "5.5.1";
private const string SdkToolName = "testSdkToolName";
private const string SdkToolVersion = "1.0.0";
private const string EnvironmentVariableWebsocketUrl = "GAMELIFT_SDK_WEBSOCKET_URL";
Expand Down
5 changes: 5 additions & 0 deletions tests/GameLiftServerSDK.Tests/log4net.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@
<level value="WARN" />
<appender-ref ref="ConsoleAppender" />
</root>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %level %logger - %message%newline" />
</layout>
</appender>
</log4net>
</configuration>