Push logs into New Relic using standard python logger asynchronously.
Project description
New Relic APM Logger
This library enables the standard python logger to send its logs to New Relic using an async strategy. Note: These logs are linked to the application only in the context of a web transaction.
Configuration
Configure the APM agent according to the documentation. A newrelic.ini
should be generated.
By default (unless NEW_RELIC_LOGGER_AUTOIMPORT_DISABLE is True), to enable the python logging module, include this line in your file.
import newrelic_logger
if auto import is disabled, it must be instantiated in the code
from newrelic_logger import NewRelicLogger
NewRelicLogger(...)
NewRelicLogger Arguments
NewRelicLogger constructor receives the following optional arguments:
Name | Type | Description |
---|---|---|
app_id | int | The app id for the newrelic APM |
app_name | str | The app name for the newrelic APM |
license_key | str | The license_key for comunicating with the new relic api |
region | str | The region for newrelic, either "US" or "EU" |
log_level | ENUM | The numeric level of the logging event (one of DEBUG, INFO etc.) |
Environment Variables
Optionally, some arguments can be configured by environment variables. These are:
Name | Description |
---|---|
NEW_RELIC_LOGGER_AUTOIMPORT_DISABLE | Disable the auto import functionality |
NEW_RELIC_APP_ID | The app id for the newrelic APM |
NEW_RELIC_APP_NAME | he app name for the newrelic APM |
NEW_RELIC_LICENSE_KEY | The license_key for comunicating with the new relic api |
NEW_RELIC_REGION | The region for newrelic, either "US" or "EU" |
Usage
Just use the normal python logger, for example, to send an info message:
import logging
logging.info("This is an info message")
Note: It could be useful to replace the python print function inside your main application to use the logger.info implementation. The following code shows how its done.
import logging
logger = logging.getLogger()
print = logger.info
print("message") # same as logger.info("message")
Running the program
Run the application using the new relic agent either by using the admin script integration, or the manual integration, as mentioned in the documentation. For example, for the admin script:
NEW_RELIC_CONFIG_FILE=newrelic.ini newrelic-admin run-program YOUR_COMMAND_OPTIONS
and for the manual integration:
import newrelic.agent
newrelic.agent.initialize('/some/path/newrelic.ini')
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file new-relic-logger-for-python-0.2.0.tar.gz
.
File metadata
- Download URL: new-relic-logger-for-python-0.2.0.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.5 CPython/3.9.1 Darwin/20.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f947620b2c1e0f081bab99cb6372cdc52a3c68a196a248951b172c330b35c5c6 |
|
MD5 | 8b9a77cb636de08066dc0b328331c138 |
|
BLAKE2b-256 | 348ecb4e2144782766f45929abadeaa97f4ea5e07847eee4cf4aef595d0084fa |
File details
Details for the file new_relic_logger_for_python-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: new_relic_logger_for_python-0.2.0-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.5 CPython/3.9.1 Darwin/20.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61b1495cb17f92bd6f3e54f7be7b4149cc2e048e5cb8f95c7d65993d841a23ff |
|
MD5 | 1f39aa7c4cd29ae61c98c3052c5b27b6 |
|
BLAKE2b-256 | a021660fbd908b8583d88a695eb92beb1fb9628eb3e85ec0c2ab8bcd485c778b |