• EnglishEspañol日本語한국어Português
  • 로그인지금 시작하기

사용자의 편의를 위해 제공되는 기계 번역입니다.

영문본과 번역본이 일치하지 않는 경우 영문본이 우선합니다. 보다 자세한 내용은 이 페이지를 방문하시기 바랍니다.

문제 신고

랩로거

통사론

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

기존 브라우저 로깅 방식을 통해 전달되는 데이터를 로그 이벤트로 자동 캡처합니다.

요구 사항

  • 브라우저 Pro 또는 Pro+SPA 에이전트(v1.261.0 이상)

  • npm을 사용하여 브라우저 에이전트를 설치하고 비표준 구현을 사용하는 경우 BrowserAgent 클래스를 인스턴스화할 때 logging 기능을 활성화해야 합니다. 예를 들어, features 다시에 다음을 추가하세요:

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

자세한 내용은 npm 브라우저 설치 설명서를 참조하세요.

설명

이 메서드에 유효한 상위 컨테이너 및 하위 함수 이름을 제공하면 브라우저 에이전트는 래핑된 함수가 호출될 때마다 새 로그 이벤트를 기록합니다. 첫 번째 인수는 호출된 함수에 로그 메시지로 전달됩니다. 로그 이벤트에 대한 자세한 내용은 로그 UI를 참조하세요.

선택적 설정은 options 인수를 사용하여 캡처된 로그와 함께 전달될 수 있습니다. options 인수(options.customAttributes)에서 API 호출에 제공된 모든 사용자 정의 속성은 이 래퍼에서 생성된 모든 로그 이벤트에 최상위 속성으로 추가됩니다. options 인수(options.level)에 level 를 제공하여 캡처된 로그의 level 를 제어할 수 있습니다. 기본값은 info 입니다. 성공적으로 래핑되면 함수의 로깅 감지를 변경할 수 없습니다.

매개변수

매개변수

설명

parent

물체

필수의. 래핑할 완충, 목표 함수가 포함된 객체입니다.

functionName

필수의. 래핑할 목표 함수의 이름입니다. 이 함수는 parent 객체에 존재해야 하며 '함수' 유형과 일치해야 합니다.

options

물체

선택 과목. 래퍼에 의해 캡처된 모든 로그인에 대해 선택적 설정을 제공하는 데 사용되는 개체입니다. options.customAttributes 는 제공된 각 속성에 대해 생성된 로그에 최상위 속성과 값을 할당하는 key:val 쌍의 객체입니다. 열거형 options.level 은 생성된 로그인 이벤트에 로그인 레벨을 할당합니다. level 는 다음 중 하나여야 합니다: debug | error | info | trace | warn. 제공되지 않은 경우 로그 레벨의 기본값은 info 입니다.

기본 콘솔 방법에서 로그 항목 캡처

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'

커스텀 로거에서 로그 항목 캡처

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'

지정된 수준의 로그 항목 캡처

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'

사용자 정의 속성을 사용하여 로그 항목 캡처

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'

여러 로거 래핑

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.