#1 2017-03-23 20:32:58

AlexZ
Member
Registered: 2017-03-23
Posts: 2

How to use SynLog like log4PHP or log4J?

Hi,
is it possible to use SynLog like log4PHP / log4J? (Database Appender, Mail Appender) Or is TSynLog's use case only for text-file logging?

The only customizing option is EchoCustom, is there an example how to integrate a log4D implementation?

Regards
Alex

Offline

#2 2017-03-24 08:05:46

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,183
Website

Re: How to use SynLog like log4PHP or log4J?

EchoCustom is able to redirect the output, to any mean of transmission; you can register several EchoCustom methods, on need.
You have TCP redirection using https://synopse.info/files/html/Synopse … l#TITL_104
You have WebSockets real-time redirection via IAdministratedDaemon.SubscribeLog() and its callback.
For email appender, you have SendEmail in SynCrtSock.

You have even a syslog redirection - see e.g. the TDDDAppSettingsAbstract.SyslogEvent method.
For log gathering (e.g. in a server farm), this SysLog UDP transmission is the best option, and has several server (Open Source) tools, with proper database storage - see e.g. https://www.graylog.org/

There is no example to integrate to a Log4j/Log4* process.
Log4j has a hierarchy of categories, whereas we defined a set of levels, with much better granularity, and unique features (like integrated stack trace or method profiling).
Log4d/Log4Php are just one-by-one translation of Log4j.
BTW Log4d performance is far lower.
We don't feature Log4j compatibility, because we never found its design complex and limited - even if it is perhaps the most widely used.

We don't support raw TSynLog database append, because we have a much better approach with SOA methods.
See https://synopse.info/files/html/Synopse … l#TITL_183

Offline

#3 2017-03-24 14:43:20

AlexZ
Member
Registered: 2017-03-23
Posts: 2

Re: How to use SynLog like log4PHP or log4J?

We are not using the framework, only the TSynLog - class itselfs. Maybe later we will switch to the framework.

Our use case (by customer security and application requirements) is that different log entries identified by levels have to be written into separate log-files.
The only approach so far i got working as expected is the following:

type
  TXLog = class(TSynLog);
  TYLog = class(TSynLog);
var
  XLog: TSynLogClass = TXLog;
  YLog: TSynLogClass = TYLog;
...

  TXLog.Family.Level          := LOG_VERBOSE;
  TXLog.Family.CustomFileName := 'XLog';

  TYLog.Family.Level          := [sllUserAuth];
  TYLog.Family.CustomFileName := 'YLog';

  TXLog.Add.Log(sllInfo, 'Starting x');
  TXLog.Add.Log(sllSQL, 'SQL');

  TYLog.Add.Log(sllInfo, 'Starting y'); // Will not be written
  TYLog.Add.Log(sllUserAuth, 'User Auth');

Offline

#4 2017-03-24 15:37:53

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,183
Website

Re: How to use SynLog like log4PHP or log4J?

Yes, one class per log instance.

Because in a multi-threaded app with one log file per thread, you may have several TSynLog instances.
So logging setup is gathered by class.

I agree this is not the best design ever...
A dedicated class instead of using the class type may have been better.

Offline

Board footer

Powered by FluxBB