Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show mount points in debug log #1325

Merged
merged 3 commits into from
Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}