I am outputting a lot of information to the console that is gathered across multiple nested calls. I would like to be able to print the information on the screen in a readable manner but the I can't seem to get the indentation right, without hardcoding the number the number of \t
s.
Basically, how can I get my code to indent based on the indentation level of the previous line. If the previous line is indented with \t
and I do "\n\t", after that, I would like the new line to indent with respect to the previous line. Meaning I expected to be like
String str = "original line (no indention)"
+ "\n"
+ "\t originally indented line"
+ "\n"
+ "\t the second indented line"
The output is
original line (no indention)
originally indented line
the second indented line
but I would like it to be
original line (no indention)
originally indented line
the second indented line
Please keep in mind that in my actual code each level of indention is a result of aggregation from a different file so it's hard to just know to indent twice on the second line. I need it to be able to indent simply based on the indentation of previous line so I don't have to hard code the levels of indentation.