Skip to content

Commit bdcdf31

Browse files
committed
address #53
1 parent fde77ca commit bdcdf31

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

Assets/UXF/Scripts/SessionLogger.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,19 @@ namespace UXF
1313
/// </summary>
1414
public class SessionLogger : MonoBehaviour
1515
{
16+
public static SessionLogger instance { get; private set; }
17+
18+
public bool setAsMainInstance = true;
19+
public bool logDebugLogCalls = true;
20+
1621
private Session session;
1722
private string[] header = new string[]{ "timestamp", "log_type", "message"};
1823
private UXFDataTable table;
1924

2025
void Awake()
2126
{
27+
if (setAsMainInstance) instance = this;
28+
2229
AttachReferences(
2330
newSession: GetComponent<Session>()
2431
);
@@ -40,7 +47,7 @@ public void AttachReferences(Session newSession = null)
4047
public void Initialise()
4148
{
4249
table = new UXFDataTable("timestamp", "log_type", "message");
43-
Application.logMessageReceived += HandleLog;
50+
if (logDebugLogCalls) Application.logMessageReceived += HandleLog;
4451
session.preSessionEnd.AddListener(Finalise); // finalise logger when cleaning up the session
4552
}
4653

@@ -58,15 +65,15 @@ void HandleLog(string logString, string stackTrace, LogType type)
5865
/// <summary>
5966
/// Manually log a message to the log file.
6067
/// </summary>
61-
/// <param name="logType">The type of the log. This can be any string you choose.</param>
62-
/// <param name="message">The content you wish to log, expressed as a string.</param>
63-
public void WriteLog(string logType, string value)
68+
/// <param name="text">The content you wish to log, expressed as a string.</param>
69+
/// <param name="logType">The type of the log. This can be any string you choose. Default is \"user\"</param>
70+
public void Log(string text, string logType = "user")
6471
{
6572
var row = new UXFDataRow();
6673

6774
row.Add(("timestamp", Time.time.ToString()));
6875
row.Add(("log_type", logType));
69-
row.Add(("message", value.Replace(",", string.Empty)));
76+
row.Add(("message", text.Replace(",", string.Empty)));
7077

7178
table.AddCompleteRow(row);
7279
}
@@ -78,7 +85,7 @@ public void Finalise(Session session)
7885
{
7986
session.SaveDataTable(table, "log", dataType: UXFDataType.SessionLog);
8087

81-
Application.logMessageReceived -= HandleLog;
88+
if (logDebugLogCalls) Application.logMessageReceived -= HandleLog;
8289
session.preSessionEnd.RemoveListener(Finalise);
8390
}
8491

0 commit comments

Comments
 (0)