autoconfig: move log_init code to function

This commit is contained in:
Oliver Smith 2023-04-06 21:04:55 +00:00
parent 314f7a0b04
commit 7bfb0ff32f
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB

View file

@ -12,6 +12,7 @@ Cu.import("resource://gre/modules/FileUtils.jsm");
var g_ff_major_version; var g_ff_major_version;
var g_updated = false; var g_updated = false;
var g_fragments_cache = {}; // cache for css_file_get_fragments() var g_fragments_cache = {}; // cache for css_file_get_fragments()
var g_logFileStream;
// Create <profile>/chrome/ directory if not already present // Create <profile>/chrome/ directory if not already present
var g_chromeDir = Services.dirsvc.get("ProfD", Ci.nsIFile); var g_chromeDir = Services.dirsvc.get("ProfD", Ci.nsIFile);
@ -20,16 +21,18 @@ if (!g_chromeDir.exists()) {
g_chromeDir.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY); g_chromeDir.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
} }
var g_logFile = g_chromeDir.clone();
g_logFile.append("mobile-config-firefox.log");
var g_mode = FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE | FileUtils.MODE_APPEND;
var g_logFileStream = FileUtils.openFileOutputStream(g_logFile, g_mode);
function write_line(ostream, line) { function write_line(ostream, line) {
line = line + "\n" line = line + "\n"
ostream.write(line, line.length); ostream.write(line, line.length);
} }
function log_init() {
var mode = FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE | FileUtils.MODE_APPEND;
var logFile = g_chromeDir.clone();
logFile.append("mobile-config-firefox.log");
g_logFileStream = FileUtils.openFileOutputStream(logFile, mode);
}
function log(line) { function log(line) {
var date = new Date().toISOString().replace("T", " ").slice(0, 19); var date = new Date().toISOString().replace("T", " ").slice(0, 19);
line = "[" + date + "] " + line; line = "[" + date + "] " + line;
@ -285,6 +288,7 @@ function main() {
log("Done"); log("Done");
} }
log_init();
try { try {
main(); main();
} catch(e) { } catch(e) {