Skip to content

Commit

Permalink
✨ Feature: add debug logger type
Browse files Browse the repository at this point in the history
  • Loading branch information
Molunerfinn committed Aug 26, 2022
1 parent 6355e1b commit 4342268
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/lib/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
ILogger,
IPicGo
} from '../types'
import { forceNumber } from '../utils/common'
import { forceNumber, isDev } from '../utils/common'

export class Logger implements ILogger {
private readonly level = {
Expand Down Expand Up @@ -130,6 +130,12 @@ export class Logger implements ILogger {
warn (...msg: ILogArgvType[]): void {
return this.handleLog(ILogType.warn, ...msg)
}

debug (...msg: ILogArgvType[]): void {
if (isDev()) {
this.handleLog(ILogType.info, ...msg)
}
}
}

export default Logger
8 changes: 8 additions & 0 deletions src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,11 @@ export function safeParse<T> (str: string): T | string {
export const forceNumber = (num: string | number = 0): number => {
return isNaN(Number(num)) ? 0 : Number(num)
}

export const isDev = (): boolean => {
return process.env.NODE_ENV === 'development'
}

export const isProd = (): boolean => {
return process.env.NODE_ENV === 'production'
}

0 comments on commit 4342268

Please sign in to comment.