Skip to content

Commit

Permalink
[FEAT] Custom Timestamp function (#3)
Browse files Browse the repository at this point in the history
feat: custom timestamp function
  • Loading branch information
henilmalaviya authored Oct 19, 2024
1 parent b797aec commit 3e5176b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ export interface LoggerOptions {
mode?: "combined" | "live";
/**
* Whether to print timestamp at the beginning of each line
* could be a function that returns a string
*
* @default false
*/
withTimestamp?: boolean;
withTimestamp?: boolean | (() => string);
/**
* Whether to print banner at the beginning of each line
*
Expand All @@ -52,10 +53,10 @@ export const logger = (options: LoggerOptions = {}) => {

if (!enabled) return app;

const getTimestamp = () => {
const now = new Date();
return now.toLocaleString();
};
const getTimestamp =
typeof options.withTimestamp === "function"
? options.withTimestamp
: () => new Date().toLocaleString();

app
.onStart(ctx => {
Expand Down

0 comments on commit 3e5176b

Please sign in to comment.