-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
38d30cf
commit 1479182
Showing
5 changed files
with
166 additions
and
89 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './client'; | ||
export * from './lib/wait'; | ||
export * from './lib/error'; | ||
export { verboseLog } from './lib/env'; |
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,37 @@ | ||
import * as v from 'valibot'; | ||
import packageJson from '../../package.json'; | ||
|
||
export const env = { | ||
verboseLevel: v.parse( | ||
v.pipe( | ||
v.optional(v.string(), '0'), | ||
v.regex(/[0-9]/, 'must contain a number.'), | ||
v.transform((strNum) => Number(strNum)) | ||
), | ||
process?.env?.VERBOSE | ||
), | ||
} as const; | ||
|
||
type Type = 'debug' | 'info' | 'warn'; | ||
type verboseLogParameters = { | ||
message: string; | ||
body: unknown; | ||
type: Type; | ||
path: string; | ||
level: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9; | ||
}; | ||
export const verboseLog = ({ message, body, type, path, level }: verboseLogParameters) => { | ||
if (env.verboseLevel >= level) { | ||
console[type]( | ||
JSON.stringify({ | ||
package: packageJson.name, | ||
version: packageJson.version, | ||
timestamp: new Date(), | ||
type: type.toUpperCase(), | ||
message, | ||
body, | ||
path, | ||
}) | ||
); | ||
} | ||
}; |
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