• English日本語한국어
  • Log inStart now

record_log_event (Python agent API)

Syntax

newrelic.agent.record_log_event(message, level=None, timestamp=None, attributes=None, application=None, priority=None)

Records a log event for use in logging in context.

Requirements

Python agent version 8.5.0 or higher.

Description

This records a log event that can be viewed and queried in the New Relic UI. If you want to use this outside of the context of a monitored transaction, use the application parameter.

Parameters

Parameter

Description

message

string

Required. The message defines the log message and must be a string.

level

string

Optional. Defines the logging level. Defaults to UNKNOWN.

timestamp

float

Optional. Defines the timestamp of the log message. Defaults to time.time().

application

object

Optional. If you want to record a log event outside of the context of a monitored transaction, use this to associate the call with a specific application object. An application object can be obtained using the newrelic.agent.application function.

priority

object

Optional. Sets the priority of the log event. See event_harvest_config.harvest_limits.log_event_data for additional information on how priority affects logging events.

Return values

None.

Examples

Record log event in background task

Here's an example of recording a log event associated with a background task:

@newrelic.agent.background_task()
def bg_task():
# do some type of work in this background task...
application = newrelic.agent.application()
newrelic.agent.record_log_event('My log message.', application)

Record log event in transaction

An example of recording a log event inside a transaction:

def fetch():
newrelic.agent.record_log_event('Fetching data.')
# do some type of work in this transaction...
Copyright © 2023 New Relic Inc.

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