• EnglishEspañol日本語한국어Português
  • EntrarComeçar agora

Esta tradução de máquina é fornecida para sua comodidade.

Caso haja alguma divergência entre a versão em inglês e a traduzida, a versão em inglês prevalece. Acesse esta página para mais informações.

Criar um problema

wrapLogger

Sintaxe

newrelic.wrapLogger(parent: Object, functionName: string, options?: Object<{ customAttributes?: Object, level?: 'debug|error|info|trace|warn'}>)

Captura automaticamente os dados que passam pelos métodos de registro do navegador existentes como evento de log.

Requisitos

  • Browser Pro ou agente Pro+SPA (v1.261.0 ou superior)

  • Se você estiver usando o npm para instalar o navegador do agente e usando uma implementação não padrão, você deverá ativar o recurso logging ao instanciar a classe BrowserAgent . Por exemplo, adicione o seguinte na matrizfeatures :

    import { Logging } from '@newrelic/browser-agent/features/logging'
    const options = {
    info: { ... },
    loader_config: { ... },
    init: { ... },
    features: [
    Logging
    ]
    }

Para obter mais informações, consulte a documentação de instalação do browser npm.

Descrição

Depois de fornecer a esse método um contêiner pai válido e um nome de função filho, o navegador do agente registrará um novo evento de log sempre que a função encapsulada for chamada. O primeiro argumento é passado para a função invocada como a mensagem do log. Consulte a interface de log para obter mais informações sobre evento de log.

A configuração opcional pode ser transmitida junto com esses logs capturados com o argumento options . Qualquer atributo personalizado fornecido à chamada de API no argumento options (options.customAttributes) será anexado como atributo de nível superior em cada evento de log criado por este wrapper. Você pode controlar o level do log capturado fornecendo um level ao argumento options (options.level), cujo padrão é info. Observe que, uma vez encapsulado com sucesso, a detecção de log da função não pode ser alterada.

Parâmetro

Parâmetro

Descrição

parent

Objeto

Obrigatório. Um objeto que contém a função de destino a ser encapsulada.

functionName

corda

Obrigatório. O nome da função de destino a ser encapsulada. Esta função deve existir no objeto parent e corresponder ao tipo de "função".

options

Objeto

Opcional. Um objeto utilizado para fornecer configuração opcional para cada log capturado pelo wrapper. options.customAttributes é um objeto de pares key:val que atribui uma propriedade e um valor de nível superior ao log criado para cada atributo fornecido. A enumeração options.level atribui um nível de log ao evento de log criado. O level deve ser um dos seguintes: debug | error | info | trace | warn. O nível de log será padronizado como info se não for fornecido.

Exemplos

Capturando itens de log do(s) método(s) nativo(s) do console

newrelic.wrapLogger(console, 'info')
// from this point forward, every time `console.info` is invoked, it will save a log event with:
// a message of --> <the first argument passed to console.info>
// a level of --> 'info'

Capturando itens log de um agente customizado

const myLoggers = {
logger: function(){...}
}
newrelic.wrapLogger(myLoggers, 'logger')
// from this point forward, every time `myLoggers.logger` is invoked, it will save a log event with:
// a message of --> <the first argument passed to myLoggers.logger>
// a level of --> 'info'

Capturando itens de log com um nível especificado

const myLoggers = {
logger: function(){...}
}
newrelic.wrapLogger(myLoggers, 'logger', {level: 'debug'})
// from this point forward, every time `myLoggers.logger` is invoked, it will save a log event with:
// a message of --> <the first argument passed to myLoggers.logger>
// a level of --> 'debug'

Capturando um item log com atributo personalizado

const myLoggers = {
logger: function(){...}
}
newrelic.wrapLogger(myLoggers, 'logger', {customAttributes: {myFavoriteApp: true}})
// from this point forward, every time `myLoggers.logger` is invoked, it will save a log event with:
// a message of --> <the first argument passed to myLoggers.logger>
// a level of --> 'info'
// an attribute of --> 'myFavoriteApp: true'

Envolver vários agentes

const myLoggers = {
myInfoLogger: function(){...},
myDebugLogger: function(){...}
}
newrelic.wrapLogger(myLoggers, 'myInfoLogger', {level: 'info'})
newrelic.wrapLogger(myLoggers, 'myDebugLogger', {level: 'debug'})
// from this point forward, every time `myLoggers.myInfoLogger` is invoked, it will save a log event with:
// a message of --> <the first argument passed to myLoggers.myInfoLogger>
// a level of --> 'info'
// every time `myLoggers.myDebugLogger` is invoked, it will save a log event with:
// a message of --> <the first argument passed to myLoggers.myDebugLogger>
// a level of --> 'debug'
Copyright © 2024 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.