Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
chasers committed Mar 12, 2021
2 parents e559b12 + 94e296a commit 169251c
Show file tree
Hide file tree
Showing 4 changed files with 1,697 additions and 1,545 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@
"@types/pumpify": "^1.4.1",
"@types/split2": "^2.1.6",
"@types/through2": "^2.0.36",
"@typescript-eslint/eslint-plugin": "^3.4.0",
"@typescript-eslint/parser": "^3.4.0",
"@typescript-eslint/eslint-plugin": "^4.16.0",
"@typescript-eslint/parser": "^4.16.0",
"eslint": "^7.3.1",
"eslint-config-airbnb-base": "^14.2.0",
"eslint-config-standard": "^14.1.1",
"eslint-config-standard": "^16.0.0",
"eslint-plugin-import": "^2.22.0",
"jest": "^26.1.0",
"jest-mock-process": "^1.4.0",
"pino-multi-stream": "^5.0.0",
"sinon": "^9.0.1",
"typescript": "^3.9.5"
"typescript": "^4.2.0"
},
"dependencies": {
"axios": "^0.21.1",
Expand All @@ -81,4 +81,4 @@
"doc": "docs",
"test": "test"
}
}
}
39 changes: 28 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
import createHttpWriteStream from "./httpStream"
import createConsoleWriteStream from "./consoleStream"
import {pinoBrowserLogEventI, formatPinoBrowserLogEvent, addLogflareTransformDirectives} from "./utils"
import {LogflareHttpClient, LogflareUserOptionsI} from "logflare-transport-core"
import {
LogEvent,
formatPinoBrowserLogEvent,
addLogflareTransformDirectives,
} from "./utils"
import {
LogflareHttpClient,
LogflareUserOptionsI,
} from "logflare-transport-core"

const isBrowser = typeof window !== 'undefined'
&& typeof window.document !== 'undefined'
const isBrowser =
typeof window !== "undefined" && typeof window.document !== "undefined"

const isNode = typeof process !== 'undefined'
&& process.versions != null
&& process.versions.node != null
const isNode =
typeof process !== "undefined" &&
process.versions != null &&
process.versions.node != null

const createPinoBrowserSend = (options: LogflareUserOptionsI) => {
const client = new LogflareHttpClient({...options, fromBrowser: true})
const client = new LogflareHttpClient({ ...options, fromBrowser: true })

return (level: number, logEvent: pinoBrowserLogEventI) => {
return (level: string, logEvent: LogEvent) => {
const logflareLogEvent = formatPinoBrowserLogEvent(logEvent)
const maybeWithTransforms = addLogflareTransformDirectives(logflareLogEvent, options)
const maybeWithTransforms = addLogflareTransformDirectives(
logflareLogEvent,
options
)
client.postLogEvents([maybeWithTransforms])
}
}
Expand All @@ -29,4 +40,10 @@ const logflarePinoVercel = (options: LogflareUserOptionsI) => {

const createWriteStream = createHttpWriteStream

export {createWriteStream, logflarePinoVercel, createPinoBrowserSend, createConsoleWriteStream, createHttpWriteStream}
export {
createWriteStream,
logflarePinoVercel,
createPinoBrowserSend,
createConsoleWriteStream,
createHttpWriteStream,
}
24 changes: 18 additions & 6 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,26 @@ function levelToStatus(level: number) {
return "info"
}

interface pinoBrowserLogEventI {
type Level = "fatal" | "error" | "warn" | "info" | "debug" | "trace"
type SerializerFn = (value: any) => any

interface Bindings {
level?: Level | string
serializers?: { [key: string]: SerializerFn }
[key: string]: any
}

interface LogEvent {
ts: number
messages: string[]
bindings: object[]
level: { value: number; label: string }
messages: any[]
bindings: Bindings[]
level: {
label: string
value: number
}
}

const formatPinoBrowserLogEvent = (logEvent: pinoBrowserLogEventI) => {
const formatPinoBrowserLogEvent = (logEvent: LogEvent) => {
const {
ts,
messages,
Expand Down Expand Up @@ -107,6 +119,6 @@ function toLogEntry(item: Record<string, any>): Record<string, any> {
export {
toLogEntry,
formatPinoBrowserLogEvent,
pinoBrowserLogEventI,
LogEvent,
addLogflareTransformDirectives,
}
Loading

0 comments on commit 169251c

Please sign in to comment.