[MediaWiki-commits] [Gerrit] Use new log and status reporting framework - change (mediawiki...latex_renderer)

2014-09-09 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Use new log and status reporting framework
..


Use new log and status reporting framework

Log through the service! Remove dependency on syslog. I also want
all errors exposed through the service so I always have to throw
and then have the main application promise catch it.

Relies on: https://gerrit.wikimedia.org/r/#/c/151224

Change-Id: I00b1479404441063132c57f3ffe1c37f80658938
---
M bin/mw-ocg-latexer
M lib/index.js
M lib/status.js
M package.json
M test/samples.js
5 files changed, 46 insertions(+), 43 deletions(-)

Approvals:
  Cscott: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/bin/mw-ocg-latexer b/bin/mw-ocg-latexer
index 4e4c1f6..ac65465 100755
--- a/bin/mw-ocg-latexer
+++ b/bin/mw-ocg-latexer
@@ -31,9 +31,7 @@
.option('-D, --debug',
'Turn on debugging features (eg, full stack traces on 
exceptions)')
.option('-T, --temporary-directory dir',
-   'Use dir for temporaries, not $TMPDIR or /tmp', null)
-   .option('--syslog',
-   'Log errors using syslog (for production deployments)');
+   'Use dir for temporaries, not $TMPDIR or /tmp', null);
 
 program.parse(process.argv);
 
@@ -48,24 +46,31 @@
 
 var bundlefile = program.args[0];
 
-var Syslog = program.syslog ? require('node-syslog') : {
-   init: function() { },
-   log: function() { },
-   close: function() { }
-};
-Syslog.init(latexer.name, Syslog.LOG_PID|Syslog.LOG_ODELAY, Syslog.LOG_LOCAL0);
-
 var log = function() {
-   // en/disable log messages here
-   if (program.verbose || program.debug) {
-   console.error.apply(console, arguments);
-   }
try {
-   Syslog.log(Syslog.LOG_INFO, util.format.apply(this, arguments));
+   // en/disable log messages here
+   if (program.verbose || program.debug) {
+   console.error.apply(console, arguments);
+   }
+   if (process.send) {
+   process.send({
+   type: 'log',
+   level: 'info',
+   message: util.format.apply(null, arguments)
+   });
+   }
} catch (err) {
// This should never happen!  But don't try to convert arguments
// toString() if it does, since that might fail too.
-   Syslog.log(Syslog.LOG_ERR, Could not format message! +err);
+   console.error(Could not format message!, err);
+   if (process.send) {
+   process.send({
+   type: 'log',
+   level: 'error',
+   message: 'Could not format message! ' + err,
+   stack: err.stack
+   });
+   }
}
 };
 
@@ -85,17 +90,21 @@
options.toc = !/^(no|false|off)$/i.test(program.toc);
 }
 
-latexer.convert(options).then(function(status) {
-   Syslog.close();
-   process.exit(status);
-}, function(err) {
-   if ((program.debug || program.syslog)  err.stack) {
-   console.error(err.stack);
-   Syslog.log(Syslog.LOG_ERR, JSON.stringify(err.stack));
+latexer.convert(options).catch(function(err) {
+   var msg = {
+   type: 'log',
+   level: 'error'
+   };
+   if ( err instanceof Error ) {
+   msg.message = err.message;
+   msg.stack = err.stack;
} else {
-   console.error(err);
-   Syslog.log(Syslog.LOG_ERR, err);
+   msg.message = '' + err;
}
-   Syslog.close();
-   process.exit(1);
+   console.error( (program.debug  msg.stack) || msg.message );
+   // process.send is sync, so we won't exit before this is sent (yay)
+   if (process.send) {
+   process.send(msg);
+   }
+   process.exit(err.exitCode || 1);
 }).done();
diff --git a/lib/index.js b/lib/index.js
index a73b4dc..ab17b40 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -1780,14 +1780,15 @@
  *
  * Convert a bundle to LaTeX and/or a PDF, respecting the given `options`.
  *
- * Return a promise for an exit status (0 for success) after the bundle
- * specified in the options has been converted.
+ * Return a promise which is resolved with no value after the bundle
+ * specified in the options has been converted.  If there is a problem
+ * during the conversion, the promise is rejected.
  */
 var convert = function(options) {
var status = options.status = new StatusReporter(4, function(msg) {
if (options.log) {
var file = msg.file ? (': ' + msg.file) : '';
-   

[MediaWiki-commits] [Gerrit] Use new log and status reporting framework - change (mediawiki...latex_renderer)

2014-08-01 Thread Mwalker (Code Review)
Mwalker has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/151222

Change subject: Use new log and status reporting framework
..

Use new log and status reporting framework

Log through the service! Remove dependency on syslog. I also want
all errors exposed through the service so I always have to throw
and then have the main application promise catch it.

Change-Id: I00b1479404441063132c57f3ffe1c37f80658938
---
M bin/mw-ocg-latexer
M lib/index.js
M lib/status.js
M package.json
4 files changed, 19 insertions(+), 36 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Collection/OfflineContentGenerator/latex_renderer
 refs/changes/22/151222/1

diff --git a/bin/mw-ocg-latexer b/bin/mw-ocg-latexer
index 4e4c1f6..d9d6b13 100755
--- a/bin/mw-ocg-latexer
+++ b/bin/mw-ocg-latexer
@@ -31,9 +31,7 @@
.option('-D, --debug',
'Turn on debugging features (eg, full stack traces on 
exceptions)')
.option('-T, --temporary-directory dir',
-   'Use dir for temporaries, not $TMPDIR or /tmp', null)
-   .option('--syslog',
-   'Log errors using syslog (for production deployments)');
+   'Use dir for temporaries, not $TMPDIR or /tmp', null);
 
 program.parse(process.argv);
 
@@ -48,25 +46,12 @@
 
 var bundlefile = program.args[0];
 
-var Syslog = program.syslog ? require('node-syslog') : {
-   init: function() { },
-   log: function() { },
-   close: function() { }
-};
-Syslog.init(latexer.name, Syslog.LOG_PID|Syslog.LOG_ODELAY, Syslog.LOG_LOCAL0);
-
 var log = function() {
// en/disable log messages here
if (program.verbose || program.debug) {
console.error.apply(console, arguments);
}
-   try {
-   Syslog.log(Syslog.LOG_INFO, util.format.apply(this, arguments));
-   } catch (err) {
-   // This should never happen!  But don't try to convert arguments
-   // toString() if it does, since that might fail too.
-   Syslog.log(Syslog.LOG_ERR, Could not format message! +err);
-   }
+   process.send({type:'log', level: 'info', message: 
Array.prototype.slice.call(arguments)});
 };
 
 var options = {
@@ -86,16 +71,23 @@
 }
 
 latexer.convert(options).then(function(status) {
-   Syslog.close();
process.exit(status);
 }, function(err) {
-   if ((program.debug || program.syslog)  err.stack) {
-   console.error(err.stack);
-   Syslog.log(Syslog.LOG_ERR, JSON.stringify(err.stack));
-   } else {
-   console.error(err);
-   Syslog.log(Syslog.LOG_ERR, err);
-   }
-   Syslog.close();
+   var format = function( err ) {
+   if ( err instanceof Error ) {
+   return {
+   message: err.message,
+   stack: err.stack
+   };
+   } else {
+   return {
+   message: err,
+   stack: null
+   };
+   }
+   };
+   err = format( err );
+   console.error( err );
+   process.send({type:'log', level: 'error', message: [err.message, err]});
process.exit(1);
 }).done();
diff --git a/lib/index.js b/lib/index.js
index fccb415..5520871 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -1776,14 +1776,6 @@
}).then(function() {
status.createStage(0, 'Done');
return 0; // success!
-   }, function(err) {
-   // xxx clean up?
-   if (options.debug) {
-   throw err;
-   }
-   // xxx send this error to parent process, if there is one?
-   console.error('Error:', err);
-   return 1;
});
 };
 
diff --git a/lib/status.js b/lib/status.js
index 3832366..c117eb5 100644
--- a/lib/status.js
+++ b/lib/status.js
@@ -25,7 +25,7 @@
this.extraLog(msg);
}
if (process.send) {
-   process.send(msg);
+   process.send({type: 'status', message: msg});
}
 };
 
diff --git a/package.json b/package.json
index 64913b8..e210403 100644
--- a/package.json
+++ b/package.json
@@ -26,7 +26,6 @@
 es6-shim: ~0.13.0,
 gammalatex: cscott/gammalatex#race-be-gone,
 icu-bidi: ~0.1.2,
-node-syslog: ~1.1.7,
 prfun: ~1.0.0,
 readable-stream: ~1.0.0,
 sqlite3: ~2.2.3,

-- 
To view, visit https://gerrit.wikimedia.org/r/151222
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I00b1479404441063132c57f3ffe1c37f80658938
Gerrit-PatchSet: 1
Gerrit-Project: 
mediawiki/extensions/Collection/OfflineContentGenerator/latex_renderer
Gerrit-Branch: master
Gerrit-Owner: Mwalker