Skip to content

Commit

Permalink
docs: improve logger methods jsdocs
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Apr 12, 2023
1 parent 36cb695 commit b7832a1
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,19 @@ export class Logger {
this.success = noop
this.warn = noop
this.error = noop
this.only = noop
}
}

public extend(domain: string): Logger {
return new Logger(`${this.name}:${domain}`)
}

/**
* Print a debug message.
* @example
* logger.debug('no duplicates found, creating a document...')
*/
public debug(message: string): void {
this.logEntry({
level: 'debug',
Expand All @@ -62,6 +68,11 @@ export class Logger {
})
}

/**
* Print an info message.
* @example
* logger.info('start parsing...')
*/
public info(message: string) {
this.logEntry({
level: 'info',
Expand All @@ -87,6 +98,11 @@ export class Logger {
}
}

/**
* Print a success message.
* @example
* logger.success('successfully created document')
*/
public success(message: string): void {
this.logEntry({
level: 'info',
Expand All @@ -99,6 +115,11 @@ export class Logger {
})
}

/**
* Print a warning.
* @example
* logger.warn('found legacy document format')
*/
public warn(message: string): void {
this.logEntry({
level: 'warn',
Expand All @@ -111,6 +132,11 @@ export class Logger {
})
}

/**
* Print an error message.
* @example
* logger.error('something went wrong')
*/
public error(message: string): void {
this.logEntry({
level: 'error',
Expand All @@ -127,8 +153,14 @@ export class Logger {
* Execute the given callback only when the logging is enabled.
* This is skipped in its entirety and has no runtime cost otherwise.
* This executes regardless of the log level.
* @example
* logger.only(() => {
* logger.info('additional info')
* })
*/
public only(callback: () => void): void {}
public only(callback: () => void): void {
callback()
}

private createEntry(level: LogLevel, message: string): LogEntry {
return {
Expand Down Expand Up @@ -235,6 +267,11 @@ function error(message: string): void {
console.error(message)
}

/**
* Return an environmental variable value.
* When run in the browser, returns the value of the global variable
* of the same name.
*/
function getVariable(variableName: string): string | undefined {
if (IS_NODE) {
return process.env[variableName]
Expand Down

0 comments on commit b7832a1

Please sign in to comment.