March 05, 2021, 07:38:18 AM

Author Topic: [bmx] AppLog Module by JoshK [ 1+ years ago ]  (Read 436 times)

Offline BlitzBot

[bmx] AppLog Module by JoshK [ 1+ years ago ]
« on: June 29, 2017, 12:28:41 AM »
Title : AppLog Module
Author : JoshK
Posted : 1+ years ago

Description : Log messages will be written to the stdout (same as Print() ).  A .log file by the same name as your application will also be automatically written.

Instead of commenting out a bunch of Print() commands, you can just enable/disable logging with AppLogMode().  An optional callback can be specified to be called for every logged string.  This allows you to send the output to a console window for your application.  For example, my callback function writes the string to a textarea gadget the user can view.


Code :
Code: BlitzMax
  1. Module leadwerks.applog
  2.  
  3. Import brl.standardio
  4. Import brl.filesystem
  5. Import brl.system
  6.  
  7. Strict
  8.  
  9.  
  10. Private
  11.  
  12. Global AppLogEnabled
  13. Global AppLogStream:TStream
  14. Global AppLogCallback(text$)
  15.  
  16. Public
  17.  
  18. Rem
  19. bbdoc:
  20. EndRem
  21. Function AppLogMode(mode,callback:Byte Ptr=Null)
  22.         If Not mode AppLog "Logging stopped"
  23.         AppLogEnabled=mode
  24.         AppLogCallback=callback
  25.         If mode AppLog "Logging started"
  26. EndFunction
  27.  
  28. 'Flags:
  29. '1 - Error
  30. '2 - Don't return line
  31. '4 - Notification box
  32. Rem
  33. bbdoc:
  34. EndRem
  35. Function AppLog(text$,flags=0)
  36.         If Not AppLogEnabled Return
  37.         If Not AppLogStream AppLogStream=WriteFile(StripExt(AppFile)+".log")
  38.        
  39.         If (4 & flags) Notify text,(1 & flags)
  40.         If (1 & flags) text="Error: "+text
  41.         If Not (2 & flags) text:+Chr(13)+Chr(10)
  42.  
  43.         If AppLogStream AppLogStream.WriteString text
  44.         WriteStdout text
  45.         If AppLogCallback<>Null AppLogCallback(text)   
  46. EndFunction


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal