Skip to content

Commit

Permalink
add doc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nhedger committed Oct 5, 2024
1 parent e8ea497 commit 93ef147
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ export const logger = window.createOutputChannel(displayName, {

type LogArguments = Record<string, unknown>;

/**
* Logs a message
*
* This function logs a generic message to the extension's logger on the
* `Biome` output channel. The message will only be logged if the extension's
* logging level is set to level specified by the `level` parameter.
*/
export const log = (
message: string,
level: LogLevel = LogLevel.Info,
Expand All @@ -42,18 +49,69 @@ export const log = (
}
};

/**
* Clears the logger
*
* This function does not actually clear the logger, but rather appends a
* few newlines to the logger to ensure that the logger so that logs from a
* previous run are visually separated from the current run. We need to do
* this because of a bug in VS Code where the output channel is not cleared
* properly when calling `clear()` on it.
*
* @see https://github.com/microsoft/vscode/issues/224516
*/
export const clear = () => {
logger.append("\n\n\n\n\n");
};

/**
* Log an informational message
*
* This function logs an informational message to the extension's logger
* on the `Biome` output channel. The message will only be logged if the
* extension's logging level is set to `Info` or higher.
*
* @param message The message to log
* @param args Optional arguments to show alongside the message
*/
export const info = (message: string, args?: LogArguments) =>
log(message, LogLevel.Info, args);

/**
* Log a warning message
*
* This function logs a warning message to the extension's logger on the
* `Biome` output channel. The message will only be logged if the extension's
* logging level is set to `Warning` or higher.
*
* @param message The message to log
* @param args Optional arguments to show alongside the message
*/
export const warn = (message: string, args?: LogArguments) =>
log(message, LogLevel.Warning, args);

/**
* Log an error message
*
* This function logs an error message to the extension's logger on the
* `Biome` output channel. The message will only be logged if the extension's
* logging level is set to `Error` or higher.
*
* @param message The message to log
* @param args Optional arguments to show alongside the message
*/
export const error = (message: string, args?: LogArguments) =>
log(message, LogLevel.Error, args);

/**
* Log a debug message
*
* This function logs a debug message to the extension's logger on the
* `Biome` output channel. The message will only be logged if the extension's
* logging level is set to `Debug` or higher.
*
* @param message The message to log
* @param args Optional arguments to show alongside the message
*/
export const debug = (message: string, args?: LogArguments) =>
log(message, LogLevel.Debug, args);

0 comments on commit 93ef147

Please sign in to comment.