question

YangChowmun-0538 avatar image
0 Votes"
YangChowmun-0538 asked PramodValavala-MSFT commented

Azure function logging with python library

I have a few function under one function app and I am doing some process flow logging using python standard library like
from logging.handlers import RotatingFileHandler

I saved the log files in the fileshare. I am expecting all the log files should contain only the function's log but i notice that the log generated by Function A is appear in log files for Function B. Similarly, log generated by Function B is appeared in Function A log files.

Is there any way for us to prevent this condition from happening or is there any setting we could use?

Thanks!

azure-functions
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

PramodValavala-MSFT avatar image
0 Votes"
PramodValavala-MSFT answered PramodValavala-MSFT commented

@YangChowmun-0538 When initializing RotatingFileHandler, you would just have to pass in different file names for each function and use the right instance as required instead of using the same for all.

Also, by default, function logs will be sent to Azure Application Insights with additional properties like the Function name that you can use to query directly instead of dealing with files, unless you are specifically require file-based logging.


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @PramodValavala-MSFT thanks for the reply. I am using RotatingFileHandler to save the log into different location but the log is still mixed up. Do you mind to clarify what you mean by 'right instance as required'?

Currently, I am using different logging python library like logzero and loguru to differentiate the log but it could only differentiate for functions?

Yea I do notice about the logging by application insight. I will require to extract some data for analysis from the log files. Btw do you have any reference for how to query from application insight? Thanks

0 Votes 0 ·

@YangChowmun-0538 I mean to say that you could have separate instances of the logger object that writes to different files, one for each function.

With logzero for example, you could have custom instances for each function.

As for Application Insights, this official doc on analyzing azure functions telemetry in application insights should cover the details. For logs, you need to query the traces table.


1 Vote 1 ·