-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import _ from 'lodash' | ||
|
||
export default interface Logger { | ||
error(...data: any[]): void; | ||
Check warning on line 4 in lib/logger.ts GitHub Actions / build (20.x)
Check warning on line 4 in lib/logger.ts GitHub Actions / build (21.x)
|
||
info(...data: any[]): void; | ||
Check warning on line 5 in lib/logger.ts GitHub Actions / build (20.x)
Check warning on line 5 in lib/logger.ts GitHub Actions / build (21.x)
|
||
warn(...data: any[]): void; | ||
Check warning on line 6 in lib/logger.ts GitHub Actions / build (20.x)
Check warning on line 6 in lib/logger.ts GitHub Actions / build (21.x)
|
||
} | ||
|
||
export enum LogLevel { | ||
INFO = 1, | ||
WARN = 2, | ||
ERROR = 3 | ||
} | ||
|
||
export class TastytradeLogger implements Logger { | ||
public logLevel: LogLevel | ||
private logger: Logger | null = null | ||
|
||
constructor(logger?: Logger, logLevel?: LogLevel) { | ||
this.logger = logger ?? null | ||
this.logLevel = logLevel ?? LogLevel.ERROR | ||
} | ||
|
||
error(...data: any[]): void { | ||
Check warning on line 24 in lib/logger.ts GitHub Actions / build (20.x)
Check warning on line 24 in lib/logger.ts GitHub Actions / build (21.x)
|
||
if (this.shouldLog(LogLevel.ERROR)) { | ||
this.logger!.error(...data) | ||
} | ||
} | ||
|
||
info(...data: any[]): void { | ||
Check warning on line 30 in lib/logger.ts GitHub Actions / build (20.x)
Check warning on line 30 in lib/logger.ts GitHub Actions / build (21.x)
|
||
if (this.shouldLog(LogLevel.INFO)) { | ||
this.logger!.info(...data) | ||
} | ||
} | ||
|
||
warn(...data: any[]): void { | ||
Check warning on line 36 in lib/logger.ts GitHub Actions / build (20.x)
Check warning on line 36 in lib/logger.ts GitHub Actions / build (21.x)
|
||
if (this.shouldLog(LogLevel.WARN)) { | ||
this.logger!.warn(...data) | ||
} | ||
} | ||
|
||
private shouldLog(level: LogLevel) { | ||
if (_.isNil(this.logger)) { | ||
return false | ||
} | ||
return LogLevel[level] >= LogLevel[this.logLevel] | ||
} | ||
} |