@bracketed/logger
Version:
An alternative to your run-of-the-mill node console logging functions!
90 lines (87 loc) • 2.37 kB
TypeScript
import { LoggerStyleResolvable } from '../Style/Resolvable.js';
import { LoggerStyle } from '../Style/Style.js';
import { Timestamp } from '../Timestamper/Timestamp.js';
import '../Colouring/index.js';
import '../Style/Options.js';
import '../Style/Background.js';
import '../Style/Effect.js';
import '../Style/Text.js';
/**
* Logger utility that formats a timestamp.
* @since 1.0.0
*/
declare class LoggerTimestamp {
/**
* The timestamp used to format the current date.
* @since 1.0.0
*/
timestamp: Timestamp;
/**
* Whether or not the logger will show a timestamp in UTC.
* @since 1.0.0
*/
utc: boolean;
/**
* The logger style to apply the color to the timestamp.
* @since 1.0.0
*/
color: LoggerStyle | null;
/**
* The final formatter.
* @since 1.0.0
*/
formatter: LoggerTimestampFormatter;
constructor(options?: LoggerTimestampOptions);
/**
* Formats the current time.
* @since 1.0.0
*/
run(): string;
}
/**
* The options for {@link LoggerTimestamp}.
* @since 1.0.0
*/
interface LoggerTimestampOptions {
/**
* The {@link Timestamp} pattern.
* @since 1.0.0
* @default 'YYYY-MM-DD HH:mm:ss'
* @example
* ```typescript
* 'YYYY-MM-DD HH:mm:ss'
* // 2020-12-23 22:01:10
* ```
*/
pattern?: string;
/**
* Whether or not the date should be UTC.
* @since 1.0.0
* @default false
*/
utc?: boolean;
/**
* The color to use.
* @since 1.0.0
* @default colorette.reset
*/
color?: LoggerStyleResolvable | null;
/**
* The formatter. See {@link LoggerTimestampFormatter} for more information.
* @since 1.0.0
* @default (value) => `${value} - `
*/
formatter?: LoggerTimestampFormatter;
}
/**
* The formatter used for {@link LoggerTimestampOptions}. This will be run **after** applying the color to the formatter.
* @since 1.0.0
*/
interface LoggerTimestampFormatter {
/**
* @param timestamp The output of {@link LoggerStyle.run} on {@link Timestamp.display}/{@link Timestamp.displayUTC}.
* @since 1.0.0
*/
(timestamp: string): string;
}
export { LoggerTimestamp, type LoggerTimestampFormatter, type LoggerTimestampOptions };