I'm currently working on a project and with a text based logging system. I give the method my String in the form "Test String \nTest String2 \n Test String3".
This is what the String Formatting looks like.
adminWriter.newLine();
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
String currDateTime = dateFormat.format(date);
adminWriter.write(String.format("%-20s | %-50s", currDateTime, text));
And the method is called like this...
Start.scribe.adminToDoWrite("User: "+this.riderID
+"\nTo Delete Horse: "+this.horses[row].getHorseID()
+"\nHorse Name: "+this.horses[row].getHorseName());
The current output looks like this
{Date And Time} | User: (Number)
To Delete Horse: (Number)
Horse Name: (Name)
Is there anyway of getting it to look like this? So that each new line is indented automatically to the String.format rules?
{Date And Time} | User: (Number)
To Delete Horse: (Number)
Horse Name: (Name)
Many Thanks
\t" - for Tab\tto put a tab in a string, but it looks like you want the text to shift all the way to the right of the|beside the first variable. If that's the case, you'll need to figure out how long that first string is and add that many spaces to the beginning of the next lines.SimpleDateFormatclass. It is not only long outdated, it is also notoriously troublesome. Today we have so much better injava.time, the modern Java date and time API. Use for exampleLocalDateTime.now(yourTimeZone).format(DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss")).