Skip to content

Commit

Permalink
Update README.md #2
Browse files Browse the repository at this point in the history
  • Loading branch information
viniciussanchez authored Oct 7, 2021
1 parent 59ef662 commit 67d0aae
Showing 1 changed file with 53 additions and 13 deletions.
66 changes: 53 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,74 @@
# horse-logger-provider-console
Provider for horse-logger
<b>horse-logger-provider-console</b> is an official <a href="https://github.com/HashLoad/horse-logger">horse-logger</a> middleware provider to print the logs of an API developed using the <a href="https://github.com/HashLoad/horse">Horse</a> framework, on console. We created a channel on Telegram for questions and support:<br><br>
<a href="https://t.me/hashload">
<img src="https://img.shields.io/badge/telegram-join%20channel-7289DA?style=flat-square">
</a>

### For install in your project using [boss](https://github.com/HashLoad/boss):
## ⭕ Prerequisites
[**horse-logger**](https://github.com/HashLoad/horse-logger) - Official middleware for logging in APIs developed with the Horse framework.<br>
[**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
```

## Config
## ✔️ Compatibility
This middleware is compatible with projects developed in:
- [X] Delphi
- [X] Lazarus

### Format
`Format` defines the logging format with defined variables
## 🔠 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`,`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`,`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_status`

#### Set custtom format:

## ⚡️ Quickstart
```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
LConsoleConfig: THorseLoggerConsoleConfig
LLogFileConfig: THorseLoggerConsoleConfig;
begin
LConsoleConfig := THorseLoggerConsoleConfig.New
LLogFileConfig := THorseLoggerConsoleConfig.New
.SetLogFormat('${request_clientip} [${time}] ${response_status}');
THorseLoggerManager.RegisterProvider(
THorseLoggerProviderLogFile.New(LConsoleConfig)
);
// 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);
end.
THorse.Get('/ping',
procedure(Req: THorseRequest; Res: THorseResponse; Next: TProc)
begin
Res.Send('pong');
end);
THorse.Listen(9000);
end;
```

## 📝 Output samples
Using default log formatting, the output will look something like this:
![image](https://user-images.githubusercontent.com/16382981/136378628-30c7fa6f-7d27-4faa-a8f9-7356b547099a.png)

## ⚠️ 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).

0 comments on commit 67d0aae

Please sign in to comment.