tsflag (similar to timestampWithFlag)
The tsflag function combines a timestamp and a debug level flag into a single formatted string. It calls ts with flag internally, producing output like [2026-03-01 - 14:30:00] [INFO] message.
Signature
function tsflag(level: DebugLevel,date?: boolean,...args: any[],): string
Parameters
level: ADebugLevelstring —"debug","info","warn", or"error".date: Whether to include the date portion. Defaults totrue....args: Additional values to append after the timestamp and flag.
Return Value
Returns a string with both timestamp and colored level flag.
Usage
import { tsflag } from "ts-better-console";
// Full timestamp with date + info flag
console.log(tsflag("info", true, "Server started"));
// => [2026-03-01 - 14:30:00] [INFO] Server started
// Time only + error flag
console.log(tsflag("error", false, "Connection lost"));
// => [14:30:00] [ERROR] Connection lost
// Default date + warn flag
console.log(tsflag("warn", true, "High memory"));
// => [2026-03-01 - 14:30:00] [WARN] High memory
Want to support this project?
If you find ts-better-console useful and want to support its development, consider starring the GitHub repository or buying me a coffee! Your support helps me dedicate more time to improving the library and adding new features.
Want to contribute to this project?
Contributions are welcome! If you're interested in improving the library, fixing bugs, or adding new features, feel free to check out the GitHub repository and submit a pull request. Whether you're a seasoned developer or new to open source, your contributions can make a difference!