Skip to content

Commit

Permalink
allow user to provide filepath *or* directory
Browse files Browse the repository at this point in the history
for WRANGLER_LOG_DIR
  • Loading branch information
RamIdeas committed Nov 17, 2023
1 parent bc0ecc2 commit b7d958d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.TEST_CLOUDFLARE_ACCOUNT_ID }}
WRANGLER: pnpm --silent --package ${{ steps.find-wrangler.outputs.dir}} dlx wrangler
NODE_OPTIONS: "--max_old_space_size=8192"
WRANGLER_DEBUG_LOG: ${{ runner.temp }}/wrangler-debug-logs/e2e-attempt-1.log
WRANGLER_DEBUG_LOG: ${{ runner.temp }}/wrangler-debug-logs/

- name: Upload debug logs
if: always()
Expand Down
2 changes: 1 addition & 1 deletion packages/wrangler/src/environment-variables/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ type VariableNames =
| "WRANGLER_C3_COMMAND"
| "WRANGLER_CF_AUTHORIZATION_TOKEN"
| "WRANGLER_CLIENT_ID"
| "WRANGLER_DEBUG_LOG"
| "WRANGLER_LOG"
| "WRANGLER_LOG_DIR"
| "WRANGLER_REVOKE_URL"
| "WRANGLER_SEND_METRICS"
| "WRANGLER_TOKEN_URL";
Expand Down
39 changes: 21 additions & 18 deletions packages/wrangler/src/utils/debug-log-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,29 @@ import { getEnvironmentVariableFactory } from "../environment-variables/factory"
import { getBasePath } from "../paths";
import type { LoggerLevel } from "../logger";

const getDebugFilepath = getEnvironmentVariableFactory({
variableName: "WRANGLER_DEBUG_LOG",
defaultValue: () => {
const date = new Date()
.toISOString()
.replaceAll(":", "-")
.replace(".", "_")
.replace("T", "_")
.replace("Z", "");
const absoluteFilepath = path.join(
getBasePath(),
".wrangler",
"debug-logs",
`wrangler-debug-${date}.log`
);

return absoluteFilepath;
},
const getDebugFileDir = getEnvironmentVariableFactory({
variableName: "WRANGLER_LOG_DIR",
});

function getDebugFilepath() {
const dir =
getDebugFileDir() ?? path.join(getBasePath(), ".wrangler", "debug-logs");

const date = new Date()
.toISOString()
.replaceAll(":", "-")
.replace(".", "_")
.replace("T", "_")
.replace("Z", "");

const filepath = dir.endsWith(".log")
? dir // allow the user to provide an exact filepath
: path.join(dir, `wrangler-debug-${date}.log`);

// use path.resolve to allow the user-provided env var to be a relative path
return path.resolve(filepath);
}

async function ensureDirectoryExists(filepath: string) {
const dirpath = path.dirname(filepath);

Expand Down

0 comments on commit b7d958d

Please sign in to comment.