Files
kuber/lib/logger.ts
T
dmgnr 8f331d4cc7 feat: add commands for managing deployments and resources
- Implemented `down` command to delete managed resources, with an option to delete ingress and PVCs.
- Added `exec` command to execute commands inside deployment pods.
- Created `logs` command to show deployment logs with an option to follow the output.
- Introduced `start` command to start deployments without rebuilding images.
- Developed `stop` command to scale managed deployments to zero.

refactor: enhance resource management and Kubernetes interactions

- Refactored resource handling in `lib/apply.ts` to support sorting and applying resources.
- Improved logging functionality with a new logger in `lib/logger.ts`.
- Enhanced build process in `lib/build.ts` to support remote builds and syncing with Git repositories.
- Added functions to manage deployments and pods in `lib/shared.ts`.

chore: update dependencies and TypeScript configuration

- Updated package.json to include `listr2` for task management.
- Modified tsconfig.json to exclude build artifacts and fixtures.
2026-08-09 00:18:14 +07:00

81 lines
2.3 KiB
TypeScript

//reused logger from other projects but use for only deployment logging
import { feature } from "bun:bundle";
import type { InspectColor } from "node:util";
import { styleText } from "node:util";
import { inspect } from "bun";
const colors: InspectColor[] = [
"red",
"green",
"yellow",
"blue",
"magenta",
"cyan",
"white",
"redBright",
"greenBright",
"yellowBright",
"blueBright",
"magentaBright",
"cyanBright",
"whiteBright",
];
var i = 0;
// if (!feature("prod"))
// console.log(
// colors.map((c, i) => styleText(c, (i + 10).toString(36))).join(""),
// );
export type Logger = {
(strings: TemplateStringsArray, ...values: unknown[]): void;
error(strings: TemplateStringsArray, ...values: unknown[]): void;
warn(strings: TemplateStringsArray, ...values: unknown[]): void;
debug(strings: TemplateStringsArray, ...values: unknown[]): void;
};
export function createLogger(label?: string) {
const start = Date.now();
const col = colors[i]!;
i = (i + 1) % colors.length;
function mkLogFn(stream: Console | NodeJS.WriteStream, strip?: InspectColor) {
return (strings: TemplateStringsArray, ...values: unknown[]) => {
const normalized = styleText(
col,
`${(strip ? styleText : (_: string, s: string) => s)("bold", (label ?? `${Date.now() - start}ms`).padStart(7))} ▌${strip ? styleText(strip, "▌") : " "}${strings
.reduce(
(out, str, i) =>
out +
styleText(col, str) +
(typeof values[i] === "string"
? values[i]
: typeof values[i] !== "undefined"
? inspect(values[i], { colors: true })
: ""),
"",
)
.split("\n")
.map((l, i) =>
styleText(
col,
i
? `${" ".repeat(7)} ▌${strip ? styleText(strip, "▌") : " "}${l}`
: l,
),
)
.join("\n")}\n`,
);
(stream.write as (data: string) => void)(normalized);
};
}
const log = mkLogFn(console) as Logger;
log.error = mkLogFn(process.stderr, "redBright");
log.warn = mkLogFn(console, "yellow");
log.debug = feature("prod") ? () => {} : mkLogFn(console, "blue");
return log;
}
export const log = createLogger("APP");