File MIES_Logging.ipf

Functions

string LOG_GetFile(string package)

Get the absolute path to the log file.

static variable LOG_HasRequiredKeys(variable JSONid)

Check that the given JSON document has the required top level keys.

Currently we require:

  • source: Source of the log entry, usually the function issuing the add entry

  • exp: Name of the Igor Pro experiment

  • id: Igor Pro instance identifier, see also GetIgorInstanceID()

variable LOG_GenerateEntryTemplate(string source)

Generate a JSON text with all required entries.

Caller is responsible for the JSON text memory.

variable LOG_MarkSessionStart(string package)

Adds a special entry to the logfile to mark the start of a session.

Should be called from IgorBeforeNewHook().

static variable LOG_AddEntryWithoutChecks(string package, variable JSONid)

Adds the JSONid text to the logfile without any checks.

variable LOG_AddEntry(string package, string action, variable stacktrace = defaultValue, WaveTextOrNull keys = defaultValue, WaveTextOrNull values = defaultValue)

Add entry for the current function into the log file.

Before LOG_AddEntry can be used the symbolic path must have been initialized via PS_Initialize or PS_FixPackageLocation. This is best done from the AfterCompiledHook().

Usage:

Function DoWork()

    LOG_AddEntry("my package", "start")

    // ...

    LOG_AddEntry("my package", "end")
End

Result:

{"action":"start","exp":"HardwareTests","source":"DoWork","ts":"2021-03-09T17:20:10.252+01:00"}
{"action":"end","exp":"HardwareTests","source":"DoWork","ts":"2021-03-09T17:20:10.298+01:00"}

Parameters:
  • package – package name, this determines the log file

  • action – additional string, can be something like start or end

  • stacktrace – [optional, defaults to false] add the stacktrace to the log

  • keys – [optional, defaults to $””] Additional key-value pairs to be written into the log file. Same size as values. Either both keys and values are present or none.

  • values – [optional, defaults to $””] Additional key-value pairs to be written into the log file. Same size as keys. Either both keys and values are present or none.

static variable LOG_AddStackTrace(variable JSONid)