B4A Library ExternalLogger (using Google Room Database)

This is a wrap for this Github-Project.

ExternalLogger
External logger library for android applications. You can save logs
in any component in your app (Activity, Service, Fragment). The data
will be stored in memory even after exiting the application or
turning off the device. You can access the information at any time,
export the data to an email, to a text file or to a server.
The data can be accessed by the tag filter, text, or log creation
time. The data will be deleted by a function under your control.

Author: DonManfred
Version: 0.1
  • ExtLog
    • Functions:
      • Initialize (tag As String, text As String)
      • IsInitialized As Boolean
    • Properties:
      • Obj As ExtLog [read only]
      • Tag As String
      • Text As String
      • Time As Long
      • Uid As Int
  • ExternalLogger
    • Events:
      • logsReturned (logs As List)
      • onCompleted()
    • Functions:
      • addLogToDB (extLog As guy4444.extrnalloggerlibrary.ExtLog)
      • addLogToDB2 (tag As String, text As String)
      • deleteAll
      • getAllLogsBetweenDates (start As Long, end As Long, loggerDBCallBack_logsReturned As guy4444.extrnalloggerlibrary.MyLoggerDB.LoggerDBCallBack_LogsReturned)
      • getAllLogsByTag (tag As String)
      • getAllLogsByTagAndText (tag As String, text As String)
      • getAllLogsByTagAndTextBetweenDates (start As Long, end As Long, tag As String, text As String)
      • getAllLogsByTagAndTextFromDate (start As Long, tag As String, text As String)
      • getAllLogsByTagBetweenDates (start As Long, end As Long, tag As String)
      • getAllLogsByTagFromDate (start As Long, tag As String)
      • getAllLogsFromDate (start As Long, loggerDBCallBack_logsReturned As guy4444.extrnalloggerlibrary.MyLoggerDB.LoggerDBCallBack_LogsReturned)
      • Initialize (EventName As String)
    • Properties:
      • AllLogs [read only]
Setup:
- Add this code to your Mainmodule to include the needed AAR and the dependency for the Room-Database Runtime.
B4X:
#AdditionalJar: externallogger.aar
#AdditionalJar: android.arch.persistence.room:runtime
- Add this code to your Starter Service
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Public extLog As ExternalLogger
End Sub

Sub Service_Create
    'This is the program entry point.
    'This is a good place to load resources that are not specific to a single activity.
    extLog.Initialize("ExtLog")
   
End Sub
Sub AddLOG(tag, text As String)
    Log($"ExtLOG(${tag},${text})"$)
    extLog.addLogToDB2(tag, text)
End Sub
Sub AddLOG2(tag, text As String)
    Log($"ExtLOG2(${tag},${text})"$)
    Dim logitem As ExtLog
    logitem.Initialize(tag,text)
    logitem.Time = DateTime.Now
    extLog.addLogToDB(logitem)
End Sub
Sub ExtLog_logsReturned(logs As List)  
    Log($"ExtLog_logsReturned(${logs})"$)
    For i=0 To logs.Size-1
        Dim l As ExtLog = logs.Get(i)
        Log($"ExtLOG: $datetime{l.Time}: ${l.Text}, ${l.Tag}"$)
    Next
End Sub
Sub ExtLog_onCompleted()
    Log($"ExtLog_onCompleted()"$)
End Sub

You now easily can add a LOG-Entry from anywhere in your Project.
B4X:
    CallSub3(Starter,"AddLOG","AppStart",$"This is the Text to LOG (FirstTime = ${FirstTime})"$)

In this case the Entry is using the Tag "AppStart". You can use any String you like. You´ll be able to get the logs based on the Tag, Datetime range...

B4X:
    Starter.extLog.getAllLogsByTag("AppStart")
 

Attachments

  • ExternalLoggerV0.1.zip
    44.3 KB · Views: 416
  • ExtLogEx.zip
    8.2 KB · Views: 409
Last edited:

AnandGupta

Expert
Licensed User
Longtime User
As I understand from Github site, it uses sql database saved in internal memory, right ?
Does it require user to be online ? (saw this line 'https://jitpack.io' there)

Regards,

Anand
 

DonManfred

Expert
Licensed User
Longtime User
As I understand from Github site, it uses sql database saved in internal memory, right ?
Honestly i do not know exactly where Google Room Databases are stored. But i guess the answer is yes ;-)
Does it require user to be online ?
All dependencies are compiled to your app when setup right. No need to be "Online".
In this case the Content needed is in the AAR provided.

The Data is saved on the Device and can be accessed afterwards until you remove the old logs.
 
Last edited:
Top