Skip to content

Instantly share code, notes, and snippets.

@moritz-t-w
Created May 9, 2023 18:38
Show Gist options
  • Save moritz-t-w/d14435541fb9e7ef9313a1a726d9b263 to your computer and use it in GitHub Desktop.
Save moritz-t-w/d14435541fb9e7ef9313a1a726d9b263 to your computer and use it in GitHub Desktop.
Simple (and incomplete) utility to allow for an (incomplete) analog to console.group() and console.groupEnd() in Deno's log lib
import { denoLog } from "https://deno.land/std@/log/mod.ts";
/** Singleton to keep track of the current groups */
class Groups {
private static _groups: string[] = [];
public static get groups() {
return Groups._groups;
}
public static push(name: string) {
Groups._groups.push(name);
}
public static pop() {
return Groups._groups.pop();
}
}
const group = (name: string, ...args: unknown[]) => {
denoLog.info(`${name}...`, ...args);
Groups.push(name);
}
const groupEnd = (message?: string, ...args: unknown[]) => {
denoLog.info(message ?? `Done ${Groups.pop() ?? ""}.`, ...args);
}
export default {
...denoLog,
group,
groupEnd
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment