logdna / logdna-browser

A frontend browser logging and exception capturing library for LogDNA
MIT License
19 stars 14 forks source link

[v2.0.1] No longer passing lines to console #28

Closed prescience-data closed 2 years ago

prescience-data commented 2 years ago

Just trying out the new v2.0.1 and noticed that despite enabling

const options = {
   console: true
}

the logger is no longer sending lines to console output.

TerryMooreII commented 2 years ago

Thank you for this feedback. I will take a look and get this fixed.

TerryMooreII commented 2 years ago

@prescience-data I unable to reproduce this issue.

If I use either in the options

{  
  console: true, 
}

or

{
  console: {
    enable: true
    integrations: ['log', 'error']
  }
}

I get logs sent to both the browser console and to LogDNA.

Can you try retesting when you have a chance?

prescience-data commented 2 years ago
const options: LogDNAOptions = {
  hostname: env.APP_NAME,
  enableIpAddress: env.LOGDNA_ENABLE_IP_ADDRESS,
  debug: env.LOGDNA_DEBUG,
  enableStacktrace: true,
  console: true,
  globalErrorHandlers: true,
  tags: ["frontend"]
}

logdna.init(env.LOGDNA_INGESTION_KEY, { ...options })

Are any of these others potentially conflicting with the console property?

This is the only way I've been able to get it to output to console is to set console: false and use a custom hook:


const hooks: LogHooks = {
  beforeSend: [
    ({ message, level, lineContext }) => {
      if (env.LOGDNA_CONSOLE) {
        switch (level) {
          case "error":
          case "fatal":
            console.error(message, lineContext)
            break
          case "warn":
            console.warn(message, lineContext)
            break
          default:
            console.log(message, lineContext)
        }
      }

      return { message, level, lineContext }
    }
  ]
}

logdna.init(env.LOGDNA_INGESTION_KEY, { ...options, hooks })

For clarity, I am using

logdna.warn("foo") 

instead of the native

console.warn("foo")

When you tested above, I assume you were using the native console?

TerryMooreII commented 2 years ago

Oh, ok I know whats going on. I will have this fixed up shortly.

logdnabot commented 2 years ago

:tada: This issue has been resolved in version 2.0.3 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

prescience-data commented 2 years ago

@TerryMooreII

Bumped to latest, but still not seeing regular console output.

Can you see any issues with this workflow?

{ 
  "dependencies": { 
    "@logdna/browser": "^2.0.3"
  }
}

export const [DEBUG_LEVEL, INFO_LEVEL, WARN_LEVEL, ERROR_LEVEL] = [
  "debug",
  "info",
  "warn",
  "error"
] as const

export const logLevels = [
  DEBUG_LEVEL,
  INFO_LEVEL,
  WARN_LEVEL,
  ERROR_LEVEL
] as const

export type LogLevel = typeof logLevels[number]

const options: LogDNAOptions = toLogDNAOptions({
  hostname: env.APP_NAME,
  enableIpAddress: env.LOGDNA_ENABLE_IP_ADDRESS,
  enableStacktrace: true,
  console: true,
  globalErrorHandlers: true
})

logdna.init(env.LOGDNA_INGESTION_KEY, options)

export const debug = (message: Serializable, context?: LogContext): void =>
  logdna.log(serialize(message), parse(context), DEBUG_LEVEL)

export const warn = (message: Serializable, context?: LogContext): void =>
  logdna.log(serialize(message), parse(context), WARN_LEVEL)