Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Commit

Permalink
feat(logger): banner method
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd committed Oct 23, 2023
1 parent a5972f1 commit 3e3af6d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/logger/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,23 @@ export const createLogger = (domain: string, devMode = DEV_MODE): AlwatrLogger =
/**
* Required logger object, accident, error always reported even when the devMode is false.
*/
const requiredItems = {
const requiredItems: AlwatrLogger = {
devMode,
domain,

banner: NODE_MODE
? console.log.bind(console, `\x1b[1;37;45m\n\n %s${_style.reset}`)
: console.log.bind(console, '%c%s',
'font-size: 2rem; background-color: #5858e8; color: #fff; padding: 1rem 4rem; border-radius: 0.5rem;'),

accident: NODE_MODE
? console.warn.bind(console, `${styleScope}⚠️\n%s\x1b[33m.%s() Accident \`%s\` %s!${_style.reset}`, domain)
: console.warn.bind(console, '%c%s%c.%s() Accident `%s` %s!', styleScope, domain, _style.reset),

error: NODE_MODE
? console.error.bind(console, `${styleScope}❌\n%s\x1b[31m.%s() Error \`%s\`${_style.reset}\n`, domain)
: console.error.bind(console, '%c%s%c.%s() Error `%s`\n', styleScope, domain, _style.reset),
} as const;
};

if (!devMode) {
return requiredItems;
Expand Down
11 changes: 11 additions & 0 deletions packages/logger/src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,15 @@ export interface AlwatrLogger {
* ```
*/
timeEnd?(label: string): void;

/**
* log big banner
*
* Example:
*
* ```ts
* logger.banner('Alwatr PWA v2');
* ```
*/
banner?(message: string): void;
}

0 comments on commit 3e3af6d

Please sign in to comment.