Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying a log per line for a multiline text

say I have a multi-line text "a\nb\nc"; when I log it, eg with the "debug" method, I get only one log;

this is the expected behaviour but then the lines excluding the first are displayed too on the left in the output :

1234 [1] [DEBUG] Test - a
b
c
1235 [1] [DEBUG] Test - ...

A simple workaround is to generate one log per line to obtain :

1234 [1] [DEBUG] Test - a
1235 [1] [DEBUG] Test - b
1236 [1] [DEBUG] Test - c
1237 [1] [DEBUG] Test - ...

_

Is there any way of having this kind of handling automatically or should I write a simple wrapper to manage this setting ?

_

Thanks in advance.

like image 492
Pragmateek Avatar asked Jan 12 '11 13:01

Pragmateek


People also ask

How do I display text on multiple lines?

Click the Display tab. To enable multiple lines of text to be typed in the text box, select the Multi-line check box, and then optionally do one of the following: To prevent users from being able to insert paragraph breaks in the text box by pressing ENTER, clear the Paragraph breaks check box.

What are multi-line logs?

Multi-line log support permits the System Monitor Agent to identify and collect log entries file that span multiple lines in a text file.

How do you log multiple lines in Python?

I just add \n symbols to the output text. If I define a log formatter as lf = logging. Formatter('%(levelname)-8s - %(message)s\\n%(detail)s') and define a FileHandler to write the logging to a file, the output will contain the \n instead of being converted to a line break. Follow "The Logging Cookbook".

How do I show multiple lines of text in HTML?

Complete HTML/CSS Course 2022 To create a multi-line text input, use the HTML <textarea> tag. You can set the size of a text area using the cols and rows attributes. It is used within a form, to allow users to input text over multiple rows.


1 Answers

Not possible and not recommended.

In your first example, it's clear that there exist two log statements, whereas in your second example one might assume at a glance that there are four of them.

One log statement should provide a single source information about what happened and when it happened, and that information should be useful in some way.

Imagine if you have one error statement, like an exception, that will span across 30 or so lines because of its stack trace. That would look like 30 errors in your case, and an automated tool might also report it as 30 errors. This is misinformation and should be avoided.

Not to mention "one log statement != one written log" might cause synchronization havoc when you're dealing with more complex logging situations, with multiple threads writing to the same file at the same time, or worse, multiple JVMs doing so.

If the "too far on the left" thing is giving you much grief, I'd suggest doing some post processing on generated log file, such as adding 8 spaces or so at the beginning of every line that doesn't contain [DEBUG], [INFO],...

like image 66
darioo Avatar answered Sep 24 '22 02:09

darioo