Skip to content

Commit

Permalink
Clean up verbose log output versus debug output. Verbose output only …
Browse files Browse the repository at this point in the history
…logs fetches
  • Loading branch information
zachleat committed Dec 19, 2024
1 parent 459f9ba commit ab8cdcf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
9 changes: 5 additions & 4 deletions src/AssetCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ const fs = require("graceful-fs");
const path = require("path");
const { create: FlatCacheCreate } = require("flat-cache");
const { createHash } = require("crypto");
const debugUtil = require("debug");

const Sources = require("./Sources.js");

const debugUtil = require("debug");
const debug = debugUtil("Eleventy:Fetch");
const debugAssets = debugUtil("Eleventy:Assets");

Expand Down Expand Up @@ -256,7 +256,8 @@ class AssetCache {

this.ensureDir();

debugAssets("Writing cache file to disk for %o", this.source)
debugAssets("[@11ty/eleventy-fetch] Writing to disk cache from %o", this.source);

// the contents must exist before the cache metadata are saved below
fs.writeFileSync(contentPath, contents);
debug(`Writing ${contentPath}`);
Expand Down Expand Up @@ -361,11 +362,11 @@ class AssetCache {
async fetch(optionsOverride = {}) {
if (this.isCacheValid(optionsOverride.duration)) {
// promise
this.log(`Using cached version of: ${this.uniqueKey}`);
debug(`Using cached version of: ${this.uniqueKey}`);
return this.getCachedValue();
}

this.log(`Saving ${this.uniqueKey} to ${this.cacheFilename}`);
debug(`Saving ${this.uniqueKey} to ${this.cacheFilename}`);
await this.save(this.source, optionsOverride.type);

return this.source;
Expand Down
16 changes: 10 additions & 6 deletions src/RemoteAssetCache.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
const debugUtil = require("debug");
const { parseXml } = require('@rgrove/parse-xml');

const Sources = require("./Sources.js");
const AssetCache = require("./AssetCache.js");
const assetDebug = require("debug")("Eleventy:Assets");

const debug = debugUtil("Eleventy:Fetch");
const debugAssets = debugUtil("Eleventy:Assets");

class RemoteAssetCache extends AssetCache {
#queue;
Expand Down Expand Up @@ -135,7 +138,7 @@ class RemoteAssetCache extends AssetCache {
// Important: no disk writes when dryRun
// As of Fetch v4, reads are now allowed!
if (this.isCacheValid(optionsOverride.duration)) {
this.log(`Cache hit for ${this.displayUrl}`);
debug(`Cache hit for ${this.displayUrl}`);
this.#lastFetchType = "hit";
return super.getCachedValue();
}
Expand All @@ -144,7 +147,7 @@ class RemoteAssetCache extends AssetCache {

try {
let isDryRun = optionsOverride.dryRun || this.options.dryRun;
this.log(`${isDryRun ? "Fetching" : "Cache miss for"} ${this.displayUrl}`);
this.log(`Fetching ${this.displayUrl}`);

let body;
let metadata = {};
Expand All @@ -162,7 +165,8 @@ class RemoteAssetCache extends AssetCache {

this.fetchCount++;

assetDebug("Fetching remote asset: %o", this.source);
debugAssets("[@11ty/eleventy-fetch] Fetching: %o", this.source);

// v5: now using global (Node-native or otherwise) fetch instead of node-fetch
let response = await fetch(this.source, fetchOptions);
if (!response.ok) {
Expand Down Expand Up @@ -196,8 +200,8 @@ class RemoteAssetCache extends AssetCache {
return body;
} catch (e) {
if (this.cachedObject) {
this.log(`Error fetching ${this.displayUrl}. Message: ${e.message}`);
this.log(`Failing gracefully with an expired cache entry.`);
debug(`Error fetching ${this.displayUrl}. Message: ${e.message}`);
debug(`Failing gracefully with an expired cache entry.`);
return super.getCachedValue();
} else {
return Promise.reject(e);
Expand Down

0 comments on commit ab8cdcf

Please sign in to comment.