forked from bbbscarter/UberLogger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UberLoggerFile.cs
42 lines (39 loc) · 1.36 KB
/
UberLoggerFile.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
using UberLogger;
using System.IO;
using UnityEngine;
/// <summary>
/// A basic file logger backend
/// </summary>
public class UberLoggerFile : UberLogger.ILogger
{
private StreamWriter LogFileWriter;
private bool IncludeCallStacks;
/// <summary>
/// Constructor. Make sure to add it to UberLogger via Logger.AddLogger();
/// filename is relative to Application.persistentDataPath
/// if includeCallStacks is true it will dump out the full callstack for all logs, at the expense of big log files.
/// </summary>
public UberLoggerFile(string filename, bool includeCallStacks = true)
{
IncludeCallStacks = includeCallStacks;
var fileLogPath = System.IO.Path.Combine(Application.persistentDataPath, filename);
Debug.Log("Initialising file logging to " + fileLogPath);
LogFileWriter = new StreamWriter(fileLogPath, false);
LogFileWriter.AutoFlush = true;
}
public void Log(LogInfo logInfo)
{
lock(this)
{
LogFileWriter.WriteLine(logInfo.Message);
if(IncludeCallStacks && logInfo.Callstack.Count>0)
{
foreach(var frame in logInfo.Callstack)
{
LogFileWriter.WriteLine(frame.GetFormattedMethodNameWithFileName());
}
LogFileWriter.WriteLine();
}
}
}
}