B4J Library [B4X] Log Server

This is one of the things I've been working on. It enables multi window logging so you can organise and more easily read the logs you create in your code.

1577789610048.png



You can :
  • create multiple dockable LogAreas (windows) the last area created will become the current default.
  • SwitchTo another existing area to make that the default.
  • Send a message to a specific log area
  • Log in Color
  • Write all messages simultaneously to a file for specified LogAreas
  • Filter or Find messages in each LogArea
  • Copy messages to the clipboard (select then ctrl-c)
  • Turn on and off logging of the messages to the IDE log (LogLocal)
  • Configure the output in the Server app (Edit/UserOptions) - Font size, Background color, Port number max message and a few more.
  • Run the server app on a separate computer.

LogServerClient is now a b4xlib which should work on all platforms. It has a different name to the previous libraries to avoid confusion.

The LogServer runs on a PC (untested on a MAC but please let me know) and is provided as a jar file which you should open before running the app containing the client module. Nothing bad will happen if you run the app without opening the server first, all messages will be sent to the IDE log window, you will get a "java.net.ConnectException: Connection refused: connect." message which you can ignore.

If you lose connection while an app is running for any reason, any subsequent messages will be sent to the IDE log.


The client module depends on:
jNetwork / Network
jRandomAccessFile / RandomAccessFile
jXUI / XUI (except NonUI B4j apps)
JavaObject

Limitations:

  • This is not a replacement for the IDE log, it cannot show application errors.
  • The Gui slows down once there are about 3000 items in a LogArea, which is why the limit is initially set to that in the User Options. If you experience a slow Gui, or are running it on an old slow computer you can try limiting this further.
The Server will now accept multiple connections.

Documentation: available as Html file on dropbox


Downloads:

Examples for B4a and B4j and single b4xlib file are attached.

The LogServer jar is too big to upload to the forum, you can get it from my Dropbox here : LogServer download


Update V2:
Supports multiple connections from any platform

The library is now a distributed as a B4xlib and should work on b4j, b4a and b4i as I have removed threading and java specific code.

The only downside is that if you send a lot of messages while the device is connecting, they are handled by a timer instead of a thread, which makes the updates a little slower. To negate this, there is a Stream_Ready callback that will fire when the stream is ready, if you wait for that as in the examples, then the slow down will not occur.

Update V2.10 Client library Updated to work with Non_UI apps in Java 9+

Update V2.2


  • Added ServertimeStamp
  • Added CircularProgressBar - Erel's Circular Progress Bar
  • Added TimePlot - Based on Klaus's xChart V4.2
  • Added LedMatrix
  • Added HexView
  • Improved tcp connection process
  • Added IsConnected method to LogServerClient

Don't forget to download the new version of LogServer.jar from the Dropbox link above and set the IP address of the server in b4a / b4i and also in b4j if you are running the server on a different computer.

If you test it on B4i, please let me know the results.


Please try it out and let me know how you get on with it.

Enjoy.
 

Attachments

  • LogServerClientB4aExample.zip
    8.3 KB · Views: 556
  • LogServerClientB4jExample.zip
    2 KB · Views: 555
  • LogServerClient-B4x.b4xlib
    8.9 KB · Views: 553
Last edited:

stevel05

Expert
Licensed User
Longtime User
V1.10 Client Library updated to work with Non_UI apps in java 9+
 

IslandMedic

Member
Licensed User
Longtime User
Ok that error has gone away now. Thank you for working on this with me. I was feeling a bit crazy because I know I saw a sql lite error and then it went away. I was able to reproduce the error. This error happens right away when I start the app.

If I have an existing blah.db file in my objects folder and then run my ap with your v1.10 LIB activated I get the following error:

B4X:
2019-12-23 12:26:39.619:INFO::main: Logging initialized @162ms to org.eclipse.jetty.util.log.StdErrLog
failed to remove existing native library file: C:\Users\I59100~1\AppData\Local\Temp\sqlite-unknown-sqlitejdbc.dll
java.sql.SQLException: [SQLITE_NOTADB]  File opened that is not a database file (file is encrypted or is not a database)
    at org.sqlite.DB.newSQLException(DB.java:383)
    at org.sqlite.DB.newSQLException(DB.java:387)
    at org.sqlite.DB.throwex(DB.java:374)
    at org.sqlite.NestedDB.prepare(NestedDB.java:134)
    at org.sqlite.DB.prepare(DB.java:123)
    at org.sqlite.PrepStmt.<init>(PrepStmt.java:42)
    at org.sqlite.Conn.prepareStatement(Conn.java:404)
    at org.sqlite.Conn.prepareStatement(Conn.java:399)
    at org.sqlite.Conn.prepareStatement(Conn.java:383)
    at anywheresoftware.b4j.objects.SQL.ExecQuery2(SQL.java:365)
    at anywheresoftware.b4j.objects.SQL.ExecQuerySingleResult2(SQL.java:420)
    at anywheresoftware.b4j.objects.SQL.ExecQuerySingleResult(SQL.java:409)
    at b4j.example.pushshared._createpushtables(pushshared.java:35)
    at b4j.example.pushshared._init(pushshared.java:58)
    at b4j.example.main$ResumableSub_AppStart.resume(main.java:120)
    at b4j.example.main._appstart(main.java:71)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
    at b4j.example.main.main(main.java:28)
main.main (java line: 28)
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
    at b4j.example.main.main(main.java:28)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:496)
    at anywheresoftware.b4a.keywords.Common.CallSubNew3(Common.java:450)
    at anywheresoftware.b4a.BA.handleUncaughtException(BA.java:164)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:108)
    ... 2 more
Caused by: java.lang.RuntimeException: java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:120)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:487)
    ... 5 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
    at b4j.example.logserverclient._messagecolorto(logserverclient.java:669)
    at b4j.example.logserverclient._messageto(logserverclient.java:686)
    at b4j.example.main._application_error(main.java:63)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
    ... 6 more

If I delete the blah.db table and re create the db with your v 1.10 LIB activated it DOES NOT throw the error. Will let you know if I find out any more info.


Here is my initialization

#Region Project Attributes
#CommandLineArgs:
#MergeLibraries: true
#AdditionalJar: sqlite-jdbc-3.7.2
#AdditionalJar: bcprov-jdk15on-159
'Version Dec 22 2019 1736

#End Region

I am using dbutils library for all my sql calls to sql lite.

I also have this code...

B4X:
' needed for ssl connections
    TempDir = File.Combine(File.DirApp, "temp")
    If File.Exists(TempDir, "") = False Then
        File.MakeDir(TempDir, "")
    End If

[/CODE

The reason I included this, in the error it talks about a temp directory.  Just thought it might be usefull.

Brad
Brad
 

stevel05

Expert
Licensed User
Longtime User
Are you sending a log from The Application_Error sub in the Main module?
 

stevel05

Expert
Licensed User
Longtime User
Log server doesn't store anything to the PC via the library neither does it use SQLite.

It uses the jRandomAccessFile library for its B4xSerializator and AsyncStreams classes, but does not use any file access. I am at a loss to see where there could be conflict.

When you say you get the error with the lib activated, does that mean just loaded or connected, or connected and sending messages?

You said you are running a server, is that the app you are adding Logserverclient to? what ports are in use by the existing server?
 
Top