Skip to content

Commit

Permalink
chore: add color formatting and severity level notice logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
bombillazo committed Feb 18, 2024
1 parent 48b4cc5 commit 87151ed
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
18 changes: 14 additions & 4 deletions connection/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import {
bold,
BufReader,
BufWriter,
cyan,
delay,
joinPath,
rgb24,
yellow,
} from "../deps.ts";
import { DeferredStack } from "../utils/deferred.ts";
Expand Down Expand Up @@ -99,15 +99,25 @@ function assertSuccessfulAuthentication(auth_message: Message) {
}

function logNotice(notice: Notice) {
console.error(`${bold(yellow(notice.severity))}: ${notice.message}`);
if (notice.severity === "INFO") {
console.info(
`[ ${bold(rgb24(notice.severity, 0xff99ff))} ] : ${notice.message}`,
);
} else if (notice.severity === "NOTICE") {
console.info(`[ ${bold(yellow(notice.severity))} ] : ${notice.message}`);
} else if (notice.severity === "WARNING") {
console.warn(
`[ ${bold(rgb24(notice.severity, 0xff9900))} ] : ${notice.message}`,
);
}
}

function logQuery(query: string) {
console.error(`${bold(cyan("QUERY"))}: ${query}`);
console.info(`[ ${bold(rgb24("QUERY", 0x00ccff))} ] : ${query}`);
}

function logResults(rows: unknown[]) {
console.error(`${bold("RESULTS")}: ${rows}`);
console.info(`[ ${bold(rgb24("RESULTS", 0x00cc00))} ] :`, rows);
}

const decoder = new TextDecoder();
Expand Down
2 changes: 1 addition & 1 deletion debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type DebugControls = DebugOptions | boolean;
type DebugOptions = {
/** Log queries */
queries?: boolean;
/** Log notices */
/** Log INFO, NOTICE, and WARNING raised database messages */
notices?: boolean;
/** Log results */
results?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export { crypto } from "https://deno.land/[email protected]/crypto/crypto.ts";
export { delay } from "https://deno.land/[email protected]/async/delay.ts";
export {
bold,
cyan,
rgb24,
yellow,
} from "https://deno.land/[email protected]/fmt/colors.ts";
export {
Expand Down

1 comment on commit 87151ed

@github-actions
Copy link

Choose a reason for hiding this comment

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

No typecheck tests failure

This error was most likely caused by incorrect type stripping from the SWC crate

Please report the following failure to https://github.com/denoland/deno with a reproduction of the current commit

Failure log

Please sign in to comment.