Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

new-relic-logger-for-python

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

new-relic-logger-for-python

Push logs into New Relic using standard python logger asynchronously.

  • 0.2.0
  • PyPI
  • Socket score

Maintainers
1

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:

NameTypeDescription
app_idintThe app id for the newrelic APM
app_namestrThe app name for the newrelic APM
license_keystrThe license_key for comunicating with the new relic api
regionstrThe region for newrelic, either "US" or "EU"
log_levelENUMThe numeric level of the logging event (one of DEBUG, INFO etc.)

Environment Variables

Optionally, some arguments can be configured by environment variables. These are:

NameDescription
NEW_RELIC_LOGGER_AUTOIMPORT_DISABLEDisable the auto import functionality
NEW_RELIC_APP_IDThe app id for the newrelic APM
NEW_RELIC_APP_NAMEhe app name for the newrelic APM
NEW_RELIC_LICENSE_KEYThe license_key for comunicating with the new relic api
NEW_RELIC_REGIONThe 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')

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc