String"; Log.d(TAG, text); it automatically p...">

Android Logging Strings with newline or <br>

It seems that if you call

String text = "String<br>String"; Log.d(TAG, text); 

it automatically parses a string to take two strings. The same applies to newlines ( \n ). This makes debugging more difficult. Is there any way to tell the logger to tell me the exact string?

+5
source share
2 answers

The arguments to the methods in the Log class are Java strings, so escaping special characters is similar to Java. For instance,

 String text = "String\nString"; Log.d("TEST!!", text); 

You'll get:

 D/TEST!!īš• String String 

a

 String text = "String\\nString"; Log.d("TEST!!", text); 

will provide you with:

 D/TEST!!īš• String\nString 

in logcat.

As far as <BR> , I do not see the same effect as you. In particular,

 String text = "String<br>String"; Log.d("TEST!!", text); 

It produces:

 D/TEST!!īš• String<br>String 

Therefore, I can not reproduce your current problem. However, in general, special characters in log lines are escaped in the same way as any other Java line. The logger is mute and there are no settings for automatically exiting special characters; you will have to do it yourself for arbitrary strings. Log methods just expand and call println_native .

+6
source

I am using System.getProperty ("line.separator")

 ArrayList<String> txts = new ArrayList<String>(); txts.add("aoeuaeou"); txts.add("snhsnthsnth"); String msg = TextUtils.join(System.getProperty("line.separator"),txts); Log.d(TAG, "Bla bla bla: "+ msg ); 

show in the magazine how

 Bla bla bla: aoeuaeou snhsnthsnth 
+1
source

Source: https://habr.com/ru/post/1202085/


All Articles