1
0
mirror of https://github.com/loginov-dmitry/multithread.git synced 2024-11-24 08:52:15 +02:00

Ex SimpleLogger converted to Lazarus

This commit is contained in:
loginov-dmitry 2024-10-13 22:20:47 +03:00
parent 874714d5a4
commit 4aa4cad0fe
7 changed files with 205 additions and 8 deletions

2
.gitignore vendored
View File

@ -38,3 +38,5 @@ __history
/ExNotUseThreads/lib
/ExExceptions/backup
/ExExceptions/lib
/ExSync/ExEvent/SimpleLogger/lib
/ExSync/ExEvent/SimpleLogger/backup

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

View File

@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<SessionStorage Value="InProjectDir"/>
<Title Value="SimpleLoggerLaz"/>
<Scaled Value="True"/>
<ResourceType Value="res"/>
<UseXPManifest Value="True"/>
<XPManifest>
<DpiAware Value="True"/>
</XPManifest>
<Icon Value="0"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<RequiredPackages>
<Item>
<PackageName Value="LCL"/>
</Item>
</RequiredPackages>
<Units>
<Unit>
<Filename Value="SimpleLoggerLaz.lpr"/>
<IsPartOfProject Value="True"/>
</Unit>
<Unit>
<Filename Value="SimpleLoggerUnit.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="DemoLoggerForm"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
</Unit>
<Unit>
<Filename Value="..\..\..\CommonUtils\MTLogger.pas"/>
<IsPartOfProject Value="True"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="SimpleLoggerLaz"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<OtherUnitFiles Value="..\..\..\CommonUtils"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf3"/>
</Debugging>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

View File

@ -0,0 +1,24 @@
program SimpleLoggerLaz;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
{$IFDEF HASAMIGA}
athreads,
{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms, SimpleLoggerUnit, MTLogger;
{$R *.res}
begin
RequireDerivedFormResource:=True;
Application.Scaled:=True;
Application.Initialize;
Application.CreateForm(TDemoLoggerForm, DemoLoggerForm);
Application.Run;
end.

Binary file not shown.

View File

@ -0,0 +1,79 @@
object DemoLoggerForm: TDemoLoggerForm
Left = 0
Height = 288
Top = 0
Width = 635
Caption = 'Демонстрация записи в лог через дополнительный поток'
ClientHeight = 288
ClientWidth = 635
Color = clBtnFace
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'Tahoma'
OnCreate = FormCreate
OnDestroy = FormDestroy
Position = poScreenCenter
object Label1: TLabel
Left = 16
Height = 16
Top = 24
Width = 132
Caption = 'Добавить сообщений:'
end
object Label2: TLabel
Left = 24
Height = 32
Top = 96
Width = 457
Caption = 'Осторожно! Если Вы используете SSD, то построчная запись 10 тыс. строк в'#13#10'лог-файл может занять около минуты, в зависимости от модели SSD.'
Font.Color = clBlue
Font.Height = -13
Font.Name = 'Tahoma'
ParentFont = False
end
object Label3: TLabel
Left = 24
Height = 32
Top = 226
Width = 486
Caption = 'При записи в лог через доп. поток будет моментально записываться практически'#13#10'любой объём информации, даже 1 млн строк!'
Font.Color = clBlue
Font.Height = -13
Font.Name = 'Tahoma'
ParentFont = False
end
object Button1: TButton
Left = 16
Height = 25
Top = 67
Width = 425
Caption = 'Добавить сообщения в лог-файл без дополнительного потока'
TabOrder = 0
OnClick = Button1Click
end
object Edit1: TEdit
Left = 154
Height = 24
Top = 21
Width = 87
TabOrder = 1
Text = '10000'
end
object Button2: TButton
Left = 16
Height = 25
Top = 195
Width = 425
Caption = 'Добавить сообщения в лог-файл через дополнительный поток'
TabOrder = 2
OnClick = Button2Click
end
object cbCloseApp: TCheckBox
Left = 456
Height = 20
Top = 200
Width = 133
Caption = 'Закрыть программу'
TabOrder = 3
end
end

View File

@ -1,10 +1,13 @@
{$IFDEF FPC}{$CODEPAGE UTF8}{$H+}{$MODE DELPHI}{$ENDIF}
unit SimpleLoggerUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, SyncObjs, MTUtils, TimeIntervals, MTLogger;
{$IFDEF MSWINDOWS}Windows, Messages,{$ENDIF}
{$IFDEF FPC}LCLIntf, LCLType, LMessages,{$ENDIF}
SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, SyncObjs, MTUtils,
TimeIntervals, MTLogger;
type
TDemoLoggerForm = class(TForm)
@ -30,7 +33,11 @@ var
implementation
{$R *.dfm}
{$IFnDEF FPC}
{$R *.dfm}
{$ELSE}
{$R *.lfm}
{$ENDIF}
procedure TDemoLoggerForm.Button1Click(Sender: TObject);
var
@ -41,10 +48,10 @@ begin
AFileName := ExtractFilePath(Application.ExeName) + 'EventsNoThread.log';
ti.Start;
for I := 1 to StrToInt(Edit1.Text) do
WriteStringToTextFile(AFileName, Format('%s [P:%d T:%d] - Ñîáûòèå ¹%d',
WriteStringToTextFile(AFileName, Format('%s [P:%d T:%d] - Событие №%d',
[FormatDateTime('dd.mm.yyyy hh:nn:ss.zzz', Now), GetCurrentProcessId, GetCurrentThreadId, I]));
ShowMessageFmt('Âðåìÿ äîáàâëåíèÿ ñîáûòèé â ëîã-ôàéë: %d ìñ', [ti.ElapsedMilliseconds]);
ShowMessageFmt('Время добавления событий в лог-файл: %d мс', [ti.ElapsedMilliseconds]);
end;
procedure TDemoLoggerForm.Button2Click(Sender: TObject);
@ -54,16 +61,16 @@ var
begin
ti.Start;
for I := 1 to StrToInt(Edit1.Text) do
DefLogger.AddToLog(Format('Ñîáûòèå ¹%d', [I]));
DefLogger.AddToLog(Format('Событие №%d', [I]));
if cbCloseApp.Checked then
Close
else
ShowMessageFmt('Âðåìÿ äîáàâëåíèÿ ñîáûòèé â ëîã-ôàéë: %d ìñ', [ti.ElapsedMilliseconds]);
ShowMessageFmt('Время добавления событий в лог-файл: %d мс', [ti.ElapsedMilliseconds]);
end;
procedure TDemoLoggerForm.FormCreate(Sender: TObject);
begin
AllowMessageBoxIfError := True; // Òîëüêî â äåìîíñòðàöèîííûõ öåëÿõ!!!
AllowMessageBoxIfError := True; // Только в демонстрационных целях!!!
CreateDefLogger(ExtractFilePath(Application.ExeName) + 'EventsInThread.log');
end;