Skip to content

Commit

Permalink
feat(minor): Create options types
Browse files Browse the repository at this point in the history
  • Loading branch information
Dam998 committed Feb 28, 2024
1 parent 3f99f75 commit ad257c5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/LogFlake.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IBodyLog, IBodyPerformance, IInitOptions, LogLevels, Queue } from "./types"
import { IBodyLog, IBodyPerformance, IInitOptions, SendExceptionOptionsType, SendLogOptionsType, LogLevels, Queue } from "./types"
import { getCurrentDateTime, wait } from "./utils"
import { Buffer } from "buffer"
import { compress } from "snappyjs"
Expand Down Expand Up @@ -69,11 +69,11 @@ export class LogFlake {
})
}

public sendLog(content: string, options?: Partial<Omit<IBodyLog, "content">>) {
public sendLog(content: string, options?: SendLogOptionsType) {
return this.log(content, options)
}

public sendException<E extends Error>(exception: E, options?: Omit<IBodyLog, "content" | "level">) {
public sendException<E extends Error>(exception: E, options?: SendExceptionOptionsType) {
const { stack, message, ...exceptionParams } = exception

return this.log(stack ?? message ?? "Unknown error", {
Expand Down
6 changes: 3 additions & 3 deletions lib/init.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { LogFlake } from "./LogFlake"
import { IBodyLog, IInitOptions } from "./types"
import { IInitOptions, SendExceptionOptionsType, SendLogOptionsType } from "./types"

let Logger: LogFlake | null = null

export const getLogger = () => {
return Logger
}

export const sendLog = (content: string, options?: Partial<Omit<IBodyLog, "content">>) => getLogger()?.sendLog(content, options)
export const sendException = (error: Error, options?: Omit<IBodyLog, "content" | "level">) => getLogger()?.sendException(error, options)
export const sendLog = (content: string, options?: SendLogOptionsType) => getLogger()?.sendLog(content, options)
export const sendException = (error: Error, options?: SendExceptionOptionsType) => getLogger()?.sendException(error, options)
export const measurePerformance = (label: string) => getLogger()?.measurePerformance(label)
export const sendPerformance = (label: string, duration: number) => getLogger()?.sendPerformance(label, duration)

Expand Down
3 changes: 3 additions & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ export interface IInitOptions {
enableCompression?: boolean
correlation?: string
}

export type SendLogOptionsType = Partial<Omit<IBodyLog, "content">>
export type SendExceptionOptionsType = Omit<IBodyLog, "content" | "level">

0 comments on commit ad257c5

Please sign in to comment.