Badgerati / Pode

Pode is a Cross-Platform PowerShell web framework for creating REST APIs, Web Sites, and TCP/SMTP servers
https://badgerati.github.io/Pode
MIT License
830 stars 92 forks source link

Add New Logging Features: Syslog and Restful Support #1335

Open mdaneri opened 2 months ago

mdaneri commented 2 months ago

Description:

This PR introduces new features to the Pode logging system, adding support for Syslog and Restful logging methods. The following new functions have been added:

Additionally,

the New-PodeLoggingMethod function now supports two new type: Syslog and Restful. Write-PodeLog now has been improved 

New Features:

Here is an example of how to configure multiple logging output methods:

$logging = @(
    (New-PodeLoggingMethod -Terminal),
    (New-PodeLoggingMethod -Syslog -Server 127.0.0.1 -Transport UDP -AsUTC -ISO8601 -FailureAction Report),
    (New-PodeLoggingMethod -File -Name 'requests' -MaxDays 4)
)

$logging | Enable-PodeRequestLogging
Badgerati commented 2 months ago

Looking at Get-PodeLoggingSysLogMethod, I'd say that Splunk and LogInsight would better being their own separate log methods - they share some common parameters with syslog (server, port, etc.), but they don't use/send the syslog format.

Ie, On New-PodeLoggingMethod, new switches for:

And then move them out of Get-PodeLoggingSysLogMethod, and into Splunk/LogInsight specific functions. This would open the doors for Azure Log Analytics, AWS Cloudwatch, DataDog, and others too down the line.

For -FailureAction, I actually like this param, and I'm wondering if instead of being syslog specific we allow it for all method types 🤔. This means the HandleFailure would be best as its own function rather than a child function.


In terms of Splunk/LogInsight using the REST API, I've no issues - in fact I was going to do this for Azure Log Analytics. However, the methods will need to handle batch logging, more so if the REST API supports sending multiple logs in one request, rather than a single log at a time. There's an example of batch logs in Get-PodeLoggingEventViewerMethod, where the $item can either be a single item or an array - if you convert it to an array each time you can simply iterate over all items, or send them in bulk.

Badgerati commented 2 months ago

Splunk was also raised a while back, and one recommendation was also the REST API; in fact, the example there an yours are basically the same 😄

Here: https://github.com/Badgerati/Pode/issues/1018

Badgerati commented 2 months ago

I've done a quick scan of the code, and can't immediately see anything concerning with the code changes. I've a couple questions, but I'll see if I answer them myself when a review properly.

Only one thing I did spot was the removal of the dd/MMM/yyyy:HH:mm:ss zzz format. I'm happy with the DateFormat parameter, but this date formatting needs adding back in for the Request logging as it's the format expected by the Combined Log Format - and would also make it a breaking change :)

mdaneri commented 2 months ago

For compatibility I can set that as default format

mdaneri commented 2 months ago

i 'm going to add additional options to support common log format and extended log format for the access log

mdaneri commented 1 month ago

I'm considering a new approach to improve the performance of our methods by utilizing runspaces. Specifically, I plan to:

  1. Remove the following line of code:

    $null = Invoke-PodeScriptBlock -ScriptBlock $method.ScriptBlock -Arguments $_args -UsingVariables $logger.Method.UsingVariables -Splat
  2. Replace it with a queue for each method to better manage execution.

Additionally, I've noticed that the current logging mechanism is too heavy and slow. To address this, I propose making the writer methods asynchronous, ensuring they operate independently from each other and the rest of the code.

mdaneri commented 1 month ago

Almost done. what is missing is the remove of a log and some doc update