Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit d845c13
Author: mdaneri <[email protected]>
Date:   Sun Mar 2 08:10:13 2025 -0800

    fix sample

commit a2e6474
Author: mdaneri <[email protected]>
Date:   Sun Mar 2 08:00:28 2025 -0800

    Ensure ErrorLoggingLevels is only set when ErrorLoggingEnabled is true in Pode listener configuration.

    Include Badgerati#1507 fixes

commit 79461e8
Author: mdaneri <[email protected]>
Date:   Sun Mar 2 07:22:24 2025 -0800

    remove a    $_ | Write-PodeErrorLog when log doesn't exist

commit c4b8ec2
Author: mdaneri <[email protected]>
Date:   Sat Mar 1 19:06:45 2025 -0800

    update test

commit 87e42b9
Merge: a19e5d3 67505f5
Author: mdaneri <[email protected]>
Date:   Sun Feb 23 07:31:25 2025 -0800

    Merge branch 'develop' into Log-rest-syslog

commit a19e5d3
Author: mdaneri <[email protected]>
Date:   Sat Feb 22 09:25:49 2025 -0800

    merged

commit 228e84b
Merge: 282875e cbdc62f
Author: mdaneri <[email protected]>
Date:   Sat Feb 22 09:25:41 2025 -0800

    Merge remote-tracking branch 'upstream/develop' into Log-rest-syslog

commit 282875e
Author: mdaneri <[email protected]>
Date:   Sat Feb 22 07:56:15 2025 -0800

    Update OpenApi.Tests.ps1

commit e60b039
Merge: 534fe56 fbf6ecf
Author: mdaneri <[email protected]>
Date:   Sat Feb 22 06:33:21 2025 -0800

    Merge branch 'develop' into Log-rest-syslog

commit 534fe56
Merge: 3a83ea8 a76741b
Author: mdaneri <[email protected]>
Date:   Sun Feb 16 07:09:03 2025 -0800

    Merge remote-tracking branch 'upstream/develop' into Log-rest-syslog

commit 3a83ea8
Merge: ad896c6 a236a1a
Author: mdaneri <[email protected]>
Date:   Tue Feb 11 18:51:53 2025 -0800

    Merge remote-tracking branch 'upstream/develop' into Log-rest-syslog

commit ad896c6
Merge: 115515b 75e2962
Author: mdaneri <[email protected]>
Date:   Sun Feb 9 07:25:15 2025 -0800

    Merge remote-tracking branch 'upstream/develop' into Log-rest-syslog

commit 115515b
Author: mdaneri <[email protected]>
Date:   Fri Feb 7 08:05:03 2025 -0800

    .

commit 01e5f16
Author: mdaneri <[email protected]>
Date:   Fri Feb 7 04:07:35 2025 -0800

    Update Server.Tests.ps1

commit 99e7b43
Author: mdaneri <[email protected]>
Date:   Thu Feb 6 06:31:33 2025 -0800

    minor changes

commit 64ab1c9
Author: mdaneri <[email protected]>
Date:   Thu Feb 6 06:13:17 2025 -0800

    Update Pode.psd1

commit 545b5f1
Merge: bf25899 6b23fc3
Author: mdaneri <[email protected]>
Date:   Wed Feb 5 14:56:38 2025 -0800

    Merge remote-tracking branch 'upstream/develop' into Log-rest-syslog

commit bf25899
Author: mdaneri <[email protected]>
Date:   Tue Feb 4 09:10:47 2025 -0800

    fixes post merge

commit f047cb6
Author: mdaneri <[email protected]>
Date:   Tue Feb 4 08:12:42 2025 -0800

    Update Logging.ps1

commit 1dde713
Author: mdaneri <[email protected]>
Date:   Sun Jan 26 11:57:24 2025 -0800

    Update Pode.psd1

commit 70683a0
Merge: 0de73eb f4db4b6
Author: mdaneri <[email protected]>
Date:   Sun Jan 26 11:57:21 2025 -0800

    Merge remote-tracking branch 'upstream/develop' into Log-rest-syslog

commit 0de73eb
Merge: a9926dd 391bdff
Author: mdaneri <[email protected]>
Date:   Sun Nov 24 17:06:09 2024 -0800

    Merge remote-tracking branch 'upstream/develop' into Log-rest-syslog

commit a9926dd
Merge: 6d9e798 7a2cf53
Author: mdaneri <[email protected]>
Date:   Sat Nov 23 08:02:23 2024 -0800

    Merge remote-tracking branch 'upstream/develop' into Log-rest-syslog

commit 6d9e798
Author: mdaneri <[email protected]>
Date:   Fri Nov 22 06:19:56 2024 -0800

    Update pode.build.ps1

commit 1ea0a7f
Merge: 09fd277 5a0bee1
Author: mdaneri <[email protected]>
Date:   Wed Nov 6 05:49:47 2024 -0800

    Merge branch 'develop' into Log-rest-syslog

commit 09fd277
Merge: a9f6855 62bc705
Author: mdaneri <[email protected]>
Date:   Sun Nov 3 15:50:49 2024 -0800

    Merge remote-tracking branch 'upstream/develop' into Log-rest-syslog

commit a9f6855
Merge: 6c9aa80 312654b
Author: mdaneri <[email protected]>
Date:   Sun Nov 3 12:41:33 2024 -0800

    Merge branch 'develop' into Log-rest-syslog

commit 6c9aa80
Author: mdaneri <[email protected]>
Date:   Sat Nov 2 14:08:59 2024 -0700

    fix merge

commit 1d10e20
Merge: a530fc5 a37f33b
Author: mdaneri <[email protected]>
Date:   Sat Nov 2 14:08:50 2024 -0700

    Merge remote-tracking branch 'upstream/develop' into Log-rest-syslog

commit a530fc5
Author: mdaneri <[email protected]>
Date:   Sat Nov 2 10:19:05 2024 -0700

    remove get-Pode<name>loggingName

commit 6119380
Author: mdaneri <[email protected]>
Date:   Sat Nov 2 09:44:23 2024 -0700

    Syslog format in C#

commit b529180
Author: mdaneri <[email protected]>
Date:   Sat Nov 2 08:28:47 2024 -0700

    FIx extended format

commit 4877db0
Author: mdaneri <[email protected]>
Date:   Sat Nov 2 07:57:17 2024 -0700

    moving some log formatting to C#

commit 7ffef30
Author: mdaneri <[email protected]>
Date:   Sat Nov 2 07:25:47 2024 -0700

    rename WriteError to LogMessagen and WriteException to LogException

commit 4de99c1
Author: mdaneri <[email protected]>
Date:   Sat Nov 2 07:19:41 2024 -0700

    Add support multiple restful syslog

commit d489460
Author: mdaneri <[email protected]>
Date:   Fri Nov 1 10:06:42 2024 -0700

    add try catch

commit 83b6f5a
Author: mdaneri <[email protected]>
Date:   Fri Nov 1 10:00:20 2024 -0700

    improvements

commit af60232
Author: mdaneri <[email protected]>
Date:   Fri Nov 1 09:04:03 2024 -0700

    merging  tag with source

commit 6c26f67
Merge: da1c605 308035d
Author: mdaneri <[email protected]>
Date:   Wed Oct 30 07:24:49 2024 -0700

    Merge remote-tracking branch 'upstream/develop' into Log-rest-syslog

commit da1c605
Author: mdaneri <[email protected]>
Date:   Mon Oct 28 09:31:18 2024 -0700

    fix servless test

commit f9ab920
Author: mdaneri <[email protected]>
Date:   Mon Oct 28 09:18:10 2024 -0700

    fix test and file logging

commit 1efbc89
Author: mdaneri <[email protected]>
Date:   Mon Oct 28 08:59:41 2024 -0700

    File service fixes

commit fe20cfb
Author: mdaneri <[email protected]>
Date:   Mon Oct 28 07:35:57 2024 -0700

    Fix tests + bugs post merge

commit 0504b1b
Merge: 1be9163 c47ad6f
Author: mdaneri <[email protected]>
Date:   Mon Oct 28 07:15:31 2024 -0700

    Merge remote-tracking branch 'upstream/develop' into Log-rest-syslog

commit 1be9163
Author: mdaneri <[email protected]>
Date:   Sun Oct 27 20:04:52 2024 -0700

    functions change

commit e4ebc2a
Merge: 4859585 09d9ad0
Author: mdaneri <[email protected]>
Date:   Sun Oct 27 16:56:39 2024 -0700

    Merge remote-tracking branch 'upstream/develop' into Log-rest-syslog

commit 4859585
Author: mdaneri <[email protected]>
Date:   Fri Oct 25 17:59:07 2024 -0700

    Fix Levels and cleanup

commit 5a77d59
Author: mdaneri <[email protected]>
Date:   Fri Oct 25 17:18:13 2024 -0700

    revert PodetraceLog

commit 34eecb6
Merge: 9e48241 c8e23fb
Author: mdaneri <[email protected]>
Date:   Wed Oct 23 12:59:20 2024 -0700

    Merge remote-tracking branch 'upstream/develop' into Log-rest-syslog

commit 9e48241
Merge: 078737a 0b08d67
Author: mdaneri <[email protected]>
Date:   Wed Oct 23 07:42:13 2024 -0700

    Merge remote-tracking branch 'upstream/develop' into Log-rest-syslog

commit 078737a
Author: mdaneri <[email protected]>
Date:   Mon Oct 21 18:53:36 2024 -0700

    Update Context.ps1

commit 58e1d58
Author: mdaneri <[email protected]>
Date:   Mon Oct 21 08:28:37 2024 -0700

    changed New-PodeCustomLoggingMethod to support only runspace

commit 7e0514a
Author: mdaneri <[email protected]>
Date:   Mon Oct 21 08:07:53 2024 -0700

    Update Pode.psd1

commit b021e7e
Merge: 94da198 79ec468
Author: mdaneri <[email protected]>
Date:   Mon Oct 21 08:07:49 2024 -0700

    Merge remote-tracking branch 'upstream/develop' into Log-rest-syslog

commit 94da198
Author: mdaneri <[email protected]>
Date:   Sun Oct 20 21:32:22 2024 -0700

    function headers

commit a0b4673
Author: mdaneri <[email protected]>
Date:   Sun Oct 20 20:46:05 2024 -0700

    New-PodeLoggingMethod deprecation

commit bd92d53
Author: mdaneri <[email protected]>
Date:   Sun Oct 20 18:08:07 2024 -0700

    fix test

commit 7858e47
Author: mdaneri <[email protected]>
Date:   Sun Oct 20 09:34:08 2024 -0700

    removed redundant sg function

commit 155b7d9
Merge: ce3ebcf 0411580
Author: mdaneri <[email protected]>
Date:   Sun Oct 20 09:24:56 2024 -0700

    Merge remote-tracking branch 'upstream/develop' into Log-rest-syslog

commit ce3ebcf
Author: mdaneri <[email protected]>
Date:   Sun Oct 20 09:24:39 2024 -0700

    fix an PodeContext.cs created by a merge

    Performance improvement

commit d16456f
Author: mdaneri <[email protected]>
Date:   Sat Oct 19 13:24:32 2024 -0700

    minor changes

commit 4d22cc3
Merge: e838173 a181172
Author: mdaneri <[email protected]>
Date:   Fri Oct 18 20:30:09 2024 -0400

    Merge branch 'develop' into Log-rest-syslog

commit e838173
Merge: 51e1ed9 696cc43
Author: mdaneri <[email protected]>
Date:   Wed Oct 16 07:55:33 2024 -0700

    Merge remote-tracking branch 'upstream/develop' into Log-rest-syslog

commit 51e1ed9
Merge: b0720cc 21c76a1
Author: mdaneri <[email protected]>
Date:   Sun Sep 29 08:06:56 2024 -0700

    Merge branch 'develop' into Log-rest-syslog

commit b0720cc
Author: mdaneri <[email protected]>
Date:   Sat Sep 28 11:00:14 2024 -0700

    Update Logging.ps1

commit 7de7e69
Merge: 3df186a 2e9d252
Author: mdaneri <[email protected]>
Date:   Sat Sep 28 10:59:51 2024 -0700

    Merge remote-tracking branch 'upstream/develop' into Log-rest-syslog

commit 3df186a
Merge: 984822e 3ba7228
Author: mdaneri <[email protected]>
Date:   Sat Sep 28 10:14:16 2024 -0700

    Merge remote-tracking branch 'upstream/develop' into Log-rest-syslog

commit 984822e
Author: mdaneri <[email protected]>
Date:   Sat Sep 28 09:03:17 2024 -0700

    fix Locales duplicated key

commit a7892ac
Merge: 8005ef8 af57434
Author: mdaneri <[email protected]>
Date:   Sat Sep 28 08:32:31 2024 -0700

    Merge remote-tracking branch 'upstream/develop' into Log-rest-syslog

commit 8005ef8
Merge: c284d8c 38f2f07
Author: mdaneri <[email protected]>
Date:   Fri Sep 27 07:50:27 2024 -0700

    Merge remote-tracking branch 'upstream/develop' into Log-rest-syslog

commit c284d8c
Author: mdaneri <[email protected]>
Date:   Mon Sep 23 08:23:59 2024 -0700

    Fix runspace naming

commit 60f8601
Author: mdaneri <[email protected]>
Date:   Sun Sep 22 08:44:12 2024 -0700

    fix en_us language

commit 811cbd6
Author: mdaneri <[email protected]>
Date:   Sun Sep 22 08:24:09 2024 -0700

    	modified:   src/Private/Context.ps1

commit 992c87f
Merge: 50a222e 473c9be
Author: mdaneri <[email protected]>
Date:   Sun Sep 22 08:24:06 2024 -0700

    Merge remote-tracking branch 'upstream/develop' into Log-rest-syslog

commit 50a222e
Merge: d7fa9f7 d51eda6
Author: mdaneri <[email protected]>
Date:   Sun Sep 22 06:24:08 2024 -0700

    Merge branch 'develop' into Log-rest-syslog

commit d7fa9f7
Author: mdaneri <[email protected]>
Date:   Sat Sep 21 14:29:53 2024 -0700

    fix tests

commit 1deeffc
Merge: d775128 93df876
Author: mdaneri <[email protected]>
Date:   Sat Sep 21 10:16:02 2024 -0700

    Merge remote-tracking branch 'upstream/develop' into Log-rest-syslog

commit d775128
Merge: 25120b0 9a99c96
Author: mdaneri <[email protected]>
Date:   Sun Sep 15 15:18:21 2024 -0700

    Merge remote-tracking branch 'upstream/develop' into Log-rest-syslog

commit 25120b0
Author: mdaneri <[email protected]>
Date:   Sat Sep 7 20:56:17 2024 -0700

    recovered from Add New Logging Features: Syslog and Restful Support Badgerati#1335
  • Loading branch information
mdaneri committed Mar 3, 2025
1 parent 1cc7bb6 commit 0958e39
Show file tree
Hide file tree
Showing 66 changed files with 5,640 additions and 939 deletions.
2 changes: 1 addition & 1 deletion docs/Getting-Started/Migrating/0X-to-1X.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Request and Error logging are inbuilt logging types that can be enabled using [`
| [`Disable-PodeRequestLogging`](../../../Functions/Logging/Disable-PodeRequestLogging) |
| [`Disable-PodeErrorLogging`](../../../Functions/Logging/Disable-PodeErrorLogging) |
| [`Remove-PodeLogger`](../../../Functions/Logging/Remove-PodeLogger) |
| [`Clear-PodeLoggers`](../../../Functions/Logging/Clear-PodeLoggers) |
| [`Clear-PodeLogger`](../../../Functions/Logging/Clear-PodeLogger) |

### Writing Logs

Expand Down
2 changes: 2 additions & 0 deletions docs/Tutorials/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ A "path" like `Server.Ssl.Protocols` looks like the below in the file:
| Server.FileMonitor | Defines configuration for restarting the server based on file updates | [link](../Restarting/Types/FileMonitoring) |
| Server.ReceiveTimeout | Define the amount of time a Receive method call will block waiting for data | [link](../Endpoints/Basic/StaticContent/#server-timeout) |
| Server.DefaultFolders | Set the Default Folders paths | [link](../Routes/Utilities/StaticContent/#changing-the-default-folders) |
| Server.Logging.QueueLimit | Set the maximum number of logs allowed in the queue | [link](../Logging/Overview) |
| Server.Logging.Masking.Patterns | Regular expressions congiguration to mask sensitive logs information | [link](../Logging/Overview) |
| Server.Console | Set the Console settings | [link](../Getting-Started/Console) |
| Web.OpenApi.DefaultDefinitionTag | Define the primary tag name for OpenAPI ( `default` is the default) | [link](../OpenAPI/Overview) |
| Web.OpenApi.UsePodeYamlInternal | Force the use of the internal YAML converter (`False` is the default) | |
Expand Down
63 changes: 52 additions & 11 deletions docs/Tutorials/Logging/Methods/Custom.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,76 @@
# Custom

Sometimes you don't want to log to a file, or the terminal; instead you want to log to something better, like LogStash, Splunk, Athena, or any other central logging platform. Although Pode doesn't have these inbuilt (yet!) it is possible to create a custom logging method, where you define a ScriptBlock with logic to send logs to these platforms.
Sometimes you may want to log to platforms other than a file or the terminal, such as LogStash, Splunk, Athena, or other central logging platforms. Although Pode doesn't have these integrations built-in (yet!), it is possible to create a custom logging method by defining a ScriptBlock with the logic to send logs to these platforms.

These custom method can be used for any log type - Requests, Error, or Custom.
Custom methods can be used for any log type: Requests, Error, or Custom.

The ScriptBlock you create will be supplied two arguments:
The ScriptBlock you create will receive two arguments:

1. The item to be logged. This could be a string (from Requests/Errors), or any custom type.
2. The options you supplied on [`New-PodeLoggingMethod`](../../../../Functions/Logging/New-PodeLoggingMethod).
1. The item to be logged. This could be a string (from Requests/Errors) or any custom type.

2. The options you supplied to [`New-PodeLoggingMethod`](../../../../Functions/Logging/New-PodeLoggingMethod).

Additionally, custom logging methods can be run in their own runspace by using the `-UseRunspace` parameter, ensuring isolation and efficiency.

## Examples

### Send to S3 Bucket

This example will take whatever item is supplied to it, convert it to a string, and then send it off to some S3 bucket in AWS. In this case, it will be logging Requests:
This example takes the supplied item, converts it to a string, and sends it to an S3 bucket in AWS. In this case, it will log Requests:

#### Legacy (No Runspace)
```powershell
$s3_options = @{
AccessKey = $AccessKey
SecretKey = $SecretKey
}
$s3_logging = New-PodeLoggingType -Custom -ArgumentList $s3_options -ScriptBlock {
$s3_logging = New-PodeLoggingMethod -Custom -ArgumentList $s3_options -ScriptBlock {
param($item, $s3_opts)
Write-S3Object `
-BucketName '<name>' `
-Content $item.ToString() `
-AccessKey $s3_opts.AccessKey `
Write-S3Object \`
-BucketName '<name>' \`
-Content $item.ToString() \`
-AccessKey $s3_opts.AccessKey \`
-SecretKey $s3_opts.SecretKey
}
$s3_logging | Enable-PodeRequestLogging
```


#### With Runspace

```powershell
$s3_options = @{
AccessKey = $AccessKey
SecretKey = $SecretKey
}
$s3_logging = New-PodeLoggingMethod -Custom -UseRunspace -CustomOptions $s3_options -ScriptBlock {
# No param() allowed here
Write-S3Object \`
-BucketName '<name>' \`
-Content $Item.ToString() \`
-AccessKey $Options.AccessKey \`
-SecretKey $Options.SecretKey
}
$s3_logging | Enable-PodeRequestLogging
```


In this example, the `-UseRunspace` parameter ensures that the custom logging method runs in its own runspace, providing better isolation and performance.

##### Variable available inside the ScriptBlock

| Variable | Type | Description |
| ----------------------- | ----------------------------- | ------------------------------------------------ |
| Item | string | Log message content |
| Options | hashtable | The options supplied to the logging method |
| Options.FailureAction | string (Ignore, Report, Halt) | Defines the behavior in case of failure. |
| Options.DataFormat | string | The date format to use for the log entries. |
| Options.AsUTC | boolean | the time is logged in UTC instead of local time. |
| Options.<CustomOptions> | PSObject | Any key passed using `-CustomOptions` parameter |
| RawItem | hashtable | Log message in raw format |


By leveraging custom logging methods, you can extend Pode's logging capabilities to integrate with a wide range of external platforms, providing flexibility and control over your logging strategy.
39 changes: 39 additions & 0 deletions docs/Tutorials/Logging/Methods/File.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,42 @@ By default Pode puts all logs in the `./logs` directory. You can use a custom pa
```powershell
New-PodeLoggingMethod -File -Name 'requests' -Path 'E:/logs' | Enable-PodeRequestLogging
```

### Format

The Format parameter allows you to specify the format of the log entries. Available options are:

- RFC3164
- RFC5424
- Simple
- Default (default option)

The Simple format uses the following structure: timestamp level source message. The Default format uses the legacy Pode format.

```powershell
New-PodeLoggingMethod -File -Name 'requests' -Format 'Simple' | Enable-PodeRequestLogging
```
A log entry using the Simple format might look like this:

```arduino
2024-08-01T12:00:00Z INFO MyApp "Request received"
```

### Custom Separator
When using the Simple format, you can specify a custom separator for log entries:

```powershell
New-PodeLoggingMethod -File -Name 'requests' -Format 'Simple' -Separator ',' | Enable-PodeRequestLogging
```

A log entry using the Simple format with a comma separator might look like this:
```arduino
2024-08-01T12:00:00Z,INFO,MyApp,"Request received"
```

### Maximum Log Entry Length
The MaxLength parameter sets the maximum length of log entries. The default value is -1, which means no limit.

```powershell
New-PodeLoggingMethod -File -Name 'requests' -MaxLength 500 | Enable-PodeRequestLogging
```
56 changes: 56 additions & 0 deletions docs/Tutorials/Logging/Methods/Syslog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

# Syslog

Pode supports logging items to a Syslog server using the inbuilt Syslog logging method. This method allows you to define various parameters such as the Syslog server address, port, transport protocol, and more. The logging method will convert any item to a string and send it to the configured Syslog server.

By default, Pode will use UDP as the transport protocol and RFC5424 as the Syslog protocol. You can customize these settings based on your Syslog server requirements.

## Examples

### Basic

The following example will setup the Syslog logging method for logging requests:

```powershell
New-PodeLoggingMethod -Syslog -Server '192.168.1.1' | Enable-PodeRequestLogging
```

### Custom Port

The following example will configure Syslog logging to use a custom port. The default port is 514, but you can specify a different port if needed:

```powershell
New-PodeLoggingMethod -Syslog -Server '192.168.1.1' -Port 1514 | Enable-PodeRequestLogging
```

### Secure Connection with TLS

The following example will configure Syslog logging to use TLS for a secure connection. You can also specify the TLS protocol version to use:

```powershell
New-PodeLoggingMethod -Syslog -Server '192.168.1.1' -Transport 'TLS' -TlsProtocol 'TLS1.2' | Enable-PodeRequestLogging
```

### Custom Syslog Protocol

The following example will configure Syslog logging to use a different Syslog protocol. The default protocol is RFC5424, but you can specify RFC3164 if needed:

```powershell
New-PodeLoggingMethod -Syslog -Server '192.168.1.1' -SyslogProtocol 'RFC3164' | Enable-PodeRequestLogging
```

### Skip Certificate Validation

The following example will configure Syslog logging to skip certificate validation for TLS connections. This is useful for testing purposes but not recommended for production environments:

```powershell
New-PodeLoggingMethod -Syslog -Server '192.168.1.1' -Transport 'TLS' -SkipCertificateCheck | Enable-PodeRequestLogging
```

### Custom Encoding

The following example will configure Syslog logging to use a different encoding for the Syslog messages. The default encoding is UTF8:

```powershell
New-PodeLoggingMethod -Syslog -Server '192.168.1.1' -Encoding 'ASCII' | Enable-PodeRequestLogging
```
61 changes: 55 additions & 6 deletions docs/Tutorials/Logging/Overview.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# Overview

There are two aspects to logging in Pode: Methods and Types.
Logging in Pode consists of two main components: Methods and Types.

* Methods define how log items should be recorded, such as to a file, terminal, or event viewer.
* Types define how items to log are transformed, and what should be supplied to the Method.
- **Methods**: Define how log items should be recorded, such as to a file, terminal, or event viewer. Each logging method operates in its own runspace, providing isolation and efficiency. The exception to this is the Custom method, which by default runs in the same runspace as the log dispatcher unless the `-UseRunspace` parameter is specified.

For example when you supply an Exception to [`Write-PodeErrorLog`](../../../Functions/Logging/Write-PodeErrorLog), this Exception is first supplied to Pode's inbuilt Error logging type. This type transforms any Exception (or Error Record) into a string which can then be supplied to the File logging method.
- **Types**: Define how log items are transformed and what data should be supplied to the Method.

In Pode you can use File, Terminal, Event Viewer, or a Custom method. As well as Request, Error, or a Custom type.
When you supply an Exception to [`Write-PodeErrorLog`](../../../Functions/Logging/Write-PodeErrorLog), the Exception is first processed by Pode's built-in Error logging type. This type transforms the Exception (or Error Record) into a string format, which can then be recorded by the logging method (e.g., File).

Pode supports various logging methods, including File, Terminal, Event Viewer, Syslog, Restful, or Custom methods. Additionally, you can utilize different logging types such as Request, Error, or Custom types.

This flexibility allows you to create a custom logging method that can output logs to various platforms, such as an S3 bucket, Splunk, or any other logging service.

This means you could write a logging method to output to an S3 bucket, Splunk, or any other logging platform.

## Masking Values

Expand Down Expand Up @@ -109,3 +111,50 @@ Instead of writing logs one-by-one, the above will keep transformed log items in
This means that the method's scriptblock will receive an array of items, rather than a single item.

You can also sent a `-BatchTimeout` value, in seconds, so that if your batch size it 10 but only 5 log items are added, then after the timeout value the logs items will be sent to your method.



## Configuring Failure Actions for Log Writing

Defines the behavior in case of failure to write a log. This can happen if the disk is full, the Syslog server is offline, or if the number of logs in the queue reaches the maximum allowed. The options are:
- **Ignore** : Does nothing and continues execution. **(Default)**
- **Report** : Writes a message to the console for any failure.
- **Halt** : Writes a message to the console and shuts down the Pode server.

```powershell
New-PodeLoggingMethod -File -Path './logs' -Name 'errors' -FailureAction 'Report' | Enable-PodeRequestLogging
```

## QueueLimit
Defines the maximum number of logs allowed in the queue before throwing an event.
The default value is 500. The exception is handled based on the `-FailureAction` parameter.

```powershell
@{
Server = @{
Logging = @{
QueueLimit = 1000
}
}
}
```

## DataFormat
The date format to use for the log entries. The default format is `'dd/MMM/yyyy:HH:mm:ss zzz'`.

```powershell
New-PodeLoggingMethod -File -Path './logs' -Name 'access' -DataFormat 'yyyy-MM-dd HH:mm:ss' | Enable-PodeErrorLogging
```

## ISO8601
If set, the date format will be ISO 8601 compliant (equivalent to `-DataFormat 'yyyy-MM-ddTHH:mm:ssK'`). This parameter is mutually exclusive with DataFormat.

```powershell
New-PodeLoggingMethod -File -Path './logs' -Name 'access' -ISO8601 | Enable-PodeErrorLogging
```

## AsUTC
If set, the time will be logged in UTC instead of local time.

```powershell
New-PodeLoggingMethod -File -Path './logs' -Name 'access' -AsUTC -ISO8601 | Enable-PodeErrorLogging
70 changes: 70 additions & 0 deletions docs/Tutorials/Logging/Types/General.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@

# General Logging

Pode supports general logging, allowing you to define custom logging methods and log levels. This feature enables you to write logs based on specified methods, ensuring flexibility and control over logging outputs.

To enable general logging, use the `Add-PodeLoggingMethod` function. This function takes a hashtable defining the logging method, including a ScriptBlock for log output. You can specify various log levels to be enabled, such as Error, Emergency, Alert, Critical, Warning, Notice, Informational, Info, Verbose, and Debug.

## Enabling General Logging

To enable general logging, use the `Add-PodeLoggingMethod` function, supplying the necessary parameters:

- `Method`: The hashtable defining the logging method, including the ScriptBlock for log output.
- `Levels`: An array of log levels to be enabled for the logging method (default includes Error, Emergency, Alert, Critical, Warning, Notice, Informational, Info, Verbose, Debug).
- `Name`: The name of the logging method to be enabled.
- `Raw`: If set, the raw log data will be included in the logging output.

### Example

```powershell
$method = New-PodeLoggingMethod -syslog -Server 127.0.0.1 -Transport UDP
$method | Add-PodeLoggingMethod -Name "mysyslog"
```

## Disabling General Logging

To disable a general logging method, use the `Remove-PodeLoggingMethod` function with the `Name` parameter:

### Example

```powershell
Remove-PodeLoggingMethod -Name 'mysyslog'
```

With these functions, Pode ensures robust and customizable logging capabilities, allowing you to manage logs effectively based on your specific requirements.

## Writing to General Logs

Pode allows you to write logs to configured custom or inbuilt logging methods using the `Write-PodeLog` function. This function supports both custom and inbuilt logging methods, enabling structured logging with various log levels and messages.

### Writing to General Logs

To write logs, you can use the `Write-PodeLog` function with different parameters to specify the logging method, log level, message, and other details.

#### Example Usage

##### Logging an Object

To write an object to a configured logging method:

```powershell
$logItem = @{
Date = [datetime]::Now
Level = 'Informational'
Server = 'MyServer'
Category = 'General'
Message = 'This is a log message'
StackTrace = ''
}
$logItem | Write-PodeLog -Name 'mysyslog'
```

##### Logging with Custom Levels and Messages

To log a custom message with a specific log level:

```powershell
Write-PodeLog -Name 'mysyslog' -Level 'Error' -Message 'An error occurred.' -Tag 'MyApp'
```

In these examples, `Write-PodeLog` is used to write structured log items or custom messages to the specified logging methods, helping you maintain organized and detailed logs.
24 changes: 22 additions & 2 deletions docs/Tutorials/Logging/Types/Requests.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ Pode has inbuilt Request logging logic, that will parse and return a valid log i

To enable and use the Request logging you use the [`Enable-PodeRequestLogging`](../../../../Functions/Logging/Enable-PodeRequestLogging) function, supplying a logging method from [`New-PodeLoggingMethod`](../../../../Functions/Logging/New-PodeLoggingMethod).

The Request type logic will format a string using [Combined Log Format](https://httpd.apache.org/docs/1.3/logs.html#combined). This string is then supplied to the logging method's scriptblock. If you're using a Custom logging method and want the raw hashtable instead, you can supply `-Raw` to [`Enable-PodeRequestLogging`](../../../../Functions/Logging/Enable-PodeRequestLogging).
The Request type logic will format a string using [Combined Log Format](https://httpd.apache.org/docs/1.3/logs.html#combined).
This string is then supplied to the logging method's scriptblock. You can customize the log format using the `-LogFormat` parameter with options like `Extended`, `Common`, `Combined`, and `JSON`.

If you're using a Custom logging method and want the raw hashtable instead, you can supply `-Raw` to [`Enable-PodeRequestLogging`](../../../../Functions/Logging/Enable-PodeRequestLogging).

## Examples

Expand All @@ -18,6 +21,23 @@ The following example simply enables Request logging, and will output all items
New-PodeLoggingMethod -Terminal | Enable-PodeRequestLogging
```

### Log Format

#### Extended Log Format
The following example enables Request logging using the Extended Log Format:

```powershell
New-PodeLoggingMethod -File -Path './logs' -Name 'requests' | Enable-PodeRequestLogging -LogFormat 'Extended'
```

#### JSON Format
The following example enables Request logging using JSON Format:

```powershell
New-PodeLoggingMethod -File -Path './logs' -Name 'requests' | Enable-PodeRequestLogging -LogFormat 'Json'
```


### Using Raw Item

The following example uses a Custom logging method, and sets Request logging to return and supply the raw hashtable to the Custom method's scriptblock. The Custom method simply logs the Host an StatusCode to the terminal (but could be to something like an S3 bucket):
Expand Down Expand Up @@ -70,4 +90,4 @@ The raw Request hashtable that will be supplied to any Custom logging methods wi
Size = '9001'
}
}
```
```
Loading

0 comments on commit 0958e39

Please sign in to comment.