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, dictionary | Required. The To report these attributes, enable context data forwarding and optionally configure include and exclude rules. |
string | Optional. Defines the logging level. Defaults to |
float | Optional. Defines the timestamp of the log message. Defaults to |
dictionary | Optional. Items included in this dictionary will be considered context data attributes under the prefix To report these attributes, enable context data forwarding and optionally configure include and exclude rules. |
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 |
중요
This setting is disabled when high security mode is enabled.
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...
Record log event with context data attributes
Here's an example of recording a log event using message attributes and context attributes:
def fetch(product_id): newrelic.agent.record_log_event({"message": "Fetching data", "product_id": product_id}, attributes={"thread_id": threading.get_ident()}) # do some type of work in this transaction...