4

I'm setting up logging on a flask service. I tried to write logs to an azure blob storage with the following code

import logging
import sys

from azure_storage_logging.handlers import BlobStorageRotatingFileHandler

logger = logging.getLogger('service_logger')
logger.setLevel(logging.DEBUG)
log_formater = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(process)d - %(message)s')
azure_blob_handler = BlobStorageRotatingFileHandler(filename = 'service.log', 
                                                    account_name='servicestorage',
                                                    account_key='',
                                                    maxBytes= maxBytes,
                                                    container='service-log')
azure_blob_handler.setLevel(logging.INFO)
azure_blob_handler.setFormatter(log_formater)
logger.addHandler(azure_blob_handler)

Then, I tried with logger.warning('test warning'), but there's not log file created on the azure blob container.

Can anyone help me figure out where I did wrong?

Best, Eigen

2
  • Hi,any progress now? Commented Aug 2, 2018 at 8:41
  • Thanks for your following. I figures out that the azure blob I first tried is for China market. The logging works when I connect to global azure blob. Any way to point the logging handler to azure blob in China market? Commented Aug 3, 2018 at 2:05

1 Answer 1

5

I tried your code in my flask but did't reproduce your issue.

code:

@app.route('/log')
def log():

    import logging
    import sys
    from azure_storage_logging.handlers import BlobStorageRotatingFileHandler

    mystorageaccountname='***'
    mystorageaccountkey='***'

    logger = logging.getLogger('service_logger')
    logger.setLevel(logging.DEBUG)
    log_formater = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(process)d - %(message)s')
    azure_blob_handler = BlobStorageRotatingFileHandler(filename = 'service.log', 
                                                        account_name=mystorageaccountname,
                                                        account_key=mystorageaccountkey,
                                                        maxBytes= 5,
                                                        container='service-log')
    azure_blob_handler.setLevel(logging.INFO)
    azure_blob_handler.setFormatter(log_formater)
    logger.addHandler(azure_blob_handler)

    logger.warning('warning message')

output:

enter image description here

More details, you could refer to the doc and source code.

Hope it helps you. Any concern,please let me know.

Sign up to request clarification or add additional context in comments.

1 Comment

there is problem that it does not upload if the content does not reach till maxBytes. And irrespective of size it should not upload results after logging ends.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.