• EnglishEspañol日本語한국어Português
  • ログイン今すぐ開始

この機械翻訳は、参考として提供されています。

英語版と翻訳版に矛盾がある場合は、英語版が優先されます。詳細については、このページを参照してください。

問題を作成する

ラップロガー

構文

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

既存のbrowserログ記録方法を通過するデータをログイベントとして自動的にキャプチャします。

要件

  • browser Pro、または Pro+SPA エージェント (v1.261.0 以上)

  • npm を使用して Browseragent をインストールし、非標準の実装を使用する場合は、 BrowserAgentクラスをインスタンス化するときにlogging機能を有効にする必要があります。 たとえば、 features配列に次のコードを追加します。

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

詳細については、 npm ブラウザのインストールに関するドキュメントを参照してください。

説明

このメソッドに有効な親 コンテナと子関数名を指定すると、ラップされた関数が呼び出されるたびに、Browseragent は新しいログイベントを記録します。 最初の引数は、呼び出された関数にログのメッセージとして渡されます。 ログイベントの詳細については、ログUI参照してください。

オプションの設定は、 options引数を使用して、これらのキャプチャされたログとともに渡すことができます。 options 引数 (options.customAttributes) でAPIコールに提供されるカスタム アトリビュートは、このラッパーによって作成されるすべてのログイベントに最上位の属性として追加されます。 キャプチャされたログのlevelを制御するには、 options引数 ( options.level ) にlevelを指定します。デフォルトではinfoになります。 正常にラップされると、関数のログ検出は変更できないことに注意してください。

パラメーター

パラメータ

説明

parent

オブジェクト

必須。 ラップするターゲット関数を含むオブジェクト。

functionName

ストリング

必須。 ラップするターゲット関数の名前。 この関数はparentオブジェクト内に存在し、「function」のタイプと一致する必要があります。

options

オブジェクト

オプション。 ラッパーによってキャプチャされたすべてのログにオプションの設定を提供するために使用されるオブジェクト。 options.customAttributesは、指定された属性ごとに作成されたログに最上位のプロパティと値を割り当てるキー:値のペアのオブジェクトです。 列挙型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株式会社。

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