1(* 2Used by: 3- LazLogger 4- LazLoggerBase 5- LazLoggerDummy 6*) 7 8 9procedure DebuglnStack(const s: string); 10begin 11 {$IFnDEF LazLoggerDummy} 12 DebugLogger.DebuglnStack(s); 13 {$ENDIF} 14end; 15 16procedure DbgOut(const s: string); 17begin 18 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 19 DebugLogger.DbgOut(s); 20 {$ENDIF} 21end; 22 23procedure DbgOut(Args: array of const); 24begin 25 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 26 DebugLogger.DbgOut(Args); 27 {$ENDIF} 28end; 29 30procedure DbgOut(const S: String; Args: array of const); 31begin 32 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 33 DebugLogger.DbgOut(S, Args); 34 {$ENDIF} 35end; 36 37procedure DbgOut(const s1, s2: string; const s3: string; const s4: string; const s5: string; 38 const s6: string; const s7: string; const s8: string; const s9: string; const s10: string; 39 const s11: string; const s12: string; const s13: string; const s14: string; 40 const s15: string; const s16: string; const s17: string; const s18: string); 41begin 42 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 43 DebugLogger.DbgOut(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18); 44 {$ENDIF} 45end; 46 47procedure DebugLn(const s: string); 48begin 49 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 50 DebugLogger.DebugLn(s); 51 {$ENDIF} 52end; 53 54procedure DebugLn(Args: array of const); 55begin 56 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 57 DebugLogger.DebugLn(Args); 58 {$ENDIF} 59end; 60 61procedure DebugLn(const S: String; Args: array of const); 62begin 63 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 64 DebugLogger.DebugLn(S, Args); 65 {$ENDIF} 66end; 67 68procedure DebugLn(const s1, s2: string; const s3: string; const s4: string; const s5: string; 69 const s6: string; const s7: string; const s8: string; const s9: string; const s10: string; 70 const s11: string; const s12: string; const s13: string; const s14: string; 71 const s15: string; const s16: string; const s17: string; const s18: string); 72begin 73 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 74 DebugLogger.DebugLn(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18); 75 {$ENDIF} 76end; 77 78procedure DebugLnEnter(const s: string); 79begin 80 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 81 DebugLogger.DebugLnEnter(s); 82 {$ENDIF} 83end; 84 85procedure DebugLnEnter(Args: array of const); 86begin 87 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 88 DebugLogger.DebugLnEnter(Args); 89 {$ENDIF} 90end; 91 92procedure DebugLnEnter(s: string; Args: array of const); 93begin 94 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 95 DebugLogger.DebugLnEnter(s, Args); 96 {$ENDIF} 97end; 98 99procedure DebugLnEnter(const s1, s2: string; const s3: string; const s4: string; 100 const s5: string; const s6: string; const s7: string; const s8: string; const s9: string; 101 const s10: string; const s11: string; const s12: string; const s13: string; 102 const s14: string; const s15: string; const s16: string; const s17: string; 103 const s18: string); 104begin 105 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 106 DebugLogger.DebugLnEnter(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18); 107 {$ENDIF} 108end; 109 110procedure DebugLnExit(const s: string); 111begin 112 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 113 DebugLogger.DebugLnExit(s); 114 {$ENDIF} 115end; 116 117procedure DebugLnExit(Args: array of const); 118begin 119 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 120 DebugLogger.DebugLnExit(Args); 121 {$ENDIF} 122end; 123 124procedure DebugLnExit(s: string; Args: array of const); 125begin 126 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 127 DebugLogger.DebugLnExit(s, Args); 128 {$ENDIF} 129end; 130 131procedure DebugLnExit(const s1, s2: string; const s3: string; const s4: string; 132 const s5: string; const s6: string; const s7: string; const s8: string; const s9: string; 133 const s10: string; const s11: string; const s12: string; const s13: string; 134 const s14: string; const s15: string; const s16: string; const s17: string; 135 const s18: string); 136begin 137 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 138 DebugLogger.DebugLnExit(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18); 139 {$ENDIF} 140end; 141 142procedure DebuglnStack(LogGroup: PLazLoggerLogGroup; const s: string); 143begin 144 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 145 DebugLogger.DebuglnStack(LogGroup, s); 146 {$ENDIF} 147end; 148 149procedure DbgOut(LogGroup: PLazLoggerLogGroup; const s: string); 150begin 151 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 152 DebugLogger.DbgOut(LogGroup, s); 153 {$ENDIF} 154end; 155 156procedure DbgOut(LogGroup: PLazLoggerLogGroup; Args: array of const); 157begin 158 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 159 DebugLogger.DbgOut(LogGroup, Args); 160 {$ENDIF} 161end; 162 163procedure DbgOut(LogGroup: PLazLoggerLogGroup; const S: String; Args: array of const); 164begin 165 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 166 DebugLogger.DbgOut(LogGroup, s, Args); 167 {$ENDIF} 168end; 169 170procedure DbgOut(LogGroup: PLazLoggerLogGroup; const s1, s2: string; const s3: string; 171 const s4: string; const s5: string; const s6: string; const s7: string; const s8: string; 172 const s9: string; const s10: string; const s11: string; const s12: string; 173 const s13: string; const s14: string; const s15: string; const s16: string; 174 const s17: string; const s18: string); 175begin 176 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 177 DebugLogger.DbgOut(LogGroup, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18); 178 {$ENDIF} 179end; 180 181procedure DebugLn(LogGroup: PLazLoggerLogGroup; const s: string); 182begin 183 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 184 DebugLogger.DebugLn(LogGroup, s); 185 {$ENDIF} 186end; 187 188procedure DebugLn(LogGroup: PLazLoggerLogGroup; Args: array of const); 189begin 190 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 191 DebugLogger.DebugLn(LogGroup, Args); 192 {$ENDIF} 193end; 194 195procedure DebugLn(LogGroup: PLazLoggerLogGroup; const S: String; Args: array of const); 196begin 197 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 198 DebugLogger.DebugLn(LogGroup, s, Args); 199 {$ENDIF} 200end; 201 202procedure DebugLn(LogGroup: PLazLoggerLogGroup; const s1, s2: string; const s3: string; 203 const s4: string; const s5: string; const s6: string; const s7: string; const s8: string; 204 const s9: string; const s10: string; const s11: string; const s12: string; 205 const s13: string; const s14: string; const s15: string; const s16: string; 206 const s17: string; const s18: string); 207begin 208 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 209 DebugLogger.DebugLn(LogGroup, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18); 210 {$ENDIF} 211end; 212 213procedure DebugLnEnter(LogGroup: PLazLoggerLogGroup; const s: string); 214begin 215 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 216 DebugLogger.DebugLnEnter(LogGroup, s); 217 {$ENDIF} 218end; 219 220procedure DebugLnEnter(LogGroup: PLazLoggerLogGroup; Args: array of const); 221begin 222 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 223 DebugLogger.DebugLnEnter(LogGroup, Args); 224 {$ENDIF} 225end; 226 227procedure DebugLnEnter(LogGroup: PLazLoggerLogGroup; s: string; Args: array of const); 228begin 229 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 230 DebugLogger.DebugLnEnter(LogGroup, s, Args); 231 {$ENDIF} 232end; 233 234procedure DebugLnEnter(LogGroup: PLazLoggerLogGroup; const s1, s2: string; const s3: string; 235 const s4: string; const s5: string; const s6: string; const s7: string; const s8: string; 236 const s9: string; const s10: string; const s11: string; const s12: string; 237 const s13: string; const s14: string; const s15: string; const s16: string; 238 const s17: string; const s18: string); 239begin 240 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 241 DebugLogger.DebugLnEnter(LogGroup, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18); 242 {$ENDIF} 243end; 244 245procedure DebugLnExit(LogGroup: PLazLoggerLogGroup; const s: string); 246begin 247 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 248 DebugLogger.DebugLnExit(LogGroup, s); 249 {$ENDIF} 250end; 251 252procedure DebugLnExit(LogGroup: PLazLoggerLogGroup; Args: array of const); 253begin 254 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 255 DebugLogger.DebugLnExit(LogGroup, Args); 256 {$ENDIF} 257end; 258 259procedure DebugLnExit(LogGroup: PLazLoggerLogGroup; s: string; Args: array of const); 260begin 261 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 262 DebugLogger.DebugLnExit(LogGroup, s, Args); 263 {$ENDIF} 264end; 265 266procedure DebugLnExit(LogGroup: PLazLoggerLogGroup; const s1, s2: string; const s3: string; 267 const s4: string; const s5: string; const s6: string; const s7: string; const s8: string; 268 const s9: string; const s10: string; const s11: string; const s12: string; 269 const s13: string; const s14: string; const s15: string; const s16: string; 270 const s17: string; const s18: string); 271begin 272 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 273 DebugLogger.DebugLnExit(LogGroup, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18); 274 {$ENDIF} 275end; 276 277function DbgS(const c: cardinal): string; 278begin 279 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 280 Result:=IntToStr(c); 281 {$ELSE} 282 Result := ''; 283 {$ENDIF} 284end; 285 286function DbgS(const i: longint): string; 287begin 288 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 289 Result:=IntToStr(i); 290 {$ELSE} 291 Result := ''; 292 {$ENDIF} 293end; 294 295function DbgS(const i: int64): string; 296begin 297 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 298 Result:=IntToStr(i); 299 {$ELSE} 300 Result := ''; 301 {$ENDIF} 302end; 303 304function DbgS(const q: qword): string; 305begin 306 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 307 Result:=IntToStr(q); 308 {$ELSE} 309 Result := ''; 310 {$ENDIF} 311end; 312 313function DbgS(const r: TRect): string; 314begin 315 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 316 Result:='l='+IntToStr(r.Left)+',t='+IntToStr(r.Top) 317 +',r='+IntToStr(r.Right)+',b='+IntToStr(r.Bottom); 318 {$ELSE} 319 Result := ''; 320 {$ENDIF} 321end; 322 323function DbgS(const p: TPoint): string; 324begin 325 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 326 Result:='(x='+IntToStr(p.x)+',y='+IntToStr(p.y)+')'; 327 {$ELSE} 328 Result := ''; 329 {$ENDIF} 330end; 331 332function DbgS(const p: pointer): string; 333begin 334 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 335 Result:=HexStr({%H-}PtrUInt(p),2*sizeof(PtrInt)); 336 {$ELSE} 337 Result := ''; 338 {$ENDIF} 339end; 340 341function DbgS(const e: extended; MaxDecimals: integer): string; 342begin 343 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 344 Result:=copy(FloatToStr(e),1,MaxDecimals); 345 {$ELSE} 346 Result := ''; 347 {$ENDIF} 348end; 349 350function DbgS(const b: boolean): string; 351begin 352 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 353 if b then Result:='True' else Result:='False'; 354 {$ELSE} 355 Result := ''; 356 {$ENDIF} 357end; 358 359function DbgS(const m: TMethod): string; 360{$IFnDEF USED_BY_LAZLOGGER_DUMMY} 361var 362 o: TObject; 363 aMethodName: ShortString; 364{$ENDIF} 365begin 366 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 367 o:=TObject(m.Data); 368 Result:=dbgsname(o)+'.'+dbgs(m.Code); 369 if (o<>nil) and (m.Code<>nil) then begin 370 aMethodName:=o.MethodName(m.Code); 371 Result:=Result+'='''+aMethodName+''''; 372 end; 373 {$ELSE} 374 Result := ''; 375 {$ENDIF} 376end; 377 378function DbgSName(const p: TObject): string; 379begin 380 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 381 if p=nil then 382 Result:='nil' 383 else if p is TComponent then 384 Result:=TComponent(p).Name+':'+p.ClassName 385 else 386 Result:=p.ClassName; 387 {$ELSE} 388 Result := ''; 389 {$ENDIF} 390end; 391 392function DbgSName(const p: TClass): string; 393begin 394 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 395 if p=nil then 396 Result:='nil' 397 else 398 Result:=p.ClassName; 399 {$ELSE} 400 Result := ''; 401 {$ENDIF} 402end; 403 404function DbgS(const ASize: TSize): string; 405begin 406 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 407 Result := 'x=' + DbgS(ASize.cx) + ',y=' + DbgS(ASize.cy); 408 {$ELSE} 409 Result := ''; 410 {$ENDIF} 411end; 412 413function DbgSJoin(const s1, s2: string): string; 414begin 415 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 416 if s1 <> '' then 417 Result := s1 + ',' + s2 418 else 419 Result := s2; 420 {$ELSE} 421 Result := ''; 422 {$ENDIF} 423end; 424 425function DbgS(const s: TComponentState): string; 426{$IFnDEF USED_BY_LAZLOGGER_DUMMY} 427type 428 TComponentStateEnum = low(TComponentState)..high(TComponentState); 429 function DbgSComponentStateEnum(const se: TComponentStateEnum): string; 430 begin 431 WriteStr(Result{%H-}, se); 432 end; 433var 434 i: TComponentStateEnum; 435{$ENDIF} 436begin 437 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 438 Result:=''; 439 for i := low(TComponentState) to high(TComponentState) do 440 if i in s then 441 Result := DbgSJoin(Result, dbgsComponentStateEnum(i)); 442 Result:='['+Result+']'; 443 {$ELSE} 444 Result := ''; 445 {$ENDIF} 446end; 447 448function dbgObjMem(AnObject: TObject): string; 449begin 450 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 451 Result:=''; 452 if AnObject=nil then exit; 453 Result:=dbgMemRange(PByte(AnObject),AnObject.InstanceSize); 454 {$ELSE} 455 Result := ''; 456 {$ENDIF} 457end; 458 459function dbghex(i: Int64): string; 460{$IFnDEF USED_BY_LAZLOGGER_DUMMY} 461const 462 Hex = '0123456789ABCDEF'; 463var 464 Negated: Boolean; 465{$ENDIF} 466begin 467 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 468 Result:=''; 469 if i<0 then begin 470 Negated:=true; 471 i:=-i; 472 end else 473 Negated:=false; 474 repeat 475 Result:=Hex[(i mod 16)+1]+Result; 476 i:=i div 16; 477 until i=0; 478 if Negated then 479 Result:='-'+Result; 480 {$ELSE} 481 Result := ''; 482 {$ENDIF} 483end; 484 485function DbgS(const i1, i2, i3, i4: integer): string; 486begin 487 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 488 Result:=dbgs(i1)+','+dbgs(i2)+','+dbgs(i3)+','+dbgs(i4); 489 {$ELSE} 490 Result := ''; 491 {$ENDIF} 492end; 493 494function DbgS(const Shift: TShiftStateEnum): string; 495begin 496 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 497 WriteStr(Result{%H-}, Shift); 498 {$ELSE} 499 Result := ''; 500 {$ENDIF} 501end; 502 503function DbgS(const Shift: TShiftState): string; 504{$IFnDEF USED_BY_LAZLOGGER_DUMMY} 505var 506 i: TShiftStateEnum; 507{$ENDIF} 508begin 509 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 510 Result:=''; 511 for i := low(TShiftStateEnum) to high(TShiftStateEnum) do 512 if i in Shift then 513 Result := DbgSJoin(Result, DbgS(i)); 514 Result:='['+Result+']'; 515 {$ELSE} 516 Result := ''; 517 {$ENDIF} 518end; 519 520function dbgMemRange(P: Pointer; Count: integer; Width: integer): string; 521{$IFnDEF USED_BY_LAZLOGGER_DUMMY} 522const 523 HexChars: array[0..15] of char = '0123456789ABCDEF'; 524 LineEnd: shortstring = LineEnding; 525var 526 i: Integer; 527 NewLen: Integer; 528 Dest: PChar; 529 Col: Integer; 530 j: Integer; 531{$ENDIF} 532begin 533 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 534 Result:=''; 535 if (p=nil) or (Count<=0) then exit; 536 NewLen:=Count*2; 537 if Width>0 then begin 538 inc(NewLen,(Count div Width)*length(LineEnd)); 539 end; 540 SetLength(Result,NewLen); 541 Dest:=PChar(Result); 542 Col:=1; 543 for i:=0 to Count-1 do begin 544 Dest^:=HexChars[PByte(P)[i] shr 4]; 545 inc(Dest); 546 Dest^:=HexChars[PByte(P)[i] and $f]; 547 inc(Dest); 548 inc(Col); 549 if (Width>0) and (Col>Width) then begin 550 Col:=1; 551 for j:=1 to length(LineEnd) do begin 552 Dest^:=LineEnd[j]; 553 inc(Dest); 554 end; 555 end; 556 end; 557 {$ELSE} 558 Result := ''; 559 {$ENDIF} 560end; 561 562function dbgMemStream(MemStream: TCustomMemoryStream; Count: integer): string; 563{$IFnDEF USED_BY_LAZLOGGER_DUMMY} 564var 565 s: string; 566{$ENDIF} 567begin 568 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 569 Result:=''; 570 if (MemStream=nil) or (not (MemStream is TCustomMemoryStream)) or (Count<=0) 571 then exit; 572 Count:=Min(Count,MemStream.Size); 573 if Count<=0 then exit; 574 SetLength(s,Count); 575 Count:=MemStream.Read(s[1],Count); 576 Result:=dbgMemRange(PByte(s),Count); 577 {$ELSE} 578 Result := ''; 579 {$ENDIF} 580end; 581 582 583procedure DumpExceptionBackTrace; 584begin 585 {$IFnDEF USED_BY_LAZLOGGER_DUMMY} 586 DebugLogger.DebugLn(' Stack trace:'); 587 DebugLogger.DumpExceptionBackTrace; 588 {$ENDIF} 589end; 590 591