Skip to content

Commit

Permalink
Show mount points in debug log (#1325)
Browse files Browse the repository at this point in the history
* Show mount points in debug log

* Improve in-memory cache wording

* Formatting
  • Loading branch information
canadaduane authored Oct 15, 2020
1 parent f563593 commit 970af70
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
9 changes: 9 additions & 0 deletions snowpack/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,15 @@ export async function startServer(commandOptions: CommandOptions) {
const filesBeingDeleted = new Set<string>();
const filesBeingBuilt = new Map<string, Promise<SnowpackBuildMap>>();

logger.debug(`Using in-memory cache.`);
logger.debug(`Mounting directories:`, {
task: () => {
for (const [dirDisk, dirUrl] of Object.entries(config.mount)) {
logger.debug(` -> '${dirDisk}' as URL '${dirUrl}'`);
}
},
});

// Set the proper install options, in case an install is needed.
const dependencyImportMapLoc = path.join(DEV_DEPENDENCIES_DIR, 'import-map.json');
logger.debug(`Using cache folder: ${path.relative(cwd, DEV_DEPENDENCIES_DIR)}`);
Expand Down
24 changes: 19 additions & 5 deletions snowpack/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,17 @@ class SnowpackLogger {
},
};

private log({level, name, message}: {level: LoggerEvent; name: string; message: string}) {
private log({
level,
name,
message,
task,
}: {
level: LoggerEvent;
name: string;
message: string;
task?: Function;
}) {
// test if this level is enabled or not
if (levels[this.level] > levels[level]) {
return; // do nothing
Expand Down Expand Up @@ -66,30 +76,34 @@ class SnowpackLogger {
} else {
throw new Error(`No logging method defined for ${level}`);
}

// logger takes a possibly processor-intensive task, and only
// processes it when this log level is enabled
task && task(this);
}

/** emit messages only visible when --debug is passed */
public debug(message: string, options?: LoggerOptions): void {
const name = (options && options.name) || 'snowpack';
this.log({level: 'debug', name, message});
this.log({level: 'debug', name, message, task: options?.task});
}

/** emit general info */
public info(message: string, options?: LoggerOptions): void {
const name = (options && options.name) || 'snowpack';
this.log({level: 'info', name, message});
this.log({level: 'info', name, message, task: options?.task});
}

/** emit non-fatal warnings */
public warn(message: string, options?: LoggerOptions): void {
const name = (options && options.name) || 'snowpack';
this.log({level: 'warn', name, message});
this.log({level: 'warn', name, message, task: options?.task});
}

/** emit critical error messages */
public error(message: string, options?: LoggerOptions): void {
const name = (options && options.name) || 'snowpack';
this.log({level: 'error', name, message});
this.log({level: 'error', name, message, task: options?.task});
}

/** get full logging history */
Expand Down
2 changes: 2 additions & 0 deletions snowpack/src/types/snowpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,6 @@ export type LoggerEvent = 'debug' | 'info' | 'warn' | 'error';
export interface LoggerOptions {
/** (optional) change name at beginning of line */
name?: string;
/** (optional) do some additional work after logging a message, if log level is enabled */
task?: Function;
}

1 comment on commit 970af70

@vercel
Copy link

@vercel vercel bot commented on 970af70 Oct 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.