Skip to main content

A Python logging library for unified logging across AWS Lambda, Django, and Google Cloud servers. Logs are asynchronously pushed to AWS CloudWatch.

Project description

Cove Unified Logs

Cove Unified Logs is a Python library for handling logs in various environments (Django, AWS Lambda, Google Cloud) and pushing them to AWS CloudWatch in an asynchronous way.

Author

SARVPRIYE SONI

Check out products from Cove Identity

Installation

Use the package manager pip to install Cove Unified Logs.

pip install cove_unified_logs

AWS Credentials Configuration

To interact with AWS services, Cove Unified Logs uses boto3, the AWS SDK for Python. You need to configure your AWS credentials for use with boto3. Here's how:

  1. Environment Variables: Set the AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_SESSION_TOKEN (optional for when you are using AWS STS temporary credentials) environment variables.
  2. Shared Credential File (~/.aws/credentials): Use an AWS credentials file to specify your credentials. The default location is ~/.aws/credentials.
  3. AWS Config File (~/.aws/config): Similar to the credentials file, you can also have a configuration file. The default location is ~/.aws/config. This file allows you to specify your region along with your credentials.
  4. IAM Role: If your application is running on an EC2 instance, you can assign an IAM role to the instance with the necessary permissions, and the boto3 client will automatically use the credentials from the IAM role.

For more information, check the official Boto3 documentation.

#Usage To use Cove Unified Logs in a Python application, first create an instance of the UnifiedLogger class:

from cove_unified_logs import UnifiedLogger

logger = UnifiedLogger('your-app-name', config='all')

You can then use this logger to log messages at different levels:

logger.debug('This is a debug message')
logger.info('This is an info message')
logger.warning('This is a warning message')
logger.error('This is an error message')
logger.critical('This is a critical message')

Each log message is automatically annotated with metadata including the app name, timestamp, and log level.

##Django Middleware To use Cove Unified Logs as middleware in a Django application, first add the middleware to your MIDDLEWARE setting:

# settings.py
MIDDLEWARE = [
    ...
    'cove_unified_logs.middleware.LoggingMiddleware',
    ...
]

Next, add the log level to your settings:

# settings.py
LOG_LEVEL = 'debug'  # or 'info', 'warning', 'error', 'critical'

Finally, in the module where you initialize your UnifiedLogger, set the log level from your settings:

# your file where UnifiedLogger is used
from django.conf import settings
from cove_unified_logs import UnifiedLogger

app_name = apps.get_app_config(__package__.split('.')[0]).verbose_name
logger = UnifiedLogger(app_name, config='all')
logger.set_level(settings.LOG_LEVEL)

Remember to replace 'your-app-name' with the name of your application, and to adjust the apps.get_app_config(package.split('.')[0]).verbose_name line as necessary for your project structure.

##Running the Log Consumer

  1. The LogConsumer class is responsible for consuming logs from a Redis queue and sending them to AWS CloudWatch. You can run it as a standalone service in your infrastructure.
from cove_unified_logs.log_consumer import LogConsumer
from cove_unified_logs.cloud_logger import CloudLogger
cloud_logger = CloudLogger(group_name='log-group', stream_name='log-stream', region_name='eu-west-1', flush_interval=10, batch_size=100)
consumer = LogConsumer(cloud_logger=cloud_logger)
consumer.run()
  1. Environment Variables: The script uses the following environment variables for Redis configuration:

REDIS_HOST: The hostname of your Redis server. REDIS_PORT: The port number on which your Redis server is running. REDIS_PASSWORD: The password for your Redis server. (Optional)

Make sure these environment variables are set correctly in your environment.

  1. Running the Script: To run the script, navigate to the root directory of this repository and use the following command:

Remember, the consumer is designed to be long-running and should be managed with a process supervisor to ensure it stays running.

Please make sure to adapt these instructions to your actual setup and include any additional steps or information that might be necessary.

##Contributing Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Confidentiality Notice

This software, including all the code, scripts, features, and documentation associated with it, is a proprietary product of Coveidentity Tech Private Limited and is confidential in nature. It is released under the MIT License and is free for use and modification in accordance with the terms of that license.

Any use of this software, or any of its parts, outside of the terms laid out in the MIT License, without express permission of Coveidentity Tech Private Limited, is strictly prohibited.

License

This software is licensed under the MIT License.

The MIT License is a permissive license that is short and to the point. It lets people do anything they want with your code as long as they provide attribution back to you and don’t hold you liable.

For the detailed terms and conditions, please refer to the LICENSE file in this repository.

Please note that this software is a proprietary product of Coveidentity Tech Private Limited and any use outside the terms laid out in the MIT License, without express permission of Coveidentity Tech Private Limited, is strictly prohibited.

Disclaimer

The software is provided "AS IS", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and non-infringement. In no event shall the authors or copyright holders be liable for any claim, damages, or other liability, whether in an action of

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

cove_unified_logs-0.2.2.tar.gz (11.0 kB view hashes)

Uploaded Source

Built Distribution

cove_unified_logs-0.2.2-py3-none-any.whl (11.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page