Skip to content

Commit

Permalink
feat: logger
Browse files Browse the repository at this point in the history
  • Loading branch information
vobu committed Nov 30, 2021
1 parent fd47ba5 commit 7547b6a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
56 changes: 56 additions & 0 deletions src/lib/Logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { chalk as console } from "./coloredConsole"
import { wdi5LogLevel } from "./types"

export class Logger {
private static instance: Logger | null = null
private constructor() {}

private prefix = "[wdi5]"
private logLevel: wdi5LogLevel = "error"

static getInstance(): Logger {
if (Logger.instance === null) {
Logger.instance = new Logger()
}
return Logger.instance
}

getLogLevel(): wdi5LogLevel {
return this.logLevel
}

setLogLevel(level: wdi5LogLevel): void {
this.logLevel = level
}

error(msg: string, ..._: string[]) {
if (this.logLevel !== "silent") {
console.red(this.prefix, msg, ..._)
}
}
warn(msg: string, ..._: string[]) {
if (this.logLevel !== "silent") {
console.yellow(this.prefix, msg, ..._)
}
}
info(msg: string, ..._: string[]) {
if (this.logLevel === "verbose") {
console.blue(this.prefix, msg, ..._)
}
}
success(msg: string, ..._: string[]) {
if (this.logLevel === "verbose") {
console.green(this.prefix, msg, ..._)
}
}
log(msg: string, ..._: string[]) {
if (this.logLevel !== "silent") {
console.default(this.prefix, msg, ..._)
}
}
debug(msg: string, ..._: string[]) {
if (this.logLevel === "verbose") {
console.magenta(this.prefix, msg, ..._)
}
}
}
4 changes: 3 additions & 1 deletion src/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Path } from "typescript"

export type wdi5LogLevel = "silent" | "error" | "verbose"

export interface wdi5Config extends WebdriverIO.Config {
wdi5: {
logLevel?: "silent" | "error" | "verbose"
logLevel?: wdi5LogLevel
url: string
screenshotPath?: Path
skipInjectUI5OnStart?: boolean
Expand Down

0 comments on commit 7547b6a

Please sign in to comment.