Wish If the last log line is identical to the previous one -> merge them

Sandman

Expert
Licensed User
Longtime User
Let's say I have log output like this one:

B4X:
Something got logged here
An example
An example
An example
An example
An example
An example
An example
An example
An example
An example
Ham and cheese
And finally this line
And finally this line

...and so on. It can be difficult to keep up with what's happening.

I propose that instead, if the last line is repeated it should be adjusted to show how many lines it represent, like so:

B4X:
Something got logged here
An example (repeated 10 times)
Ham and cheese
And finally this line (repeated 2 times)

(I know this is standard behaviour in some app/log viewer already, but I can't remember which one - sorry.)
 

Sandman

Expert
Licensed User
Longtime User
The Chrome developer console behaves this way.

Ah, you're quite right - that's where I've seen it, thanks!

And for reference, this is what it looks like:

upload_2017-9-26_6-45-19.png
 

Misterbates

Active Member
Licensed User
Are those lines errors with the source, or output from log() statements? Because if they're source errors they must each be for a different source line and collapsing them would mean it's no longer possible to click on a line to go to the error in the source...
 

Sandman

Expert
Licensed User
Longtime User
Are those lines errors with the source, or output from log() statements?

Well, as I imagined it, it would be for Log(Color) lines only. But there's nothing to stop this from being a general feature of the log window. But the idea is to make it more space efficient while increasing understanding of what's happening (by allowing more "groups" of lines to appear at the same time on the screen). So no, killing the possibility of clicking a line where there's been a source error and going to that place seems like a very bad idea. That's not what my suggestion is about.
 

Misterbates

Active Member
Licensed User
If it's not about the error statements, maybe I'm missing something - aren't we in full control of the log() statements?

A partial solution would be to create a public sub as follows and use it in place of log():
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim LastLogMessage As String
    Dim LastLogCount As Int
End Sub

Sub Activity_Resume
    LogPlus("Something got logged here")
    LogPlus("An example")
    LogPlus("An example")
    LogPlus("An example")
    LogPlus("An example")
    LogPlus("An example")
    LogPlus("An example")
    LogPlus("An example")
    LogPlus("An example")
    LogPlus("An example")
    LogPlus("An example")
    LogPlus("Ham And cheese")
    LogPlus("And finally this line")
    LogPlus("And finally this line")
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    LogPlus("<clear the log>")
End Sub

public Sub LogPlus(Message As String)
    If Message <> LastLogMessage Then
        If LastLogCount > 1 Then
            Log($"${LastLogMessage} (repeated ${LastLogCount} times)"$)
        Else
            Log(LastLogMessage)
        End If
        LastLogMessage = Message
        LastLogCount = 0
    End If
    LastLogCount = LastLogCount + 1
End Sub
 

Sandman

Expert
Licensed User
Longtime User
Well, that's a creative solution, but it wouldn't be what I'm proposing. Your code adds info on how many times the last line was repeated, but it does not merge the lines. This is what your example outputs:

B4X:
<clear the log>
Something got logged here
An example
An example (repeated 2 times)
An example (repeated 3 times)
An example (repeated 4 times)
An example (repeated 5 times)
An example (repeated 6 times)
An example (repeated 7 times)
An example (repeated 8 times)
An example (repeated 9 times)
An example (repeated 10 times)
Ham and cheese
And finally this line
And finally this line (repeated 2 times)

Where my suggestion would instead output this:

B4X:
<clear the log>
Something got logged here
An example (repeated 10 times)
Ham and cheese
And finally this line (repeated 2 times)

Now, if we had a command with the clumsy name of DeleteLastLogLine, we could add that to your code and get exactly the proposed behaviour. But why extend the language with something like that? It probably makes lots more sense to just update how the log window works.
 

Misterbates

Active Member
Licensed User
Well, that's a creative solution, but it wouldn't be what I'm proposing. Your code adds info on how many times the last line was repeated, but it does not merge the lines. This is what your example outputs:

B4X:
<clear the log>
Something got logged here
An example
An example (repeated 2 times)
An example (repeated 3 times)
An example (repeated 4 times)
An example (repeated 5 times)
An example (repeated 6 times)
An example (repeated 7 times)
An example (repeated 8 times)
An example (repeated 9 times)
An example (repeated 10 times)
Ham and cheese
And finally this line
And finally this line (repeated 2 times)

Interesting ... here's the output running B4A 7.30 on a Nexus 6P:
B4X:
Logger connected to:  Huawei Nexus 6P
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Something got logged here
An example (repeated 10 times)
Ham And cheese
** Activity (main) Pause, UserClosed = false **
And finally this line (repeated 2 times)
 

Sandman

Expert
Licensed User
Longtime User
Note that in Android 8 it doesn't print identical lines printed at the exact same time. It is actually a bit confusing as it doesn't show the "repeated x times" message.

So there's just a "silent" merge? That seems super confusing...
 

Misterbates

Active Member
Licensed User
I am, but the code I posted *only* calls log if Message <> LastLogMessage. If Message = LastLogMessage, Log isn't called ... it's not clear to me how on your setup you're seeing multiple "An Example" lines - why is the <> test failing?
 

Sandman

Expert
Licensed User
Longtime User
Sorry, I made an assumption. You're quite correct that your code prints out the proposed format. But only once the log changes the last line, correct?
 

Misterbates

Active Member
Licensed User
Correct, which is why the extra "flush the log" call is there in activity pause. You're correct that the fill solution would need the development environment to have a LogMerge() statement which would log a new line if different than the last, or would update the previous line if the same as the last item logged.

Still, it's a partial solution if you need it.
 
Top