corneliusdavid 214 Posted August 19, 2021 I'm fairly new to RAD Server and while I have a small module working, pulling data from a database, I'd like to be able to do some logging. Sure, I can create another endpoint and dump stuff in a JSON result, but that's not really behind-the-scenes logging. And yes, I could create a log table and insert records in there. But there's an intriguing class in the EMS namespace called TEMSLoggingService. I can't find any documentation or examples that explain what this is for or how to use it. Anyone have any wisdom on this to share? Share this post Link to post
Lars Fosdal 1792 Posted August 19, 2021 There is documentation, but it is meagre on examples of use. http://docwiki.embarcadero.com/Libraries/Sydney/en/EMS.Services.TEMSLoggingService 1 Share this post Link to post
corneliusdavid 214 Posted August 19, 2021 I looked in DocWiki but could not find it. This is a start, albeit not much more than viewing the source. Thanks for the link! Share this post Link to post
mvanrijnen 123 Posted August 20, 2021 (edited) unit MyUnit; interface {$IFDEF RADSERVER_PACKAGE} uses ..... EMS.ResourceAPI; type THSLoggerRADServerDebugTargetQueue = class(THSLoggerBaseTargetQueue) protected function HandleTargetItem(const AItem: THSLLoggerItem): Boolean; override; public end; {$ENDIF} implementation {$IFDEF RADSERVER_PACKAGE} { THSLoggerRADServerDebugTargetQueue } function THSLoggerRADServerDebugTargetQueue.HandleTargetItem(const AItem: THSLLoggerItem): Boolean; var line: string; begin inherited; ..... TEMSEndpointEnvironment.Instance.LogMessage(line); .... end; {$ENDIF} end. Edited August 20, 2021 by mvanrijnen added code 1 Share this post Link to post
mvanrijnen 123 Posted August 20, 2021 (edited) Somehow inserting code goes wrong sometime, my text of my post disappeared. You just need the EMS.ResourceAPI in your uses and then you can use the TEMSEndPointEnvironment.Instance.LogMessage('your log text'); In debugmode (running your RADServer package from the IDE), the logging goes into the radserver console window, where the radserver itself also logs. We are not in production yet, so i do not know at the moment where the logging goes in a production environment 🙂 I use this in a logging framework, which also can log to file, database etc etc. Did not see the TEMSLoggingService before, have to inspect that, maybe it's the better way to work. [edit, added first code for the emsloggingservice) so, first tryout for the loggingservice: unit .......; interface uses ..... EMS.Services; type THSLoggerRADServerDebugTargetQueue = class(THSLoggerBaseTargetQueue) private femslogsvc : IEMSLoggingService; protected function HandleTargetItem(const AItem: THSLLoggerItem): Boolean; override; public procedure DoBeforeStart; override; procedure DoAfterStop; override; {TODO -oOwner -cGeneral : CheckCanStart wordt helemaal niet aangeroepen ???? } procedure CheckCanStart(var ACanStart: Boolean; var AMessage: string); override; end; implementation uses ....., EMS.ResourceAPI; { THSLoggerRADServerDebugTargetQueue } procedure THSLoggerRADServerDebugTargetQueue.CheckCanStart(var ACanStart: Boolean; var AMessage: string); begin inherited; ACanStart := True; end; procedure THSLoggerRADServerDebugTargetQueue.DoAfterStop; begin femslogsvc := nil; inherited; end; procedure THSLoggerRADServerDebugTargetQueue.DoBeforeStart; begin femslogsvc := nil; inherited; if TEMSServices.TryGetService<IEMSLoggingService>(femslogsvc) then begin if not femslogsvc.LoggingEnabled then begin femslogsvc := nil; end; end; end; function THSLoggerRADServerDebugTargetQueue.HandleTargetItem(const AItem: THSLLoggerItem): Boolean; var obj : TJSONObject; begin inherited; Result := False; try if Assigned(femslogsvc) then begin obj := TJSONObject.Create(); obj.AddPair('user', AItem.UserName); obj.AddPair('computer', AItem.ComputerName); obj.AddPair('datetime', DateToISO8601(AItem.DateTime)); obj.AddPair('message', AItem.LogMessage); obj.AddPair('position', AItem.Position); femslogsvc.Log(AItem.LogType.AsString, obj); end; Result := True; except on e: exception do begin // DebugLog('xx', 'xxxx'); end; end; end; end. Edited August 20, 2021 by mvanrijnen Share this post Link to post
corneliusdavid 214 Posted August 20, 2021 3 hours ago, mvanrijnen said: TEMSEndpointEnvironment.Instance.LogMessage(line); This is perfect--exactly what I was looking for! Thank you! I'll have to spend some time checking out your THSLoggerRADServerDebugTargetQueue class. That looks like it could useful as well. Thanks again! Share this post Link to post