Skip to content
Permalink
Browse files

Updates application logging

  • Loading branch information
davidmerfield committed Nov 24, 2019
1 parent b6b251e commit 1149094d14b4c00227becf868d9a08e780d5cc42
Showing with 32 additions and 25 deletions.
  1. +3 −1 app/build/index.js
  2. +6 −3 app/helper/clfdate.js
  3. +2 −2 app/index.js
  4. +3 −3 app/models/entry/set.js
  5. +2 −4 app/models/ignoredFiles.js
  6. +8 −5 app/sync/index.js
  7. +6 −5 app/sync/renames.js
  8. +2 −2 app/sync/update/index.js
@@ -3,6 +3,8 @@ var uuid = require("uuid/v4");
var exitHook = require("async-exit-hook");
var child_process = require("child_process");
var debug = require("debug")("blot:build");
var helper = require("helper");
var clfdate = helper.clfdate;
var workers = [];
var jobs = {};

@@ -123,6 +125,6 @@ module.exports = function(blog, path, options, callback) {
};

debug("Sending job to worker", jobs[id]);
console.log("Blog:", blog.id, "building", path);
console.log(clfdate(), blog.id, path, "building");
worker.send({ blog: blog, path: path, id: id, options: options });
};
@@ -29,7 +29,10 @@ function rpad3(num) {
return str;
}

module.exports = function clfdate(dateTime) {
module.exports = function clfdate() {

dateTime = new Date();

var date = dateTime.getUTCDate();
var hour = dateTime.getUTCHours();
var mins = dateTime.getUTCMinutes();
@@ -39,7 +42,7 @@ module.exports = function clfdate(dateTime) {

var month = CLF_MONTH[dateTime.getUTCMonth()];

return (
return ("[" +
pad2(date) +
"/" +
month +
@@ -53,6 +56,6 @@ module.exports = function clfdate(dateTime) {
pad2(secs) +
"." +
rpad3(msecs) +
" +0000"
" +0000]"
);
};
@@ -29,7 +29,7 @@ Blot.use(function(req, res, next) {

try {
console.log(
"[" + clfdate(new Date()) + "]",
clfdate(),
req.headers["x-request-id"],
"REQ",
req.protocol + "://" + req.hostname + req.originalUrl,
@@ -42,7 +42,7 @@ Blot.use(function(req, res, next) {
res.on("finish", function() {
try {
console.log(
"[" + clfdate(new Date()) + "]",
clfdate(),
req.headers["x-request-id"],
"RES",
req.protocol + "://" + req.hostname + req.originalUrl,
@@ -1,7 +1,7 @@
var helper = require("helper");
var ensure = helper.ensure;
var doEach = helper.doEach;

var clfdate = helper.clfdate;
var model = require("./model");
var redis = require("client");

@@ -108,9 +108,9 @@ module.exports = function set(blogID, path, updates, callback) {

doEach(queue, function() {
if (entry.deleted) {
console.log("Blog:", blogID, "Entry:", path, "deleted");
console.log(clfdate(), blogID, path, "deleted");
} else {
console.log("Blog:", blogID, "Entry:", path, "updated");
console.log(clfdate(), blogID, path, "updated");
}
callback(null);
});
@@ -1,6 +1,7 @@
module.exports = (function() {
var redis = require("client"),
helper = require("helper"),
clfdate = helper.clfdate,
normalize = helper.pathNormalizer,
ensure = helper.ensure,
REASONS = {
@@ -29,10 +30,7 @@ module.exports = (function() {
redis.hset(ignoredFilesKey(blogID), path, reason, function(err) {
if (err) throw err;

console.log(
"Blog: " + blogID + ": Ignored " + path,
"because it is " + reason
);
console.log(clfdate(), blogID, path, "ignored for", reason);
callback();
});
}
@@ -3,7 +3,10 @@ var Redlock = require("redlock");
var buildFromFolder = require("template").buildFromFolder;
var Blog = require("blog");
var Update = require("./update");
var localPath = require("helper").localPath;
var helper = require("helper");
var localPath = helper.localPath;
var clfdate = helper.clfdate;
var uuid = require("uuid/v4");
var async = require("async");
var renames = require("./renames");
var exitHook = require("async-exit-hook");
@@ -89,11 +92,11 @@ function sync(blogID, options, callback) {
// We acquired a lock on the resource!
// This function is to be called when we are finished
// with the lock on the user's folder.
now = new Date();
console.log("Blog:", blogID, "Sync:", now, "Started");
syncID = "sync_" + uuid().slice(0, 7);
console.log(clfdate(), blogID, syncID, "Started");

callback(null, folder, function(syncError, callback) {
console.log("Blog:", blogID, "Sync:", now, "Released");
console.log(clfdate(), blogID, syncID, "Released");

if (typeof syncError === "function")
throw new Error("Pass an error or null as first argument to done");
@@ -123,7 +126,7 @@ function sync(blogID, options, callback) {
Blog.set(blogID, { cacheID: Date.now() }, function(err) {
if (err) return callback(err);

console.log("Blog:", blogID, "Sync:", now, "Finished");
console.log(clfdate(), blogID, syncID, "Finished");
callback(syncError);
});
});
@@ -1,6 +1,8 @@
var Entries = require("entries");
var async = require("async");
var Entry = require("entry");
var helper = require("helper");
var clfdate = helper.clfdate;

module.exports = function(blogID, update, callback) {
var RENAME_PERIOD = 1000 * 60; // 1 minute
@@ -76,13 +78,12 @@ module.exports = function(blogID, update, callback) {
}

console.log(
"Blog:",
clfdate(),
blogID,
"Entry rename detected:",
"\n (deleted)",
createdEntry.path,
"(created) <==",
deletedEntry.path,
"\n (created)",
createdEntry.path
"(deleted)"
);

Entry.set(blogID, createdEntry.path, updates, next);
@@ -1,7 +1,7 @@
var fs = require("fs-extra");
var helper = require("helper");
var localPath = helper.localPath;

var clfdate = helper.clfdate;
var drop = require("./drop");
var set = require("./set");
var mkdir = require("./mkdir");
@@ -21,7 +21,7 @@ module.exports = function(blog) {
function done(err) {
// we never let this error escape out
if (err) {
console.error("Blog", blog.id, "Caught error updating", path, err);
console.error(clfdate(), blog.id, path, err);
}
callback(null, { error: err || null });
}

0 comments on commit 1149094

Please sign in to comment.
You can’t perform that action at this time.