https://github.com/hashload/horse-logger-provider-console
Horse Logger - Provider Console
https://github.com/hashload/horse-logger-provider-console
Last synced: 4 months ago
JSON representation
Horse Logger - Provider Console
- Host: GitHub
- URL: https://github.com/hashload/horse-logger-provider-console
- Owner: HashLoad
- License: mit
- Created: 2021-02-02T15:09:00.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-10-18T17:03:04.000Z (over 1 year ago)
- Last Synced: 2024-04-14T01:00:08.076Z (about 1 year ago)
- Language: Pascal
- Size: 33.2 KB
- Stars: 10
- Watchers: 6
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# horse-logger-provider-console
horse-logger-provider-console is an official horse-logger middleware provider to print the logs of an API developed using the Horse framework, on console. We created a channel on Telegram for questions and support:
![]()
## ⭕ Prerequisites
[**horse-logger**](https://github.com/HashLoad/horse-logger) - Official middleware for logging in APIs developed with the Horse framework.
[**horse-utils-clientip**](https://github.com/dliocode/horse-utils-clientip) - Capture the client's IP.*Obs: If you use Boss (dependency manager for Delphi), the jhonson will be installed automatically when installing horse-logger-provider-console.*
## ⚙️ Installation
Installation is done using the [`boss install`](https://github.com/HashLoad/boss) command:
``` sh
$ boss install horse-logger-provider-console
```
If you choose to install manually, simply add the following folders to your project, in *Project > Options > Resource Compiler > Directories and Conditionals > Include file search path*
```
../horse-logger-provider-console/src
```## ✔️ Compatibility
This middleware is compatible with projects developed in:
- [X] Delphi
- [X] Lazarus## 🔠 Formatting
You can format the log output:Default: `${request_clientip} [${time}] ${request_user_agent} "${request_method} ${request_path_info} ${request_version}" ${response_status} ${response_content_length}`
Possible values: `time`,`time_short`,`execution_time`,`request_clientip`,`request_method`,`request_version`,`request_url`,`request_query`,`request_path_info`,`request_path_translated`,`request_cookie`,`request_accept`,`request_from`,`request_host`,`request_referer`,`request_user_agent`,`request_connection`,`request_derived_from`,`request_remote_addr`,`request_remote_host`,`request_script_name`,`request_server_port`,`request_remote_ip`,`request_internal_path_info`,`request_raw_path_info`,`request_cache_control`,`request_script_name`,`request_authorization`,`request_content_encoding`,`request_content_type`,`request_content_length`,`request_content_version`,`request_content`,`response_version`,`response_reason`,`response_server`,`response_realm`,`response_allow`,`response_location`,`response_log_message`,`response_title`,`response_content_encoding`,`response_content_type`,`response_content_length`,`response_content_version`,`response_content`,`response_status`
## ⚡️ Quickstart Delphi
```delphi
uses
Horse,
Horse.Logger, // It's necessary to use the unit
Horse.Logger.Provider.Console, // It's necessary to use the unit
System.SysUtils;// var
// LLogFileConfig: THorseLoggerConsoleConfig;begin
// LLogFileConfig := THorseLoggerConsoleConfig.New
// .SetLogFormat('${request_clientip} [${time}] ${response_status}');// You can also specify the log format:
// THorseLoggerManager.RegisterProvider(THorseLoggerProviderConsole.New(LLogFileConfig));// Here you will define the provider that will be used.
THorseLoggerManager.RegisterProvider(THorseLoggerProviderConsole.New());// It's necessary to add the middleware in the Horse:
THorse.Use(THorseLoggerManager.HorseCallback);THorse.Get('/ping',
procedure(Req: THorseRequest; Res: THorseResponse; Next: TProc)
begin
Res.Send('pong');
end);THorse.Listen(9000);
end;
```## ⚡️ Quickstart Lazarus
```delphi
{$MODE DELPHI}{$H+}uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Horse,
Horse.Logger, // It's necessary to use the unit
Horse.Logger.Provider.Console, // It's necessary to use the unit
SysUtils;// var
// LLogFileConfig: THorseLoggerConsoleConfig;procedure GetPing(Req: THorseRequest; Res: THorseResponse; Next: TNextProc);
begin
Res.Send('Pong');
end;begin
// LLogFileConfig := THorseLoggerConsoleConfig.New
// .SetLogFormat('${request_clientip} [${time}] ${response_status}');// You can also specify the log format:
// THorseLoggerManager.RegisterProvider(THorseLoggerProviderConsole.New(LLogFileConfig));// Here you will define the provider that will be used.
THorseLoggerManager.RegisterProvider(THorseLoggerProviderConsole.New());// It's necessary to add the middleware in the Horse:
THorse.Use(THorseLoggerManager.HorseCallback);THorse.Get('/ping', GetPing);
THorse.Listen(9000);
end.
```## 📝 Output samples
Using default log formatting, the output will look something like this:
## ⚠️ License
`horse-logger-provider-console` is free and open-source middleware licensed under the [MIT License](https://github.com/HashLoad/horse-logger-provider-console/blob/master/LICENSE).