Update Cryville.Common.Logging.
This commit is contained in:
@@ -43,7 +43,9 @@ namespace Cryville.Crtr {
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore,
|
||||
};
|
||||
|
||||
public static BufferedLogger MainLogger { get; private set; }
|
||||
public static Logger MainLogger { get; private set; }
|
||||
static FileStream _logFileStream;
|
||||
static StreamLoggerListener _logWriter;
|
||||
|
||||
static bool _init;
|
||||
public static void Init() {
|
||||
@@ -53,25 +55,41 @@ namespace Cryville.Crtr {
|
||||
bool _bcflag = new Version(Settings.Default.LastRunVersion) < new Version("0.4");
|
||||
if (_bcflag) Settings.Default.Reset();
|
||||
|
||||
Logger.SetLogPath(Settings.Default.GameDataPath + "/logs");
|
||||
MainLogger = new BufferedLogger();
|
||||
Application.logMessageReceivedThreaded += OnLog;
|
||||
Logger.Create("main", MainLogger);
|
||||
|
||||
Logger.Log("main", 1, "Game", "Game Version: {0}", Application.version);
|
||||
Logger.Log("main", 1, "Game", "Unity Version: {0}", Application.unityVersion);
|
||||
Logger.Log("main", 1, "Game", "Operating System: {0}, Unity = {1}, Family = {2}", Environment.OSVersion, SystemInfo.operatingSystem, SystemInfo.operatingSystemFamily);
|
||||
Logger.Log("main", 1, "Game", "Platform: Build = {0}, Unity = {1}", PlatformConfig.Name, Application.platform);
|
||||
Logger.Log("main", 1, "Game", "Culture: {0}, UI = {1}, System = {2}, Unity = {3}", CultureInfo.CurrentCulture, CultureInfo.CurrentUICulture, CultureInfo.InstalledUICulture, Application.systemLanguage);
|
||||
Logger.Log("main", 1, "Game", "Device: Model = {0}, Name = {1}, Type = {2}", SystemInfo.deviceModel, SystemInfo.deviceName, SystemInfo.deviceType);
|
||||
Logger.Log("main", 1, "Game", "Graphics: Name = {0}, Type = {1}, Vendor = {2}, Version = {3}", SystemInfo.graphicsDeviceName, SystemInfo.graphicsDeviceType, SystemInfo.graphicsDeviceVendor, SystemInfo.graphicsDeviceVersion);
|
||||
Logger.Log("main", 1, "Game", "Processor: Count = {0}, Frequency = {1}MHz, Type = {2}", SystemInfo.processorCount, SystemInfo.processorFrequency, SystemInfo.processorType);
|
||||
|
||||
if (_bcflag) Logger.Log("main", 2, "Game", "Reset all settings");
|
||||
|
||||
GameDataPath = Settings.Default.GameDataPath;
|
||||
UnityDataPath = Application.dataPath;
|
||||
|
||||
var logPath = Directory.CreateDirectory(Path.Combine(GameDataPath, "logs"));
|
||||
_logFileStream = new FileStream(
|
||||
Path.Combine(
|
||||
logPath.FullName,
|
||||
string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"{0}.log",
|
||||
(int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds
|
||||
)
|
||||
),
|
||||
FileMode.Create, FileAccess.Write, FileShare.Read
|
||||
);
|
||||
_logWriter = new StreamLoggerListener(_logFileStream) { AutoFlush = true };
|
||||
MainLogger = new Logger();
|
||||
var listener = new InstantLoggerListener();
|
||||
listener.Log += MainLogger.Log;
|
||||
Common.Shared.Logger.AddListener(listener);
|
||||
Input.Shared.Logger.AddListener(listener);
|
||||
MainLogger.AddListener(_logWriter);
|
||||
Application.logMessageReceivedThreaded += OnInternalLog;
|
||||
|
||||
MainLogger.Log(1, "Game", "Game Version: {0}", Application.version);
|
||||
MainLogger.Log(1, "Game", "Unity Version: {0}", Application.unityVersion);
|
||||
MainLogger.Log(1, "Game", "Operating System: {0}, Unity = {1}, Family = {2}", Environment.OSVersion, SystemInfo.operatingSystem, SystemInfo.operatingSystemFamily);
|
||||
MainLogger.Log(1, "Game", "Platform: Build = {0}, Unity = {1}", PlatformConfig.Name, Application.platform);
|
||||
MainLogger.Log(1, "Game", "Culture: {0}, UI = {1}, System = {2}, Unity = {3}", CultureInfo.CurrentCulture, CultureInfo.CurrentUICulture, CultureInfo.InstalledUICulture, Application.systemLanguage);
|
||||
MainLogger.Log(1, "Game", "Device: Model = {0}, Name = {1}, Type = {2}", SystemInfo.deviceModel, SystemInfo.deviceName, SystemInfo.deviceType);
|
||||
MainLogger.Log(1, "Game", "Graphics: Name = {0}, Type = {1}, Vendor = {2}, Version = {3}", SystemInfo.graphicsDeviceName, SystemInfo.graphicsDeviceType, SystemInfo.graphicsDeviceVendor, SystemInfo.graphicsDeviceVersion);
|
||||
MainLogger.Log(1, "Game", "Processor: Count = {0}, Frequency = {1}MHz, Type = {2}", SystemInfo.processorCount, SystemInfo.processorFrequency, SystemInfo.processorType);
|
||||
|
||||
if (_bcflag) MainLogger.Log(2, "Game", "Reset all settings");
|
||||
|
||||
#if UNITY_ANDROID && !UNITY_EDITOR
|
||||
JavaVMManager.Register(JniInvoke.Instance);
|
||||
#endif
|
||||
@@ -120,14 +138,14 @@ namespace Cryville.Crtr {
|
||||
AudioManager = EngineBuilder.Create();
|
||||
if (AudioManager == null) {
|
||||
Dialog.Show(null, "Fatal error: Cannot initialize audio engine");
|
||||
Logger.Log("main", 5, "Audio", "Cannot initialize audio engine");
|
||||
MainLogger.Log(5, "Audio", "Cannot initialize audio engine");
|
||||
}
|
||||
else {
|
||||
Logger.Log("main", 1, "Audio", "Using audio API: {0}", AudioManager.GetType().Namespace);
|
||||
MainLogger.Log(1, "Audio", "Using audio API: {0}", AudioManager.GetType().Namespace);
|
||||
AudioDevice = AudioManager.GetDefaultDevice(DataFlow.Out);
|
||||
AudioClient = AudioDevice.Connect(AudioDevice.DefaultFormat, AudioDevice.MinimumBufferSize + AudioDevice.BurstSize);
|
||||
Logger.Log(
|
||||
"main", 1, "Audio",
|
||||
MainLogger.Log(
|
||||
1, "Audio",
|
||||
"Audio Output = {{ Name = \"{0}\", BurstSize = {1}, Format = {2}, BufferSize = {3} }}",
|
||||
AudioDevice.Name, AudioDevice.BurstSize, AudioClient.Format, AudioClient.BufferSize
|
||||
);
|
||||
@@ -140,8 +158,8 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Dialog.Show(null, "An error occurred while trying to initialize the recommended audio engine\nTrying to use fallback audio engines");
|
||||
Logger.Log("main", 4, "Audio", "An error occurred when initializing the audio engine: {0}", ex);
|
||||
Logger.Log("main", 2, "Audio", "Trying to use fallback audio engines");
|
||||
MainLogger.Log(4, "Audio", "An error occurred when initializing the audio engine: {0}", ex);
|
||||
MainLogger.Log(2, "Audio", "Trying to use fallback audio engines");
|
||||
EngineBuilder.Engines.Remove(AudioManager.GetType());
|
||||
}
|
||||
}
|
||||
@@ -159,7 +177,7 @@ namespace Cryville.Crtr {
|
||||
Settings.Default.LastRunVersion = Application.version;
|
||||
Settings.Default.Save();
|
||||
|
||||
Logger.Log("main", 1, "UI", "Initializing font manager");
|
||||
MainLogger.Log(1, "UI", "Initializing font manager");
|
||||
foreach (var res in Resources.LoadAll<TextAsset>("cldr/common/validity")) {
|
||||
IdValidity.Load(LoadXmlDocument(res));
|
||||
}
|
||||
@@ -171,7 +189,7 @@ namespace Cryville.Crtr {
|
||||
};
|
||||
TMPAutoFont.DefaultShader = Resources.Load<Shader>(PlatformConfig.TextShader);
|
||||
|
||||
Logger.Log("main", 1, "Game", "Initialized");
|
||||
MainLogger.Log(1, "Game", "Initialized");
|
||||
}
|
||||
|
||||
static readonly Encoding _encoding = new UTF8Encoding(false, true);
|
||||
@@ -194,7 +212,7 @@ namespace Cryville.Crtr {
|
||||
if (_shutdown) return;
|
||||
_shutdown = true;
|
||||
|
||||
Logger.Log("main", 1, "Game", "Shutting down");
|
||||
MainLogger.Log(1, "Game", "Shutting down");
|
||||
try {
|
||||
AudioClient.Dispose();
|
||||
AudioSequencer.Dispose();
|
||||
@@ -205,15 +223,16 @@ namespace Cryville.Crtr {
|
||||
LogException("Game", "An error occurred while shutting down", ex);
|
||||
}
|
||||
finally {
|
||||
Logger.Close();
|
||||
_logWriter.Dispose();
|
||||
_logFileStream.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public static void LogException(string module, string prefix, Exception ex) {
|
||||
Logger.Log("main", 4, module, "{0}: {1}", prefix, ex);
|
||||
MainLogger.Log(4, module, "{0}: {1}", prefix, ex);
|
||||
}
|
||||
|
||||
static void OnLog(string condition, string stackTrace, LogType type) {
|
||||
static void OnInternalLog(string condition, string stackTrace, LogType type) {
|
||||
int l;
|
||||
switch (type) {
|
||||
case LogType.Log: l = 1; break;
|
||||
@@ -223,7 +242,7 @@ namespace Cryville.Crtr {
|
||||
case LogType.Exception: l = 4; break;
|
||||
default: l = 1; break;
|
||||
}
|
||||
Logger.Log("main", l, "Internal", "{0}\n{1}", condition, stackTrace);
|
||||
MainLogger.Log(l, "Internal", "{0}\n{1}", condition, stackTrace);
|
||||
}
|
||||
|
||||
public static void SuspendBackgroundTasks() {
|
||||
|
Reference in New Issue
Block a user