-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add optional logging; update example app (#44)
* Add optional logging; update example app * linter fixes
- Loading branch information
Showing
9 changed files
with
117 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)
|
||
info(...data: any[]): void; | ||
Check warning on line 5 in lib/logger.ts GitHub Actions / build (20.x)
|
||
warn(...data: any[]): void; | ||
Check warning on line 6 in lib/logger.ts GitHub Actions / build (20.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)
|
||
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)
|
||
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)
|
||
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] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters