B4J Library [B4j] [B4a] Log Server

Discussion in 'B4J Libraries & Classes' started by stevel05, Apr 28, 2018.

  1. stevel05

    stevel05 Expert Licensed User

    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.

    Columns.PNG

    Multi.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.

    Code for the LogServerClient is provided. The same Module file will work for B4a and B4j but it is better to use the platform specific library as the Client is threaded, which means if you add the module to your project, logging won't then work in debug mode. There is no such problem if you use the library version, or compile it to a library yourself if you want to add functionality. Copy the jar and xml files to your additional library folder and select it in the IDE libs tab (after refreshing it).

    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
    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 only accept one connection at a time. Although you can connect from a B4j or B4a app you can't do both at the same time.


    Downloads:

    Examples for B4a and B4j and a compiled LogServerClientLib file for each are attached, please remember to run the examples in release mode as they contain the modules and not the libraries.


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


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

    Enjoy.





    Documentation (Courtesy of LibDoc from Informatix)

    LogServerClient

    Author: Stevel05
    Version: 0.1



      • LogServerClient
        • Fields:
          • JUSTIFY_CENTER As String
          • JUSTIFY_LEFT As String
          • JUSTIFY_RIGHT As String
          • LOCATION_BOTTOM As String
          • LOCATION_CENTER As String
          • LOCATION_LEFT As String
          • LOCATION_RIGHT As String
          • LOCATION_TOP As String
          • ORIENT_HORIZONTAL As String
          • ORIENT_VERTICAL As String
        • Functions:
          • AddLogArea (LogArea As String, Location As String) As String
            Add a new logarea relative to the window contents.
            Location on of LOCATION_CENTER, LOCATION_TOP , LOCATION_BOTTOM , LOCATION_LEFT or LOCATION_RIGHT
            All areas are autosized after the add.
          • AddLogAreaTo (NewLogArea As String, AddTo As String, Location As String) As String
            Add a new log area relative to an existing one.
            Location on of LOCATION_CENTER, LOCATION_TOP , LOCATION_BOTTOM , LOCATION_LEFT or LOCATION_RIGHT
            All areas are autosized after the add.
          • Class_Globals As String
          • Clear As String
            Clears the current log area
          • ClearAll As String
            Clears All log area
          • ClearLogArea (LogArea As String) As String
            Clear a specific log
          • Close As String
          • Columns (LI As List, NoSpaces As Int, Justify As String, Header As Boolean) As String
            Send a list or array of Objects to the default log area with the default color
            with each element Left, Right or Center justified in the specified number of spaces
          • ColumnsColor (LI As List, NoSpaces As Int, Justify As String, Header As Boolean, Clr As Object) As String
            Send a list or array of Objects to the default log area with the specified color
            with each element Left, Right or Center justified in the specified number of spaces
          • ColumnsColorTo (LogArea As String, Li As List, NoSpaces As Int, Justify As String, Header As Boolean, Clr As Object) As String
            Send a list or array of Objects to the Specified log area with the specified color
            with each element Left, Right or Center justified in the specified number of spaces
          • ColumnsTo (LogArea As String, LI As List, NoSpaces As Int, Justify As String, Header As Boolean) As String
            Send a list or array of Objects to the Specified log area with the default color
            with each element Left, Right or Center justified in the specified number of spaces
          • FileStart (LogArea As String) As String
            Start logging to a file for the spcified logarea
            don't forget to set the archive folder on the server app (in Edit/UserOptions)
          • FileStop (LogArea As String) As String
            Stop wrting to file for the specified logarea
          • FileStopAll As String
            Stop writing to files for all logareas
          • getLogLocal As Boolean
          • Initialize (IPaddr As String, Port As Int) As String
            Initializes the TCP object, pass
            the required IPAddr, or -1 for the defaultlocal: 127.0.0.1
            the required port number, or -1 for the default: 49776
          • IsInitialized As Boolean
            Tests whether the object has been initialized.
          • List (Li As List, Orientation As String) As String
            Send a list or array of Objects to the default log area
          • ListColor (Li As List, Orientation As String, clr As Object) As String
            Send a list or array of Objects to the default log area
          • ListColorTo (LogArea As String, Li As List, Orientation As String, clr As Object) As String
            Send a list or array of Objects to the Specified log area with the specified color
          • ListTo (LogArea As String, Li As List, Orientation As String) As String
            Send a list or array of Objects to the Specified log area
          • Message (Msg As String) As String
            Send a message to the default LogArea
          • MessageColor (Msg As String, clr As Object) As String
            Send a message to the deafult LogArea with Color
          • MessageColorTo (LogArea As String, Msg As String, clr As Object) As String
            Send a message to the specified LogArea with Color
          • MessageTo (LogArea As String, Msg As String) As String
            Send a message to the specified LogArea
          • RemoveLogArea (LogArea As String) As String
            Remove the specified logarea, it is not possible to remove the main area.
          • setDefaultColor (clr As Object) As String
            Set the default color
          • SetIPAddressPort (IPAddress As String, Port As Int) As String
          • setLogLocal (LogLocal As Boolean) As String
            Get / Set the log to local status
          • SetTag (Tag As String) As String
            Set a tag to be prefixed to messages (postfixed to the timestamp)
          • SpaceAligned (Text As String, NoSpaces As Int, Justify As String) As String
            Returns A String Left, Center or Right justified in the specified number of spaces.
            NOTE: this does not send a message, just returns a string that you can place in a message.
          • Spaced (LI As List, SpcCount As Int) As String
            Send a formatted message to the Default logarea with SpcCount spaces in between
          • SpacedColor (LI As List, SpcCount As Int, clr As Object) As String
            Send a formatted message to the default logarea with SpcCount spaces in between in the specified color
          • SpacedColorTo (LogArea As String, LI As List, SpcCount As Int, clr As Object) As String
            Send a formated message to the specified logarea with SpcCount spaces in between and the specified color
          • SpacedTo (LogArea As String, LI As List, SpcCount As Int) As String
            Send a formatted message to the specified logarea with SpcCount spaces in between
          • SwitchTo (LogArea As String) As String
            Make the specified log area the default
          • TimeStamp As String
            Send A Timestamp (DateTime.Now) to the default log area in the default color
          • TimeStampColor (clr As Object) As String
            Send A Timestamp (DateTime.Now) to the default log area in the specified color
          • TimeStampColorTo (LogArea As String, clr As Object) As String
            Send A Timestamp (DateTime.Now) to the specified log area in the specified color
          • TimeStampMessage (Msg As String) As String
            Send A Timestamp (DateTime.Now) and message to the default log area in the default color
          • TimeStampMessageColor (Msg As String, clr As Object) As String
            Send A Timestamp (DateTime.Now) and message to the default log area in the specified color
          • TimeStampMessageColorTo (LogArea As String, Msg As String, clr As Object) As String
            Send A Timestamp (DateTime.Now) and message to the specified log area in the specified color
          • TimeStampMessageTo (LogArea As String, Msg As String) As String
            Send A Timestamp (DateTime.Now) and message to the specified log area
          • TimeStampTo (LogArea As String) As String
            Send A Timestamp (DateTime.Now) to the specified log area
        • Properties:
          • DefaultColor
            Set the default color
          • LogLocal As Boolean
            Get / Set the log to local status
     

    Attached Files:

    Last edited: May 5, 2018
  2. stevel05

    stevel05 Expert Licensed User

    Found some instability in the method used to access the synchronised list when a very high volume of messages were being sent, this has been fixed, please download the example and or Library again.
     
  3. stevel05

    stevel05 Expert Licensed User

    LogServer v0,2 Fixes a small bug in the display and selection of lists. Available at the above link.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice