1
0
mirror of https://github.com/moparisthebest/FireTray synced 2025-01-08 12:08:05 -05:00

Using __proto__ to set a prototype is now deprecated (FF30).

This commit is contained in:
foudfou 2014-05-30 19:35:27 +02:00
parent e8890c9ac0
commit 738c412c23
2 changed files with 151 additions and 165 deletions

View File

@ -331,13 +331,11 @@ function BasicFormatter(dateFormat) {
if (dateFormat) if (dateFormat)
this.dateFormat = dateFormat; this.dateFormat = dateFormat;
} }
BasicFormatter.prototype = { BasicFormatter.prototype = Object.create(Formatter.prototype);
__proto__: Formatter.prototype, BasicFormatter.prototype.constructor = BasicFormatter;
BasicFormatter.prototype.format = function BF_format(message) {
format: function BF_format(message) {
return message.time + "\t" + message.loggerName + "\t" + message.levelDesc return message.time + "\t" + message.loggerName + "\t" + message.levelDesc
+ "\t" + message.message + "\n"; + "\t" + message.message + "\n";
}
}; };
/* /*
@ -372,12 +370,10 @@ function DumpAppender(formatter) {
this._name = "DumpAppender"; this._name = "DumpAppender";
Appender.call(this, formatter); Appender.call(this, formatter);
} }
DumpAppender.prototype = { DumpAppender.prototype = Object.create(Appender.prototype);
__proto__: Appender.prototype, DumpAppender.prototype.constructor = DumpAppender;
DumpAppender.prototype.doAppend = function DApp_doAppend(message) {
doAppend: function DApp_doAppend(message) {
dump(message); dump(message);
}
}; };
/* /*
@ -389,17 +385,14 @@ function ConsoleAppender(formatter) {
this._name = "ConsoleAppender"; this._name = "ConsoleAppender";
Appender.call(this, formatter); Appender.call(this, formatter);
} }
ConsoleAppender.prototype = { ConsoleAppender.prototype = Object.create(Appender.prototype);
__proto__: Appender.prototype, ConsoleAppender.prototype.doAppend = function CApp_doAppend(message) {
doAppend: function CApp_doAppend(message) {
if (message.level > Log4Moz.Level.Warn) { if (message.level > Log4Moz.Level.Warn) {
Cu.reportError(message); Cu.reportError(message);
return; return;
} }
Cc["@mozilla.org/consoleservice;1"]. Cc["@mozilla.org/consoleservice;1"].
getService(Ci.nsIConsoleService).logStringMessage(message); getService(Ci.nsIConsoleService).logStringMessage(message);
}
}; };
/** /**
@ -414,20 +407,20 @@ function BlockingStreamAppender(formatter) {
this._name = "BlockingStreamAppender"; this._name = "BlockingStreamAppender";
Appender.call(this, formatter); Appender.call(this, formatter);
} }
BlockingStreamAppender.prototype = { BlockingStreamAppender.prototype = Object.create(Appender.prototype);
__proto__: Appender.prototype, BlockingStreamAppender.prototype.constructor = BlockingStreamAppender;
BlockingStreamAppender.prototype._converterStream = null, // holds the nsIConverterOutputStream
BlockingStreamAppender.prototype._outputStream = null, // holds the underlying nsIOutputStream
_converterStream: null, // holds the nsIConverterOutputStream /**
_outputStream: null, // holds the underlying nsIOutputStream
/**
* Output stream to write to. * Output stream to write to.
* *
* This will automatically open the stream if it doesn't exist yet by * This will automatically open the stream if it doesn't exist yet by
* calling newOutputStream. The resulting raw stream is wrapped in a * calling newOutputStream. The resulting raw stream is wrapped in a
* nsIConverterOutputStream to ensure text is written as UTF-8. * nsIConverterOutputStream to ensure text is written as UTF-8.
*/ */
get outputStream() { Object.defineProperty(BlockingStreamAppender, "outputStream", {
get: function outputStream() {
if (!this._outputStream) { if (!this._outputStream) {
// First create a raw stream. We can bail out early if that fails. // First create a raw stream. We can bail out early if that fails.
this._outputStream = this.newOutputStream(); this._outputStream = this.newOutputStream();
@ -446,21 +439,22 @@ BlockingStreamAppender.prototype = {
Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER); Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER);
} }
return this._converterStream; return this._converterStream;
}, }
});
newOutputStream: function newOutputStream() { BlockingStreamAppender.prototype.newOutputStream = function newOutputStream() {
throw "Stream-based appenders need to implement newOutputStream()!"; throw "Stream-based appenders need to implement newOutputStream()!";
}, };
reset: function reset() { BlockingStreamAppender.prototype.reset = function reset() {
if (!this._outputStream) { if (!this._outputStream) {
return; return;
} }
this.outputStream.close(); this.outputStream.close();
this._outputStream = null; this._outputStream = null;
}, };
doAppend: function doAppend(message) { BlockingStreamAppender.prototype.doAppend = function doAppend(message) {
if (!message) { if (!message) {
return; return;
} }
@ -478,7 +472,6 @@ BlockingStreamAppender.prototype = {
} }
} }
} }
}
}; };
/** /**
@ -493,28 +486,27 @@ function StorageStreamAppender(formatter) {
this._name = "StorageStreamAppender"; this._name = "StorageStreamAppender";
BlockingStreamAppender.call(this, formatter); BlockingStreamAppender.call(this, formatter);
} }
StorageStreamAppender.prototype = { StorageStreamAppender.prototype = Object.create(BlockingStreamAppender.prototype);
__proto__: BlockingStreamAppender.prototype, StorageStreamAppender.prototype.constructor = StorageStreamAppender;
_ss: null, StorageStreamAppender.prototype._ss = null,
newOutputStream: function newOutputStream() { StorageStreamAppender.prototype.newOutputStream = function newOutputStream() {
let ss = this._ss = Cc["@mozilla.org/storagestream;1"] let ss = this._ss = Cc["@mozilla.org/storagestream;1"]
.createInstance(Ci.nsIStorageStream); .createInstance(Ci.nsIStorageStream);
ss.init(STREAM_SEGMENT_SIZE, PR_UINT32_MAX, null); ss.init(STREAM_SEGMENT_SIZE, PR_UINT32_MAX, null);
return ss.getOutputStream(0); return ss.getOutputStream(0);
}, };
getInputStream: function getInputStream() { StorageStreamAppender.prototype.getInputStream = function getInputStream() {
if (!this._ss) { if (!this._ss) {
return null; return null;
} }
return this._ss.newInputStream(0); return this._ss.newInputStream(0);
}, };
reset: function reset() { StorageStreamAppender.prototype.reset = function reset() {
BlockingStreamAppender.prototype.reset.call(this); BlockingStreamAppender.prototype.reset.call(this);
this._ss = null; this._ss = null;
}
}; };
/** /**
@ -529,25 +521,24 @@ function FileAppender(file, formatter) {
this._file = file; // nsIFile this._file = file; // nsIFile
BlockingStreamAppender.call(this, formatter); BlockingStreamAppender.call(this, formatter);
} }
FileAppender.prototype = { FileAppender.prototype = Object.create(BlockingStreamAppender.prototype);
__proto__: BlockingStreamAppender.prototype, FileAppender.prototype.constructor = FileAppender;
newOutputStream: function newOutputStream() { FileAppender.prototype.newOutputStream = function newOutputStream() {
try { try {
return FileUtils.openFileOutputStream(this._file); return FileUtils.openFileOutputStream(this._file);
} catch(e) { } catch(e) {
return null; return null;
} }
}, };
reset: function reset() { FileAppender.prototype.reset = function reset() {
BlockingStreamAppender.prototype.reset.call(this); BlockingStreamAppender.prototype.reset.call(this);
try { try {
this._file.remove(false); this._file.remove(false);
} catch (e) { } catch (e) {
// File didn't exist in the first place, or we're on Windows. Meh. // File didn't exist in the first place, or we're on Windows. Meh.
} }
}
}; };
/** /**
@ -567,19 +558,19 @@ function RotatingFileAppender(file, formatter, maxSize, maxBackups) {
this._maxSize = maxSize; this._maxSize = maxSize;
this._maxBackups = maxBackups; this._maxBackups = maxBackups;
} }
RotatingFileAppender.prototype = { RotatingFileAppender.prototype = Object.create(FileAppender.prototype);
__proto__: FileAppender.prototype, RotatingFileAppender.prototype.constructor = RotatingFileAppender;
doAppend: function doAppend(message) { RotatingFileAppender.prototype.doAppend = function doAppend(message) {
FileAppender.prototype.doAppend.call(this, message); FileAppender.prototype.doAppend.call(this, message);
try { try {
this.rotateLogs(); this.rotateLogs();
} catch(e) { } catch(e) {
dump("Error writing file:" + e + "\n"); dump("Error writing file:" + e + "\n");
} }
}, };
rotateLogs: function rotateLogs() { RotatingFileAppender.prototype.rotateLogs = function rotateLogs() {
if (this._file.exists() && this._file.fileSize < this._maxSize) { if (this._file.exists() && this._file.fileSize < this._maxSize) {
return; return;
} }
@ -600,5 +591,4 @@ RotatingFileAppender.prototype = {
} }
// Note: this._file still points to the same file // Note: this._file still points to the same file
}
}; };

View File

@ -85,11 +85,10 @@ firetray.Logging = {
setupLogging: function(loggerName) { setupLogging: function(loggerName) {
// lifted from log4moz.js // lifted from log4moz.js
function SimpleFormatter() {} function SimpleFormatter() {LogMod.Formatter.call(this);}
SimpleFormatter.prototype = { SimpleFormatter.prototype = Object.create(LogMod.Formatter.prototype);
__proto__: LogMod.Formatter.prototype, SimpleFormatter.prototype.constructor = SimpleFormatter;
SimpleFormatter.prototype.format = function(message) {
format: function(message) {
let messageString = ""; let messageString = "";
if (message.hasOwnProperty("message")) if (message.hasOwnProperty("message"))
messageString = message.message; messageString = message.message;
@ -111,20 +110,17 @@ firetray.Logging = {
stringLog += message.stackTrace + "\n"; stringLog += message.stackTrace + "\n";
return stringLog; return stringLog;
}
}; };
function ColorTermFormatter() {} function ColorTermFormatter() {SimpleFormatter.call(this);}
ColorTermFormatter.prototype = { ColorTermFormatter.prototype = Object.create(SimpleFormatter.prototype);
__proto__: SimpleFormatter.prototype, ColorTermFormatter.prototype.constructor = ColorTermFormatter;
ColorTermFormatter.prototype.format = function(message) {
format: function(message) {
let color = colorTermLogColors[message.levelDesc]; let color = colorTermLogColors[message.levelDesc];
let stringLog = SimpleFormatter.prototype.format.call(this, message); let stringLog = SimpleFormatter.prototype.format.call(this, message);
stringLog = color + stringLog + COLOR_RESET; stringLog = color + stringLog + COLOR_RESET;
return stringLog; return stringLog;
}
}; };
// Loggers are hierarchical, affiliation is handled by a '.' in the name. // Loggers are hierarchical, affiliation is handled by a '.' in the name.