make logs useful

This commit is contained in:
jomo
2014-11-02 05:24:22 +01:00
9 changed files with 111 additions and 22 deletions

View File

@@ -5,14 +5,14 @@ var exp = {};
// sets the timestamp for +uuid+ to now
exp.update_timestamp = function(uuid) {
console.log("cache: updating timestamp for " + uuid);
console.log(uuid + " cache: updating timestamp");
var time = new Date().getTime();
redis.hmset(uuid, "t", time);
};
// create the key +uuid+, store +hash+ and time
exp.save_hash = function(uuid, hash) {
console.log("cache: saving hash for " + uuid);
console.log(uuid + " cache: saving hash");
var time = new Date().getTime();
redis.hmset(uuid, "h", hash, "t", time);
};

View File

@@ -20,17 +20,17 @@ function store_images(uuid, details, callback) {
} else {
var skinurl = skin_url(profile);
if (skinurl) {
console.log(skinurl);
console.log(uuid + " " + skinurl);
// set file paths
var hash = get_hash(skinurl);
if (details && details.h == hash) {
// hash hasn't changed
console.log("hash has not changed");
console.log(uuid + " hash has not changed");
cache.update_timestamp(uuid);
callback(null, hash);
} else {
// hash has changed
console.log("new hash: " + hash);
console.log(uuid + "new hash: " + hash);
var facepath = config.faces_dir + hash + ".png";
var helmpath = config.helms_dir + hash + ".png";
// download skin, extract face/helm
@@ -81,15 +81,15 @@ function get_image_hash(uuid, callback) {
} else {
if (details && details.t + config.local_cache_time >= new Date().getTime()) {
// uuid known + recently updated
console.log("uuid known & recently updated");
console.log(uuid + " uuid known & recently updated");
callback(null, 1, details.h);
} else {
console.log("uuid not known or too old");
console.log(uuid + " uuid not known or too old");
store_images(uuid, details, function(err, hash) {
if (err) {
callback(err, -1, details && details.h);
} else {
console.log("hash: " + hash);
console.log(uuid + " hash: " + hash);
callback(null, (hash ? 2 : 3), hash);
}
});

View File

@@ -15,7 +15,7 @@ exp.get_profile = function(uuid, callback) {
}, function (error, response, body) {
if (!error && response.statusCode == 200) {
// profile downloaded successfully
console.log("profile downloaded for " + uuid);
console.log(uuid + " profile downloaded");
callback(null, JSON.parse(body));
} else {
if (error) {
@@ -23,13 +23,13 @@ exp.get_profile = function(uuid, callback) {
return;
} else if (response.statusCode == 204 || response.statusCode == 404) {
// we get 204 No Content when UUID doesn't exist (including 404 in case they change that)
console.log("uuid does not exist");
console.log(uuid + " uuid does not exist");
} else if (response.statusCode == 429) {
// Too Many Requests
console.warn("Too many requests for " + uuid);
console.warn(uuid + " Too many requests");
console.warn(body);
} else {
console.error("Unknown error:");
console.error(uuid + " Unknown error:");
console.error(response);
console.error(body);
}
@@ -50,14 +50,14 @@ exp.skin_file = function(url, facename, helmname, callback) {
}, function (error, response, body) {
if (!error && response.statusCode == 200) {
// skin downloaded successfully
console.log("skin downloaded.");
console.log(url + " skin downloaded");
skins.extract_face(body, facename, function(err) {
if (err) {
callback(err);
} else {
console.log("face extracted.");
console.log(facename + " face extracted");
skins.extract_helm(facename, body, helmname, function(err) {
console.log("helm extracted.");
console.log(helmname + " helm extracted.");
callback(err);
});
}
@@ -66,14 +66,14 @@ exp.skin_file = function(url, facename, helmname, callback) {
if (error) {
console.error("Error downloading '" + url + "': " + error);
} else if (response.statusCode == 404) {
console.warn("Texture not found: " + url);
console.warn(url + " texture not found");
} else if (response.statusCode == 429) {
// Too Many Requests
// Never got this, seems like textures aren't limited
console.warn("Too many requests for " + url);
console.warn(url + " too many requests");
console.warn(body);
} else {
console.error("Unknown error:");
console.error(url + " unknown error:");
console.error(response);
console.error(body);
}