Permalink
Browse files

Log errors, warnings, and info to syslog (Use --console to log to con…

…sole).
  • Loading branch information...
scottgonzalez committed Jan 3, 2012
1 parent 5e7cd6f commit 7cf2402188f3dd2fbc20c7a19c9b50493485510c
Showing with 40 additions and 21 deletions.
  1. +2 −1 package.json
  2. +5 −3 src/hook.js
  3. +22 −0 src/logger.js
  4. +2 −4 src/retry.js
  5. +4 −7 src/update.js
  6. +5 −6 src/wp-update.js
View
@@ -15,7 +15,8 @@
"semver": "1.0.12",
"sqlite3": "2.1.1",
"step": "0.0.5",
- "rimraf": "1.0.9"
+ "rimraf": "1.0.9",
+ "node-syslog": "1.1.1"
},
"engines": {
"node": "0.6.5"
View
@@ -3,13 +3,14 @@ var semver = require( "semver" ),
UserError = require( "./user-error" ),
pluginsDb = require( "./pluginsdb" ),
service = require( "./service" ),
- retry = require( "./retrydb" );
+ retry = require( "./retrydb" ),
+ logger = require( "./logger" );
function processHook( data, fn ) {
var repo = service.getRepoByHook( data );
if ( !repo ) {
- // TODO: log and bail (no retry)
+ logger.warn( "Could not parse hook: " + JSON.stringify( data ) );
return fn( new Error( "Could not parse hook." ) );
}
@@ -132,6 +133,7 @@ function processRelease( repo, release, fn ) {
// the plugin is owned by someone else
if ( owner !== repo.userName ) {
// TODO: report error to user
+ logger.log( repo.userName + " attempted to add " + release.package.name + " which is owned by " + owner );
return fn( new UserError( "Plugin " + release.package.name + " is owned by " + owner + "." ) );
}
@@ -150,7 +152,7 @@ function processRelease( repo, release, fn ) {
return fn( error );
}
- console.log( "Added " + release.package.name + " " + release.package.version + " to plugins DB" );
+ logger.log( "Added " + release.package.name + " v" + release.package.version + " to plugins DB" );
fn( null, release );
}
);
View
@@ -0,0 +1,22 @@
+if ( process.argv.indexOf( "--console" ) !== -1 ) {
+ module.exports = console;
+ return;
+}
+
+var syslog = require( "node-syslog" );
+
+syslog.init( "plugins.jquery.com", syslog.LOG_PID, syslog.LOG_LOCAL0 );
+
+module.exports = {
+ log: function( msg ) {
+ syslog.log( syslog.LOG_INFO, msg );
+ },
+
+ warn: function( msg ) {
+ syslog.log( syslog.LOG_NOTICE, msg );
+ },
+
+ error: function( msg ) {
+ syslog.log( syslog.LOG_ERR, msg );
+ }
+};
View
@@ -4,9 +4,7 @@ var Step = require( "step" ),
retry = require( "./retrydb" );
process.on( "uncaughtException", function( error ) {
- // TODO: log error to file
- console.error( "uncaught exception" );
- console.error( error.stack );
+ logger.error( "Uncaught exception: " + error.stack );
});
// exponential backoff for retries, with a max of 2 minutes
@@ -85,5 +83,5 @@ function processFailures( fn ) {
}
processFailures(function( error ) {
- console.error( error.stack );
+ logger.error( "Error during retry: " + error.stack );
});
View
@@ -1,19 +1,16 @@
-var hook = require( "./hook" );
+var hook = require( "./hook" ),
+ logger = require( "./logger" );
process.on( "uncaughtException", function( error ) {
- // TODO: log error to file
- console.error( "uncaught exception" );
- console.error( error.stack );
+ logger.error( "Uncaught exception: " + error.stack );
});
hook.processHook({
url: "http://github.com/scottgonzalez/temp-jquery-foo",
watchers: 25,
forks: 3
}, function( error, data ) {
- // TODO: log error to file
if ( error ) {
- console.error( error );
- console.error( error.stack );
+ logger.error( "Error processing hook: " + error.stack );
}
});
View
@@ -4,13 +4,12 @@ var fs = require( "fs" ),
template = require( "./template" ),
wordpress = require( "./wordpress" ),
pluginsDb = require( "./pluginsdb" ),
- service = require( "./service" );
+ service = require( "./service" ),
+ logger = require( "./logger" );
process.on( "uncaughtException", function( error ) {
- // TODO: log error to file
wordpress.end();
- console.error( "uncaught exception" );
- console.error( error.stack );
+ logger.error( "Uncaught exception: " + error.stack );
});
function isStable( version ) {
@@ -129,7 +128,7 @@ actions.addRelease = function( data, fn ) {
},
function( error ) {
- console.log( "Added", package.name, package.version, "to WordPress" );
+ logger.log( "Added " + package.name + " v" + package.version + " to WordPress" );
fn( error );
}
);
@@ -235,5 +234,5 @@ function processNextAction( actionId, fn ) {
processActions(function( error ) {
wordpress.end();
- console.error( error.stack );
+ logger.error( "Error updating WordPress: " + error.stack );
});

0 comments on commit 7cf2402

Please sign in to comment.