delphimvcframework/samples/rest_logs_collector/LogsCollectorControllerU.pas
Daniele Teti 55500acdf9 Squashed 'lib/loggerpro/' content from commit d1e0db6e
git-subtree-dir: lib/loggerpro
git-subtree-split: d1e0db6e93724e5fd825f0a8c02151d60450f98f
2023-02-27 12:26:25 +01:00

57 lines
1.3 KiB
ObjectPascal

unit LogsCollectorControllerU;
interface
uses
MVCFramework,
MVCFramework.Commons;
type
[MVCPath('/api')]
TLogsCollectorController = class(TMVCController)
public
[MVCPath('/logs/($logtag)/($logtype)')]
[MVCHTTPMethod([httpPOST])]
[MVCConsumes(TMVCMediaType.TEXT_PLAIN)]
procedure Logs(const logtag, logtype: string);
protected
procedure OnBeforeAction(Context: TWebContext; const AActionName: string; var Handled: Boolean); override;
procedure OnAfterAction(Context: TWebContext; const AActionName: string); override;
public
end;
implementation
uses
System.SysUtils,
System.StrUtils,
LoggerProConfig,
LoggerPro;
procedure TLogsCollectorController.Logs(const logtag, logtype: string);
var
lLogType: TLogType;
begin
lLogType := LoggerPro.StringToLogType(logtype);
Log.Log(lLogType, Context.Request.Body, logtag);
end;
procedure TLogsCollectorController.OnAfterAction(Context: TWebContext; const AActionName: string);
begin
{ Executed after each action }
inherited;
end;
procedure TLogsCollectorController.OnBeforeAction(Context: TWebContext; const AActionName: string; var Handled: Boolean);
begin
{ Executed before each action
if handled is true (or an exception is raised) the actual
action will not be called }
inherited;
end;
end.