@@ -13,12 +13,19 @@ namespace UXF
13
13
/// </summary>
14
14
public class SessionLogger : MonoBehaviour
15
15
{
16
+ public static SessionLogger instance { get ; private set ; }
17
+
18
+ public bool setAsMainInstance = true ;
19
+ public bool logDebugLogCalls = true ;
20
+
16
21
private Session session ;
17
22
private string [ ] header = new string [ ] { "timestamp" , "log_type" , "message" } ;
18
23
private UXFDataTable table ;
19
24
20
25
void Awake ( )
21
26
{
27
+ if ( setAsMainInstance ) instance = this ;
28
+
22
29
AttachReferences (
23
30
newSession : GetComponent < Session > ( )
24
31
) ;
@@ -40,7 +47,7 @@ public void AttachReferences(Session newSession = null)
40
47
public void Initialise ( )
41
48
{
42
49
table = new UXFDataTable ( "timestamp" , "log_type" , "message" ) ;
43
- Application . logMessageReceived += HandleLog ;
50
+ if ( logDebugLogCalls ) Application . logMessageReceived += HandleLog ;
44
51
session . preSessionEnd . AddListener ( Finalise ) ; // finalise logger when cleaning up the session
45
52
}
46
53
@@ -58,15 +65,15 @@ void HandleLog(string logString, string stackTrace, LogType type)
58
65
/// <summary>
59
66
/// Manually log a message to the log file.
60
67
/// </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" )
64
71
{
65
72
var row = new UXFDataRow ( ) ;
66
73
67
74
row . Add ( ( "timestamp" , Time . time . ToString ( ) ) ) ;
68
75
row . Add ( ( "log_type" , logType ) ) ;
69
- row . Add ( ( "message" , value . Replace ( "," , string . Empty ) ) ) ;
76
+ row . Add ( ( "message" , text . Replace ( "," , string . Empty ) ) ) ;
70
77
71
78
table . AddCompleteRow ( row ) ;
72
79
}
@@ -78,7 +85,7 @@ public void Finalise(Session session)
78
85
{
79
86
session . SaveDataTable ( table , "log" , dataType : UXFDataType . SessionLog ) ;
80
87
81
- Application . logMessageReceived -= HandleLog ;
88
+ if ( logDebugLogCalls ) Application . logMessageReceived -= HandleLog ;
82
89
session . preSessionEnd . RemoveListener ( Finalise ) ;
83
90
}
84
91
0 commit comments