Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/docker/containers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@ const calculateMemoryUsage = (memoryStats: any): number => {
return usage;
};

type DebugLogger = {
debug: (message: string) => void;
};

const hasDebugLogger = (value: unknown): value is DebugLogger => {
return (
typeof value === 'object' &&
value !== null &&
'debug' in value &&
typeof (value as { debug?: unknown }).debug === 'function'
);
};

/**
* Fetches stats for a single container.
* @param docker The Dockerode client.
Expand All @@ -134,8 +147,8 @@ const fetchContainerStats = async (docker: any, containerId: string) => {
} catch (err) {
const errMsg = err instanceof Error ? err.message : String(err);
const msg = `Failed to fetch stats for container ${containerId}: ${errMsg}`;
if (typeof (logger as any).debug === 'function') {
(logger as any).debug(msg);
if (hasDebugLogger(logger)) {
logger.debug(msg);
} else {
console.debug(msg);
}
Expand Down
Loading