Complete collection of AI agent skills including: - Frontend Development (Vue, React, Next.js, Three.js) - Backend Development (NestJS, FastAPI, Node.js) - Mobile Development (React Native, Expo) - Testing (E2E, frontend, webapp) - DevOps (GitHub Actions, CI/CD) - Marketing (SEO, copywriting, analytics) - Security (binary analysis, vulnerability scanning) - And many more... Synchronized from: https://skills.sh/ Co-Authored-By: Claude <noreply@anthropic.com>
64 lines
1.4 KiB
TypeScript
64 lines
1.4 KiB
TypeScript
/**
|
|
* Logger utility for the dev-browser extension.
|
|
* Logs to console and optionally sends to relay server.
|
|
*/
|
|
|
|
export type LogLevel = "log" | "debug" | "error";
|
|
|
|
export interface LogMessage {
|
|
method: "log";
|
|
params: {
|
|
level: LogLevel;
|
|
args: string[];
|
|
};
|
|
}
|
|
|
|
export type SendMessageFn = (message: unknown) => void;
|
|
|
|
/**
|
|
* Creates a logger instance that logs to console and sends to relay.
|
|
*/
|
|
export function createLogger(sendMessage: SendMessageFn) {
|
|
function formatArgs(args: unknown[]): string[] {
|
|
return args.map((arg) => {
|
|
if (arg === undefined) return "undefined";
|
|
if (arg === null) return "null";
|
|
if (typeof arg === "object") {
|
|
try {
|
|
return JSON.stringify(arg);
|
|
} catch {
|
|
return String(arg);
|
|
}
|
|
}
|
|
return String(arg);
|
|
});
|
|
}
|
|
|
|
function sendLog(level: LogLevel, args: unknown[]): void {
|
|
sendMessage({
|
|
method: "log",
|
|
params: {
|
|
level,
|
|
args: formatArgs(args),
|
|
},
|
|
});
|
|
}
|
|
|
|
return {
|
|
log: (...args: unknown[]) => {
|
|
console.log("[dev-browser]", ...args);
|
|
sendLog("log", args);
|
|
},
|
|
debug: (...args: unknown[]) => {
|
|
console.debug("[dev-browser]", ...args);
|
|
sendLog("debug", args);
|
|
},
|
|
error: (...args: unknown[]) => {
|
|
console.error("[dev-browser]", ...args);
|
|
sendLog("error", args);
|
|
},
|
|
};
|
|
}
|
|
|
|
export type Logger = ReturnType<typeof createLogger>;
|