Azure / azure-functions-core-tools

Command line tools for Azure Functions
MIT License
1.31k stars 433 forks source link

Option to output log category to Azure Functions Core Tools Function Runtime console and logfile #2835

Open ghost opened 4 years ago

ghost commented 4 years ago

What problem would the feature you're requesting solve? Please describe.

I'm always frustrated when I can see my log output in the Azure Functions Core Tools Function Runtime console but I cannot see what class is emitting the log entries because the log category is not included in output. This would be very useful during development and also to more easily understand and refine log filters.

Describe the solution you'd like

Add an option to allow the Category of the log to be output to the Azure Functions Core Tools Function Runtime console.

e.g. [26/02/2020 13:27:21] [category here] Initializing function HTTP routes [26/02/2020 13:27:21] [category here] No HTTP routes mapped [26/02/2020 13:27:21] [category here] [26/02/2020 13:27:21] [category here] Host initialized (364ms) [26/02/2020 13:27:21] [category here] Host started (652ms) [26/02/2020 13:27:21] [category here] Job host started [26/02/2020 13:27:21] [category here] Debug file watch initialized. [26/02/2020 13:27:21] [category here] Foo [26/02/2020 13:27:21] [category here] Bar [26/02/2020 13:27:21] [category here] Elephant

Describe alternatives you've considered

Thought I might get this from looking in the logfile created at %temp%\LogFiles\Application\Functions but whilst that has loglevel it too does not have log category. Log category is available in application insights but there is no local equivalent of application insights and using the cloud application insights is not a sensible option for cost and latency reasons.

Additional context

Add any other context or screenshots about the feature request here.

gzuber commented 4 years ago

@acrov Thanks for the suggestion! You should be able to inject a custom logger so you can see the category for your logs, would that work? Or did you want the category for all logs?

ghost commented 4 years ago

Many thanks for the reply.

I could indeed inject a logger, although, as you imply, that would not work for logger output from the function host itself - knowing the logger category of function host output allows one to tune log filters appropriately.

Perhaps more importantly, logger injection simply doesn't work if you are not using DI - e.g. static void functions (as in all the azure function examples in the documentation).

Also, there is high utility and convenience, especially for people just getting started with Azure Functions, in just being able to look at output rigth there on the Tools Function Runtime console and not have work out how to hook up their own custom logger (or even know they can do that).

ghost commented 4 years ago

Instead of injecting a logger, if one could inject a log format template into the built in logger that would work nicely.

Perhaps this could be specified somehow in the Host section of the local.setting.json where there seem to be other settings that affect the local function host - https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=windows#local-settings-file

gzuber commented 4 years ago

@acrov this is good input, thank you! Especially since we seem to be outputting category when running from Visual Studio. Unfortunately I can't promise anything, but I'll go ahead and Triage this so we can look into what we might be able to do.

ghost commented 4 years ago

Please could you elaborate on "we seem to be outputting category when running from Visual Studio". When I run a function app in Visual Studio it runs the Tools Function Runtime and outputs to that. Where do you see the category?

M0ns1gn0r commented 3 years ago

I would also like to see the format customization. I need to see the log level as text (e.g. [E] or [I]) for post-processing of the console output via pipes. Currently the log level can only be deduced from the message color (hello colorblind).

aggieben commented 2 years ago

Another +1 from me on the need for some kind of configurable logging format template.

anthonychu commented 2 years ago

I like this suggestion as well. Quite often the only way to see this is in App Insights. Moving to Core Tools repo.