All files / utils/src/utilities/logging index.ts

100% Statements 15/15
100% Branches 0/0
100% Functions 3/3
100% Lines 15/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54                                    128x         128x 128x 128x 128x 128x 128x 128x 128x 128x             1794x 1794x 1538x 1794x             128x          
/**
 * Logging utilities. Uses the log exported by dcmjs so all packages share
 * the same log hierarchy.
 */
import { log } from 'dcmjs';
 
export type Logger = {
  getLogger: (...categories: string[]) => Logger;
  debug: (...args: unknown[]) => void;
  info: (...args: unknown[]) => void;
  warn: (...args: unknown[]) => void;
  error: (...args: unknown[]) => void;
  setLevel: (level: string | number) => void;
};
 
/**
 * Root category for Cornerstone3D logs.
 */
export const cs3dLog = getRootLogger('cs3d');
 
/**
 * Category loggers that existing packages re-export.
 */
export const metadataLog = cs3dLog.getLogger('metadata') as Logger;
export const coreLog = cs3dLog.getLogger('core') as Logger;
export const toolsLog = cs3dLog.getLogger('tools') as Logger;
export const loaderLog = cs3dLog.getLogger('dicomImageLoader') as Logger;
export const aiLog = cs3dLog.getLogger('ai') as Logger;
export const examplesLog = cs3dLog.getLogger('examples') as Logger;
export const workerLog = cs3dLog.getLogger('worker') as Logger;
export const dicomConsistencyLog = log.getLogger('consistency.dicom') as Logger;
export const imageConsistencyLog = log.getLogger('consistency.image') as Logger;
 
/**
 * Gets a root logger for the given category name and wires up a hierarchical
 * `getLogger` method on it, similar to loglevel 2.x.
 */
export function getRootLogger(name: string): Logger {
  const logger = log.getLogger(name) as Logger;
  logger.getLogger = (...names: string[]): Logger =>
    getRootLogger(`${name}.${names.join('.')}`);
  return logger;
}
 
/**
 * Gets a nested logger from the root, preserving hierarchical `getLogger`.
 */
export function getLogger(...name: string[]): Logger {
  return getRootLogger(name.join('.'));
}
 
/** Re-export dcmjs log for consumers that need the root */
export { log };