#1 2024-01-01 22:24:59

tbo
Member
Registered: 2015-04-20
Posts: 335

TSynDaemon.AfterCreate()

I have switched to the latest mORMot2 version. The following source code has worked so far. Two log files are now created. One for TSynLog and one for TVGServerLog.

type
  TVGServerLog = class(TSynLog)
  protected
    procedure ComputeFileName; override;
  end;

constructor TVGServerDaemon.Create;
begin
  inherited Create(TVGServerSettings, ...
  Settings.LogPath := TFileUtils.GetLogFileFolder(TVGServerSettings(Settings).ServerID);
  Settings.SetLog(TVGServerLog);

Now TSynDaemon.AfterCreate must be overwritten. Name AfterCreate() does not really say what is being done. Perhaps a name like SetLogClassAfterCreate() would be more descriptive. If the LogClass has already been assigned in TSynDaemonSettings Create, it will be overwritten in AfterCreate(). Maybe check for Nil:

procedure TSynDaemon.AfterCreate;
begin
  if RunFromSynTests then
    fSettings.fLogClass := TSynLog // share the same TSynLog for all daemons
  else if fSettings.LogClass = Nil then
    fSettings.SetLog(TSynLog); // real world logging
end;

Best wishes and a Happy New Year 2024 to all.

With best regards
Thomas

Offline

#2 2024-01-02 09:04:14

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

Re: TSynDaemon.AfterCreate()

Renaming may not be the best idea because this method is virtual, and its behavior could change when overridden.
This was one point of its introduction: you could change the default behavior, but by default logging is enabled.
So renaming may not be an option.

I have enhanced the documentation to emphasize this breaking change:
https://github.com/synopse/mORMot2/commit/50eaf926

Offline

Board footer

Powered by FluxBB