Coder Social home page Coder Social logo

horse-logger-provider-console's Introduction

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 - Official middleware for logging in APIs developed with the Horse framework.
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 command:

$ 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:

  • Delphi
  • 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

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

{$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: image

⚠️ License

horse-logger-provider-console is free and open-source middleware licensed under the MIT License.

horse-logger-provider-console's People

Contributors

andre-djsystem avatar leandrobtu avatar viniciussanchez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

leandrobtu

horse-logger-provider-console's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.