CEIP.logEvent Member
Logs a single event to the log file, if CEIP is enabled.
Syntax
object.logEvent(data);
Arguments
Argument | Summary |
---|---|
data | An Object containing properties, including "type", to be logged by CEIP. All property names matching /^[-_a-z0-9]+$/i will be included. The time of the event is logged automatically, overriding any property called "time". |
Returns
Remarks
All code performing actions directly caused by the user should log CEIP events using logEvent.
See Also
Source Code
function ceip_logevent(data)
{
const NORMAL_FILE_TYPE = Components.interfaces.nsIFile.NORMAL_FILE_TYPE;
// Don't log anything we're not meant to. We always log 'logger' events.
if ((data.type != "logger") && !client.prefs["ceip.log." + data.type])
return;
var logFile = this.getLogFile();
if (!logFile.exists()) {
logFile.create(NORMAL_FILE_TYPE, 0600);
this.writeLogLine("<events>");
}
var line = " <event";
data.time = Number(new Date());
for (var prop in data) {
if (prop.match(/[^-_a-z0-9]/i)) {
// Skip anything that's not a valid name for our log.
continue;
}
line += " " + prop + '="';
line += encodeForXMLAttribute(String(data[prop])) + '"';
}
line += "/>";
this.writeLogLine(line);
// We want to return if we're:
// a) currently switching logs.
// b) haven't filled up the current log file.
if (("changeOver" in this) || (logFile.fileSize < client.prefs["ceip.uploadSize"])) {
return;
}
this.changeOver = true;
this.stopLog();
this.writeLogLine("</events>");
try
{
// Move current log to a unique filename before resuming logging.
var oldFile = this.getLogFile();
var newFile = this.getLogFile();
newFile.leafName = Number(new Date()) + ".xml";
newFile.createUnique(NORMAL_FILE_TYPE, 0600);
oldFile.moveTo(null, newFile.leafName);
/* startLog() will reset the nest, but we might be in the middle of a
* command execution right now and would rather not let that happen.
*/
var commandNest = this.commandNest;
this.startLog();
this.commandNest = commandNest;
}
catch (ex)
{
this.logEvent({type: "logger", event: "error", method: "logEvent",
error: formatException(ex)});
this.logEvent({type: "logger", event: "start"});
}
delete this.changeOver;
setTimeout(function(self) { self.uploadLogs() }, 1000, this);
}