Azure-Samples / functions-custom-handlers

Sample code for Azure Functions custom handlers
MIT License
91 stars 31 forks source link

How to log properly from a custom handler #17

Open Fishrock123 opened 3 years ago

Fishrock123 commented 3 years ago

Hi, I'm using a custom handler so I write a function in Rust: https://github.com/squamishaccess/squamishaccess-signup-function-rs

My main blocker right now is figuring out how to log properly. Logging to the stdio only seems to show up in a local (VS Code) log stream, and not in the function monitor panel log stream. Ideally I'd like to make log traces to the "invocations" panel, I'm unsure if that is scraped from file system logs or Application Insights.

Additionally, it doesn't seem to parse JSON logs. Here is an example:

2020-10-23T23:05:47.930 [Trace] Sending invocation id:cae182d4-f137-4a62-bc79-76d9265924e1
2020-10-23T23:05:47.930 [Debug] Forwarding httpTrigger invocation for function: 'Paypal-IPN' invocationId: 'cae182d4-f137-4a62-bc79-76d9265924e1'
2020-10-23T23:05:47.931 [Debug] Sending invocation for function: 'Paypal-IPN' invocationId: 'cae182d4-f137-4a62-bc79-76d9265924e1'
2020-10-23T23:05:47.940 [Information] {"level":30,"time":1603494347939,"msg":"<-- Request received","method":POST,"path":/api/Paypal-IPN}
2020-10-23T23:05:47.946 [Information] {"level":30,"time":1603494347939,"msg":"cae182d4-f137-4a62-bc79-76d9265924e1 PayPal IPN Notification Event received successfully."}

The lines that say ... [Information] {"level":30, ... are from my json logger.

horizondeep commented 6 months ago

Hi @Fishrock123..Are you able to figure out how to do logging in Rust Custom Handler function. I am also facing the same issue, where logs are working fine in local VS code but after deployment I cannot see them in the panel. Using env_logger/log.

Fishrock123 commented 4 months ago

@horizondeep see the code in https://github.com/squamishaccess/squamishaccess-functions/tree/main/src/azure_function

sanan-go commented 2 months ago

I have the same issue with golang