This repository has been archived by the owner on Jul 13, 2020. It is now read-only.
forked from Slaynash/VRCModLoader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VRCModLogger.cs
78 lines (68 loc) · 2.83 KB
/
VRCModLogger.cs
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
using System;
using System.IO;
using UnityEngine;
namespace VRCModLoader
{
public class VRCModLogger
{
internal static bool consoleEnabled = false;
private static StreamWriter log;
internal static void Init()
{
FileStream fileStream = null;
DirectoryInfo logDirInfo = null;
FileInfo logFileInfo;
string logFilePath = "";
//string logFilePath = Path.Combine(Environment.CurrentDirectory, "Logs");
if (Application.platform == RuntimePlatform.WindowsPlayer)
logFilePath = Path.Combine(Environment.CurrentDirectory, "Logs");
if (Application.platform == RuntimePlatform.Android)
logFilePath = "/sdcard/VRCTools/Logs";
logFilePath = logFilePath + "/VRCModLoader_" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss-fff") + ".log";
logFileInfo = new FileInfo(logFilePath);
logDirInfo = new DirectoryInfo(logFileInfo.DirectoryName);
if (!logDirInfo.Exists) logDirInfo.Create();
if (!logFileInfo.Exists)
{
fileStream = logFileInfo.Create();
}
else
{
fileStream = new FileStream(logFilePath, FileMode.Open, FileAccess.Write, FileShare.Read);
}
log = new StreamWriter(fileStream);
log.AutoFlush = true;
}
internal static void Stop()
{
log.Close();
}
internal static string GetTimestamp() { return DateTime.Now.ToString("HH:mm:ss.fff"); }
public static void Log(string s)
{
var timestamp = GetTimestamp();
if(consoleEnabled) Console.WriteLine("[" + timestamp + "] [VRCMod] " + s);
if(log != null) log.WriteLine("[" + timestamp + "] " + s);
}
public static void Log(string s, params object[] args)
{
var timestamp = GetTimestamp();
var formatted = string.Format(s, args);
if (consoleEnabled) Console.WriteLine("[" + timestamp + "] [VRCMod] " + s, args);
if (log != null) log.WriteLine("[" + timestamp + "] " + formatted);
}
public static void LogError(string s)
{
var timestamp = GetTimestamp();
if (consoleEnabled) Console.WriteLine("[" + timestamp + "] [VRCMod] [Error] " + s);
if (log != null) log.WriteLine("[" + timestamp + "] [Error] " + s);
}
public static void LogError(string s, params object[] args)
{
var timestamp = GetTimestamp();
var formatted = string.Format(s, args);
if (consoleEnabled) Console.WriteLine("[" + timestamp + "] [VRCMod] [Error] " + formatted);
if (log != null) log.WriteLine("[" + timestamp + "] [Error] " + formatted);
}
}
}