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 |
---|---|
string | Required. The |
string | Optional. Defines the logging level. Defaults to |
float | Optional. Defines the timestamp of the log message. Defaults to |
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 |
object | Optional. Sets the priority of the log event. See |
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...