Scripting DebugLogging

Revision as of 20:25, 6 November 2016 by imported>Qazaaq (Created page with "Category:Scripting_Guides <source lang="papyrus"> Scriptname Papyrus:Log Hidden DebugOnly {Creates custom user logs for the purpose of debugging} Struct UserLog string...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Scriptname Papyrus:Log Hidden DebugOnly
{Creates custom user logs for the purpose of debugging}

Struct UserLog
	string Caller
	string FileName
EndStruct


; User Log
;---------------------------------------------

bool Function WriteLine(UserLog Log, var Text) Global
	If (Log == none)
		Log = new UserLog
		Log.Caller = ""
		Log.FileName = "User"
	ElseIf (StringIsNoneOrEmpty(Log.FileName))
		Log.FileName = "User"
	EndIf
	Text = Log.Caller + " " + Text
	If(Debug.TraceUser(Log.FileName, Text))
		return true
	Else
		Debug.OpenUserLog(Log.FileName)
		return Debug.TraceUser(Log.FileName, Text)
	EndIf
EndFunction


Function WriteChangedValue(UserLog Log, string propertyName, var fromValue, var toValue) Global
	WriteLine(Log, "Changing "+propertyName+" from " + fromValue + " to " + toValue)
EndFunction


Function WriteNotification(UserLog Log, var Text) Global
	If (WriteLine(Log, Text))
		Debug.Notification(Text)
	EndIf
EndFunction


Function WriteMessage(UserLog Log, var Text) Global
	If (WriteLine(Log, Text))
		Debug.MessageBox(Text)
	EndIf
EndFunction


Function WriteError(UserLog Log, var Text) Global
	If (WriteLine(Log, Text))
		Debug.MessageBox("Error\n"+Text)
	EndIf
EndFunction


; Text
;---------------------------------------------

bool Function StringIsNoneOrEmpty(string value) Global
	return !(value) || value == ""
EndFunction