Skip to content

Commit ab8cdcf

Browse files
committed
Clean up verbose log output versus debug output. Verbose output only logs fetches
1 parent 459f9ba commit ab8cdcf

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/AssetCache.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ const fs = require("graceful-fs");
22
const path = require("path");
33
const { create: FlatCacheCreate } = require("flat-cache");
44
const { createHash } = require("crypto");
5+
const debugUtil = require("debug");
56

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

8-
const debugUtil = require("debug");
99
const debug = debugUtil("Eleventy:Fetch");
1010
const debugAssets = debugUtil("Eleventy:Assets");
1111

@@ -256,7 +256,8 @@ class AssetCache {
256256

257257
this.ensureDir();
258258

259-
debugAssets("Writing cache file to disk for %o", this.source)
259+
debugAssets("[@11ty/eleventy-fetch] Writing to disk cache from %o", this.source);
260+
260261
// the contents must exist before the cache metadata are saved below
261262
fs.writeFileSync(contentPath, contents);
262263
debug(`Writing ${contentPath}`);
@@ -361,11 +362,11 @@ class AssetCache {
361362
async fetch(optionsOverride = {}) {
362363
if (this.isCacheValid(optionsOverride.duration)) {
363364
// promise
364-
this.log(`Using cached version of: ${this.uniqueKey}`);
365+
debug(`Using cached version of: ${this.uniqueKey}`);
365366
return this.getCachedValue();
366367
}
367368

368-
this.log(`Saving ${this.uniqueKey} to ${this.cacheFilename}`);
369+
debug(`Saving ${this.uniqueKey} to ${this.cacheFilename}`);
369370
await this.save(this.source, optionsOverride.type);
370371

371372
return this.source;

src/RemoteAssetCache.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
const debugUtil = require("debug");
12
const { parseXml } = require('@rgrove/parse-xml');
23

34
const Sources = require("./Sources.js");
45
const AssetCache = require("./AssetCache.js");
5-
const assetDebug = require("debug")("Eleventy:Assets");
6+
7+
const debug = debugUtil("Eleventy:Fetch");
8+
const debugAssets = debugUtil("Eleventy:Assets");
69

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

145148
try {
146149
let isDryRun = optionsOverride.dryRun || this.options.dryRun;
147-
this.log(`${isDryRun ? "Fetching" : "Cache miss for"} ${this.displayUrl}`);
150+
this.log(`Fetching ${this.displayUrl}`);
148151

149152
let body;
150153
let metadata = {};
@@ -162,7 +165,8 @@ class RemoteAssetCache extends AssetCache {
162165

163166
this.fetchCount++;
164167

165-
assetDebug("Fetching remote asset: %o", this.source);
168+
debugAssets("[@11ty/eleventy-fetch] Fetching: %o", this.source);
169+
166170
// v5: now using global (Node-native or otherwise) fetch instead of node-fetch
167171
let response = await fetch(this.source, fetchOptions);
168172
if (!response.ok) {
@@ -196,8 +200,8 @@ class RemoteAssetCache extends AssetCache {
196200
return body;
197201
} catch (e) {
198202
if (this.cachedObject) {
199-
this.log(`Error fetching ${this.displayUrl}. Message: ${e.message}`);
200-
this.log(`Failing gracefully with an expired cache entry.`);
203+
debug(`Error fetching ${this.displayUrl}. Message: ${e.message}`);
204+
debug(`Failing gracefully with an expired cache entry.`);
201205
return super.getCachedValue();
202206
} else {
203207
return Promise.reject(e);

0 commit comments

Comments
 (0)