1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921
|
unit AdminServerLogs;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, InstanceSections, ComCtrls, StdCtrls, Grids, ImgList, DateUtils,
ExtCtrls, PNGImage, AuxFuncs, myx_admin_public_interface,
myx_public_interface, TntExtCtrls, Menus, TntMenus, TntComCtrls,
TntStdCtrls, TntDialogs, AdminService,
ApplicationDataModule, MySQLConnection, MyxError,
StrUtils;
type
TAdminServerLogsForm = class(TInstanceSectionForm)
ServerLogsPnl: TTntPanel;
ServerLogPageControl: TTntPageControl;
ErrorLogTabSheet: TTabSheet;
SlowLogTabSheet: TTabSheet;
QueryTabSheet: TTabSheet;
HeaderPnl: TTntPanel;
ErrorBevel: TTntBevel;
HeaderLbl: TTntLabel;
HeaderImg: TTntImage;
BottomPnl: TTntPanel;
LogImageList: TImageList;
Label1: TTntLabel;
MemoPopupMenu: TTntPopupMenu;
SearchMI: TTntMenuItem;
SaveMI: TTntMenuItem;
SearchNextMI: TTntMenuItem;
N1: TTntMenuItem;
LogBrowsePnl: TTntPanel;
PagesPaintBox: TTntPaintBox;
ErrorLogMemo: TTntRichEdit;
ErrorLogEventListView: TTntListView;
LogBlockUpDown: TTntUpDown;
Label2: TTntLabel;
EventsLbl: TTntLabel;
Label4: TTntLabel;
LocalhostOnlyPnl: TTntPanel;
Label3: TTntLabel;
OpenErrorFileBtn: TTntButton;
SearchBtn: TTntButton;
Button2: TTntButton;
RefreshBtn: TTntButton;
SubTreePnl: TTntPanel;
ServicesTreeView: TTntTreeView;
Panel2: TTntPanel;
Label15: TTntLabel;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure DisplayLogFileBlock(BlockNr: Integer);
procedure PagesPaintBoxPaint(Sender: TObject);
procedure LogBlockUpDownClick(Sender: TObject; Button: TUDBtnType);
procedure PagesPaintBoxMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure ErrorLogEventListViewClick(Sender: TObject);
procedure SetCaretPos(Edit: TTntRichEdit; const Value: TPoint);
procedure GetLogFileNames;
procedure DoFind(Sender: TObject);
procedure ErrorLogMemoKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure SearchMIClick(Sender: TObject);
procedure SearchNextMIClick(Sender: TObject);
procedure MemoPopupMenuPopup(Sender: TObject);
procedure SaveMIClick(Sender: TObject);
procedure SearchDoClose(Sender: TObject);
procedure SearchDoShow(Sender: TObject);
procedure ServerLogPageControlChange(Sender: TObject);
procedure RefreshBtnClick(Sender: TObject);
procedure ConnectionLost(var Message: TMessage); message WM_CONNECTION_LOST;
procedure ConnectionEstablished(var Message: TMessage); message WM_CONNECTION_ESTABLISHED;
procedure InitializeControls; override;
procedure OpenErrorFileBtnClick(Sender: TObject);
procedure MenuMeasureItem(Sender: TObject; ACanvas: TCanvas; var Width, Height: Integer);
procedure MenuDrawItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect; State: TOwnerDrawState);
procedure ServicesTreeViewDeletion(Sender: TObject; Node: TTreeNode);
procedure ServicesTreeViewChange(Sender: TObject; Node: TTreeNode);
private
FHeaderPNGImg: TPNGObject;
FLogBarEmptyPNGImg: TPNGObject;
FLogBarFilledPNGImg: TPNGObject;
FLogBarFilledTopPNGImg: TPNGObject;
FErrorLogFileName: WideString;
FSlowLogFileName: WideString;
FQueryLogFileName: WideString;
procedure RefreshServiceList;
procedure SetCurrentService(MySQLService: TMySQLService);
procedure ChangeCurrentService(ServiceName: WideString = '');
protected
procedure ActivateSection; override;
public
FindDialog: TFindDialog;
end;
type
PInteger = ^integer;
TCharRange = record
cpMin: Longint;
cpMax: LongInt;
end;
const
EM_EXSETSEL = WM_USER + 55;
EM_SCROLLCARET = $00B7;
EM_LINESCROLL = $00B6;
FetchedBlockSizeErrorLog = 20480;
FetchedBlockSizeSlowLog = 20480;
FetchedBlockSizeGeneralLog = 40960;
var
AdminServerLogsForm: TAdminServerLogsForm;
//----------------------------------------------------------------------------------------------------------------------
implementation
{$R *.dfm}
uses
PNGTools, gnugettext;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminServerLogsForm.FormCreate(Sender: TObject);
begin
InitForm(self);
DockedPanel := ServerLogsPnl;
SubTreePanel := SubTreePnl;
FHeaderPNGImg := LoadPNGImageFromResource('server_logs', HeaderImg);
FLogBarEmptyPNGImg := LoadPNGImageFromResource('log_bar_empty');
FLogBarFilledPNGImg := LoadPNGImageFromResource('log_bar_filled');
FLogBarFilledTopPNGImg := LoadPNGImageFromResource('log_bar_filled_top');
ServerLogPageControl.ActivePageIndex := 0;
FindDialog := nil;
LocalhostOnlyPnl.Visible := not (MySQLConn.IsLocalServer or ApplicationDM.Options.ShowOnlyServiceSections);
DisableEnablePages(ServerLogPageControl, MySQLConn.IsLocalServer or ApplicationDM.Options.ShowOnlyServiceSections);
RefreshServiceList;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminServerLogsForm.FormDestroy(Sender: TObject);
begin
FHeaderPNGImg.Free;
FLogBarEmptyPNGImg.Free;
FLogBarFilledPNGImg.Free;
FLogBarFilledTopPNGImg.Free;
ClearListView(ErrorLogEventListView, myx_ndt_pointer);
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminServerLogsForm.GetLogFileNames;
// Attempts to get the file names of all activated log files. If the particular file does not exist then its name is
// not stored, just as wouldn't it be enabled at all.
var
Size: Cardinal;
Buffer: array[0..MAX_PATH] of WideChar;
ComputerName: WideString;
begin
if MySQLConn.IsLocalServer or ApplicationDM.Options.ShowOnlyServiceSections then
begin
Size := SizeOf(Buffer);
GetComputerNameW(Buffer, Size);
SetString(ComputerName, Buffer, Size);
// Log file can be check-only (i.e. no file name given, but just enabled).
// In this case construct the same log file names as the server would do.
FErrorLogFileName := ApplicationDM.GetPathFromConfig('log-error');
if FErrorLogFileName = 'checked' then
FErrorLogFileName := ApplicationDM.DataDir + ComputerName + '.err';
if not FileExists(FErrorLogFileName) then
FErrorLogFileName := '';
FSlowLogFileName := ApplicationDM.GetPathFromConfig('log-slow-queries');
if FSlowLogFileName = 'checked' then
FSlowLogFileName := ApplicationDM.DataDir + ComputerName + '-slow.log';
if not FileExists(FSlowLogFileName) then
FSlowLogFileName := '';
FQueryLogFileName := ApplicationDM.GetPathFromConfig('log');
if FQueryLogFileName = 'checked' then
FQueryLogFileName := ApplicationDM.DataDir + ComputerName + '.log';
if not FileExists(FQueryLogFileName) then
FQueryLogFileName := '';
end
else
begin
FErrorLogFileName := '';
FSlowLogFileName := '';
FQueryLogFileName := '';
end;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminServerLogsForm.DisplayLogFileBlock(BlockNr: Integer);
var
pLogFile: PMYX_LOGFILE;
LogFile: TMYX_LOGFILE;
LastBlock: integer;
i: integer;
EventCaption: WideString;
EventDateTime: TDateTime;
IconNr: integer;
PInt: PInteger;
Item: TListItem;
LogFileName: WideString;
begin
case ServerLogPageControl.ActivePageIndex of
0:
LogFileName := FErrorLogFileName;
1:
LogFileName := FSlowLogFileName;
2:
LogFileName := FQueryLogFileName;
else
Exit;
end;
if (LogFileName='') or not FileExists(LogFileName) then
begin
DisableEnableControls(ServerLogPageControl.ActivePage, False);
ClearListView(ErrorLogEventListView, myx_ndt_pointer);
ErrorLogMemo.Text := '';
EventsLbl.Caption := 'Events:';
Exit;
end;
case ServerLogPageControl.ActivePageIndex of
0:
pLogFile := myx_parse_error_log(LogFileName, FetchedBlockSizeErrorLog, BlockNr, @LastBlock);
1:
pLogFile := myx_parse_slow_log(LogFileName, FetchedBlockSizeSlowLog, BlockNr, @LastBlock);
2:
pLogFile := myx_parse_general_log(LogFileName, FetchedBlockSizeGeneralLog, BlockNr, @LastBlock);
else
pLogFile := nil;
end;
if pLogFile = nil then
begin
DisableEnableControls(ServerLogPageControl.ActivePage, False);
ClearListView(ErrorLogEventListView, myx_ndt_pointer);
ErrorLogMemo.Text := '';
EventsLbl.Caption := 'Events:';
raise EMyxError.Create('Errorlog could not be parsed.');
end;
DisableEnableControls(ServerLogPageControl.ActivePage, True);
LogFile := TMYX_LOGFILE.Create(pLogFile);
try
ErrorLogEventListView.Items.BeginUpdate;
try
ClearListView(ErrorLogEventListView, myx_ndt_pointer);
ErrorLogEventListView.Clear;
for i := 0 to LogFile.events.Count-1 do
begin
IconNr := -1;
EventCaption := '';
case LogFile.events[i].event_type of
MYX_EVENT_START:
begin
EventCaption := 'Startup';
IconNr := 0;
end;
MYX_EVENT_END:
begin
EventCaption := 'Shutdown';
IconNr := 1;
end;
MYX_EVENT_ERROR:
begin
EventCaption := 'Error';
IconNr := -1;
end;
MYX_EVENT_INNODB_START:
begin
EventCaption := 'InnoDB Startup';
IconNr := 0;
end;
MYX_EVENT_INNODB_SHUTDOWN:
begin
EventCaption := 'InnoDB Shutdown';
IconNr := 1;
end;
MYX_EVENT_FORCED_CLOSE_THREAD:
begin
EventCaption := 'Thread closed';
IconNr := 1;
end;
MYX_EVENT_ABORT:
begin
EventCaption := 'Abort';
IconNr := 1;
end;
MYX_EVENT_SELECT:
begin
EventCaption := 'Select';
IconNr := 1;
end;
MYX_EVENT_INIT:
begin
EventCaption := 'Init DB';
IconNr := 1;
end;
MYX_EVENT_CONNECT:
begin
EventCaption := 'Connect';
IconNr := 1;
end;
MYX_EVENT_QUIT:
begin
EventCaption := 'Quit';
IconNr := 1;
end;
MYX_EVENT_QUERY:
begin
EventCaption := 'Query';
IconNr := 1;
end;
end;
if(LogFile.events[i].date<>nil)then
begin
TryEncodeDateTime(LogFile.events[i].date.tm_year+2000,
LogFile.events[i].date.tm_mon,
LogFile.events[i].date.tm_mday,
LogFile.events[i].date.tm_hour,
LogFile.events[i].date.tm_min,
LogFile.events[i].date.tm_sec,
0,
EventDateTime);
GetMem(PInt, SizeOf(integer));
PInt^ := LogFile.events[i].line_no-1;
Item := AddListViewItem(ErrorLogEventListView, nil,
FormatDateTime('dd mmm hh:nn', EventDateTime), IconNr, PInt);
Item.SubItems.Add(EventCaption);
end
else
begin
GetMem(PInt, SizeOf(integer));
PInt^ := LogFile.events[i].line_no-1;
AddListViewItem(ErrorLogEventListView, nil,
' '+EventCaption, IconNr, PInt);
end;
end;
finally
ErrorLogEventListView.Items.EndUpdate;
end;
ErrorLogMemo.HandleNeeded;
ErrorLogMemo.Text := LogFile.lines.text;
//Scroll to end
SendMessage(ErrorLogMemo.Handle, WM_VSCROLL, SB_BOTTOM, 0);
SendMessage(ErrorLogEventListView.Handle, WM_VSCROLL, SB_BOTTOM, 0);
LogBlockUpDown.Min := 1;
LogBlockUpDown.Max := LogFile.block_num+1;
LogBlockUpDown.Position := BlockNr;
EventsLbl.Caption := 'Events of page '+IntToStr(LogFile.block_num-BlockNr+2)+
' / '+IntToStr(LogFile.block_num+1)+':';
PagesPaintBox.Repaint;
finally
myx_free_logfile(pLogFile);
LogFile.Free;
end;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminServerLogsForm.PagesPaintBoxPaint(Sender: TObject);
var
i: Integer;
x: Integer;
PagesNr: Integer;
CurrentPage: Integer;
begin
PagesNr := LogBlockUpDown.Max;
CurrentPage := LogBlockUpDown.Position;
//At least one page
if(PagesNr=0)then
PagesNr := 1;
with PagesPaintBox.Canvas do
begin
//Pen.Color := $00CB8B64;
Pen.Color := $00B2ACA5;
MoveTo(0, 0);
LineTo(0, PagesPaintBox.Height-1);
LineTo(PagesPaintBox.Width-1, PagesPaintBox.Height-1);
LineTo(PagesPaintBox.Width-1, 0);
LineTo(0, 0);
FLogBarEmptyPNGImg.Draw(PagesPaintBox.Canvas,
Rect(1, 1, PagesPaintBox.Width-1, 16));
Pen.Color := $00BA3F01;
for i := 0 to PagesNr-1 do
begin
x := Round((PagesPaintBox.Width/PagesNr)*i);
MoveTo(x, 1);
LineTo(x, PagesPaintBox.Height-1);
end;
x := Round((PagesPaintBox.Width/PagesNr)*(PagesNr-CurrentPage));
FLogBarFilledTopPNGImg.Draw(PagesPaintBox.Canvas,
Rect(x, 1, x+3, 16));
FLogBarFilledPNGImg.Draw(PagesPaintBox.Canvas,
Rect(x+3, 1,
Round((PagesPaintBox.Width/PagesNr)*(PagesNr-CurrentPage+1)), 16));
Pen.Color := $00CB8B64;
Brush.Color := $00D7D0D0;
end;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminServerLogsForm.LogBlockUpDownClick(Sender: TObject; Button: TUDBtnType);
begin
if(LogBlockUpDown.Position>0)then
DisplayLogFileBlock(LogBlockUpDown.Position);
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminServerLogsForm.PagesPaintBoxMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X,
Y: Integer);
begin
if(Button=mbLeft)then
begin
if(LogBlockUpDown.Max>0)then
LogBlockUpDown.Position := LogBlockUpDown.Max-
Trunc(X/(PagesPaintBox.Width/LogBlockUpDown.Max));
DisplayLogFileBlock(LogBlockUpDown.Position);
end;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminServerLogsForm.ErrorLogEventListViewClick(Sender: TObject);
var
CaretPos: TPoint;
begin
if(ErrorLogEventListView.Selected<>nil)then
if(ErrorLogEventListView.Selected.Data<>nil)then
begin
CaretPos.Y := PInteger(ErrorLogEventListView.Selected.Data)^;
CaretPos.X := 0;
SetCaretPos(ErrorLogMemo, CaretPos);
if(ServerLogPageControl.ActivePageIndex=1)then
ErrorLogMemo.SelLength := 6
else
ErrorLogMemo.SelLength := 15;
ErrorLogMemo.SetFocus;
end;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminServerLogsForm.SetCaretPos(Edit: TTntRichEdit; const Value: TPoint);
var
CharRange: TCharRange;
begin
CharRange.cpMin := SendMessage(Edit.Handle, EM_LINEINDEX, Value.y, 0) + Value.x;
CharRange.cpMax := CharRange.cpMin;
SendMessage(Edit.Handle, EM_EXSETSEL, 0, Longint(@CharRange));
//SendMessage(Edit.Handle, EM_LINESCROLL, 0, Edit.Lines.Count - 1);
SendMessage(Edit.Handle, WM_VSCROLL, SB_BOTTOM, 0);
SendMessage(Edit.Handle, EM_SCROLLCARET, 0, 0);
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminServerLogsForm.DoFind(Sender: TObject);
var
FoundAt: LongInt;
StartPos, ToEnd: Integer;
SearchType: TSearchTypes;
begin
with ErrorLogMemo do
begin
{ begin the search after the current selection if there is one }
{ otherwise, begin at the start of the text }
if SelLength <> 0 then
StartPos := SelStart + SelLength
else
StartPos := 0;
{ ToEnd is the length from StartPos to the end of the text in the rich edit control }
ToEnd := Length(Text) - StartPos;
SearchType := [];
if(frWholeWord in TFindDialog(Sender).Options)then
SearchType := SearchType+[stWholeWord];
if(frMatchCase in TFindDialog(Sender).Options)then
SearchType := SearchType+[stMatchCase];
FoundAt := FindText(TFindDialog(Sender).FindText, StartPos, ToEnd, SearchType);
if FoundAt <> -1 then
begin
SetFocus;
SelStart := FoundAt;
SelLength := Length(TFindDialog(Sender).FindText);
end;
SendMessage(ErrorLogMemo.Handle, WM_VSCROLL, SB_BOTTOM, 0);
SendMessage(ErrorLogMemo.Handle, EM_SCROLLCARET, 0, 0);
end;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminServerLogsForm.ErrorLogMemoKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if((Key=Ord('F'))and(ssCtrl in Shift))then
SearchMIClick(self);
if(Key=VK_F3)and(FindDialog<>nil)then
DoFind(FindDialog);
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminServerLogsForm.SearchMIClick(Sender: TObject);
begin
if(FindDialog=nil)then
begin
FindDialog := TFindDialog.Create(self);
FindDialog.Options := [frHideUpDown];
FindDialog.OnFind := DoFind;
FindDialog.OnShow := SearchDoShow;
FindDialog.OnClose := SearchDoClose;
FindDialog.Execute;
end;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminServerLogsForm.SearchDoClose(Sender: TObject);
begin
FindDialog := nil;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminServerLogsForm.SearchDoShow(Sender: TObject);
begin
SetWindowPos(TFindDialog(Sender).Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOSIZE);
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminServerLogsForm.SearchNextMIClick(Sender: TObject);
begin
if(FindDialog<>nil)then
DoFind(FindDialog);
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminServerLogsForm.MemoPopupMenuPopup(Sender: TObject);
begin
SearchNextMI.Enabled := (FindDialog<>nil);
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminServerLogsForm.SaveMIClick(Sender: TObject);
var
SaveDialog: TTntSaveDialog;
begin
SaveDialog := TTntSaveDialog.Create(self);
try
SaveDialog.Title := 'Save Log File Block';
SaveDialog.Filter := '*.txt|Text Files';
SaveDialog.FileName := 'ErrorLog.txt';
if(SaveDialog.Execute)then
begin
ErrorLogMemo.PlainText := True;
ErrorLogMemo.Lines.SaveToFile(SaveDialog.FileName);
end;
finally
SaveDialog.Free;
end;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminServerLogsForm.ServerLogPageControlChange(Sender: TObject);
var
ListColumn: TListColumn;
begin
HeaderLbl.Caption := ServerLogPageControl.ActivePage.Caption;
HeaderPnl.Parent := ServerLogPageControl.ActivePage;
LogBrowsePnl.Parent := ServerLogPageControl.ActivePage;
BottomPnl.Parent := ServerLogPageControl.ActivePage;
if ServerLogPageControl.ActivePage = SlowLogTabSheet then
begin
if ErrorLogEventListView.Columns.Count > 1 then
ErrorLogEventListView.Columns.Delete(1);
ErrorLogEventListView.Columns[0].AutoSize := True;
ErrorLogEventListView.Columns[0].Width := 200;
ErrorLogEventListView.Columns[0].Caption := _('Log entry');
end
else
begin
if(ErrorLogEventListView.Columns.Count<2)then
begin
ErrorLogEventListView.Columns[0].AutoSize := False;
ErrorLogEventListView.Columns[0].Width := 90;
ErrorLogEventListView.Columns[0].Caption := _('Time');
ListColumn := ErrorLogEventListView.Columns.Add;
ListColumn.Width := 110;
ListColumn.Caption := _('Log entry');
end;
end;
if MySQLConn.IsLocalServer or ApplicationDM.Options.ShowOnlyServiceSections then
DisplayLogFileBlock(1);
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminServerLogsForm.RefreshServiceList;
var
LastService: WideString;
begin
if Assigned(ApplicationDM.CurrentService) then
LastService := ApplicationDM.CurrentService.ServiceName;
SetCurrentService(nil);
ServicesTreeView.Items.Clear;
// Get all MySQL Services.
ScanForServices(ServicesTreeView, ServicesImageIndex);
ChangeCurrentService(LastService);
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminServerLogsForm.ActivateSection;
begin
inherited;
ChangeCurrentService;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminServerLogsForm.ChangeCurrentService(ServiceName: WideString);
var
I: Integer;
begin
// Activate the last selected service or the first one if none was before.
if ServicesTreeView.Items.Count > 0 then
begin
if (ServiceName = '') and Assigned(ApplicationDM.CurrentService) then
ServiceName := ApplicationDM.CurrentService.ServiceName;
I := SelectService(ServicesTreeview, ServiceName);
if I = -1 then
I := 0;
SetCurrentService(ServicesTreeView.Items[I].Data);
ServicesTreeView.Selected := ServicesTreeView.Items[I];
end;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminServerLogsForm.SetCurrentService(MySQLService: TMySQLService);
begin
ApplicationDM.CurrentService := MySQLService;
GetLogFileNames;
DisplayLogFileBlock(1);
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminServerLogsForm.ServicesTreeViewChange(Sender: TObject; Node: TTreeNode);
begin
if not InitControls then
begin
ApplicationDM.CurrentService := nil;
if (ServicesTreeView.Selected <> nil) then
if (ServicesTreeView.Selected.Data <> nil) then
ApplicationDM.CurrentService := TMySQLService(ServicesTreeView.Selected.Data);
SetCurrentService(ApplicationDM.CurrentService);
end;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminServerLogsForm.ServicesTreeViewDeletion(Sender: TObject; Node: TTreeNode);
begin
if not (csRecreating in ServicesTreeView.ControlState) then
begin
if Node.Data = ApplicationDM.CurrentService then
SetCurrentService(nil);
TObject(Node.Data).Free;
end;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminServerLogsForm.RefreshBtnClick(Sender: TObject);
begin
DisplayLogFileBlock(LogBlockUpDown.Position);
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminServerLogsForm.ConnectionLost(var Message: TMessage);
begin
GetLogFileNames;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminServerLogsForm.ConnectionEstablished(var Message: TMessage);
begin
GetLogFileNames;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminServerLogsForm.InitializeControls;
begin
if MySQLConn.IsLocalServer then
DisplayLogFileBlock(1);
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminServerLogsForm.OpenErrorFileBtnClick(Sender: TObject);
var
OpenDialog: TTntOpenDialog;
begin
OpenDialog := TTntOpenDialog.Create(self);
try
OpenDialog.Title := 'Open Error Log File ...';
OpenDialog.Filter := 'Error log file|*.*';
OpenDialog.InitialDir := ApplicationDM.GetLastFileDialogPaths('ErrorLogFile');
if(OpenDialog.Execute)then
begin
ApplicationDM.SetLastFileDialogPaths('ErrorLogFile',
ExtractFilePath(OpenDialog.FileName));
case ServerLogPageControl.ActivePageIndex of
0:
FErrorLogFileName := OpenDialog.FileName;
1:
FSlowLogFileName := OpenDialog.FileName;
2:
FQueryLogFileName := OpenDialog.FileName;
end;
DisplayLogFileBlock(1);
end;
finally
OpenDialog.Free;
end;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminServerLogsForm.MenuMeasureItem(Sender: TObject; ACanvas: TCanvas; var Width, Height: Integer);
var
Size: TSize;
Item: TTntMenuItem;
begin
if Sender is TTntMenuItem then
begin
Item := Sender as TTntMenuItem;
ACanvas.Font := Font;
if Item.IsLine then
begin
Width := 10; // This will actually have no effect, because other entries are much wider.
Height := 6;
end
else
begin
GetTextExtentPoint32W(ACanvas.Handle, PWideChar(Item.Caption), Length(Item.Caption), Size);
// Border around each entry.
Width := Size.cx + 4;
Height := Size.cy + 6;
end;
end;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TAdminServerLogsForm.MenuDrawItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect; State: TOwnerDrawState);
var
Item: TTntMenuItem;
begin
if Sender is TTntMenuItem then
begin
Item := Sender as TTntMenuItem;
ACanvas.Font := Font;
if Item.IsLine then
begin
// A menu separator.
ACanvas.Pen.Color := clBtnShadow;
ACanvas.MoveTo(ARect.Left + 2, (ARect.Bottom + ARect.Top) div 2);
ACanvas.LineTo(ARect.Right - 2, (ARect.Bottom + ARect.Top) div 2);
end
else
begin
// Top level items have an invisible parent, so have to check the parent of the parent.
if (Item.Parent.Parent = nil) and not (Item.GetParentMenu is TPopupMenu) then
begin
if [odHotLight, odSelected] * State <> [] then
ACanvas.Brush.Color := clHighlight
else
ACanvas.Brush.Color := clBtnFace;
end;
ACanvas.FillRect(ARect);
Inc(ARect.Left, 8);
SetBKMode(ACanvas.Handle, TRANSPARENT);
Windows.DrawTextW(ACanvas.Handle, PWideChar(Item.Caption), Length(Item.Caption), ARect, DT_LEFT + DT_SINGLELINE +
DT_HIDEPREFIX + DT_VCENTER);
end;
end;
end;
//----------------------------------------------------------------------------------------------------------------------
end.
|