Package: cove-unified-logs
Cove Unified LogsCove 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.AuthorSARVPRIYE SONIGithub:@Cove-IdentityEmail:sarvpriye.soni@coveidentity.comWebsite:Cove IdentityCheck out products from Cove IdentityCove Identity:Cove IdentityCove Drive:Cove DriveInstallationUse the package managerpipto install Cove Unified Logs.pipinstallcove_unified_logsAWS Credentials ConfigurationTo 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:Environment Variables:Set theAWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEYandAWS_SESSION_TOKEN(optional for when you are using AWS STS temporary credentials) environment variables.Shared Credential File (~/.aws/credentials):Use an AWS credentials file to specify your credentials. The default location is~/.aws/credentials.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.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 theofficial Boto3 documentation.#Usage
To use Cove Unified Logs in a Python application, first create an instance of the UnifiedLogger class:fromcove_unified_logsimportUnifiedLoggerlogger=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 yourMIDDLEWAREsetting:# settings.py
MIDDLEWARE = [
    ...
    'cove_unified_logs.middleware.LoggingMiddleware',
    ...
]Next, add the log level to your settings:# settings.pyLOG_LEVEL='debug'# or 'info', 'warning', 'error', 'critical'Finally, in the module where you initialize yourUnifiedLogger, set the log level from your settings:# your file where UnifiedLogger is usedfromdjango.confimportsettingsfromcove_unified_logsimportUnifiedLoggerapp_name=apps.get_app_config(__package__.split('.')[0]).verbose_namelogger=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 ConsumerTheLogConsumerclass 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.fromcove_unified_logs.log_consumerimportLogConsumerfromcove_unified_logs.cloud_loggerimportCloudLoggercloud_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()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.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 NoticeThis 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.LicenseThis 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.DisclaimerThe 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