Skip to content

Commit b9a5be7

Browse files
committed
Change header format
Change header format
1 parent 1502cc0 commit b9a5be7

1 file changed

Lines changed: 20 additions & 21 deletions

File tree

  • src/main/java/com/neuronrobotics/sdk/common

src/main/java/com/neuronrobotics/sdk/common/Log.java

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,13 @@ public class Log {
7373

7474
/** The out stream. */
7575
private static PrintStream outStream = System.out;
76+
7677
/** The out stream. */
7778
private static PrintStream errStream = System.err;
79+
7880
/** The out stream. */
7981
private static PrintStream mirrorStream = System.out;
82+
8083
/** The use colored prints. */
8184
private boolean useColoredPrints = false;
8285

@@ -88,6 +91,7 @@ public class Log {
8891
private ByteList incomingOut;
8992

9093
private String lastCallingClass = "";
94+
9195
/**
9296
* Instantiates a new log.
9397
*/
@@ -158,20 +162,16 @@ public static void add(String message) {
158162
*/
159163
private void add(String message, int importance) {
160164

161-
if (importance < minprintlevel) {
165+
if (importance < minprintlevel)
162166
return;
163-
}
167+
164168
if (m == null)
165169
m = new Message(message, importance);
166-
else{
170+
else
167171
m.init(message, importance);
168-
}
169-
//messages.add(m);
170172

171-
172-
if (systemprint) {
173+
if (systemprint)
173174
outStream.println(m.toString());
174-
}
175175
}
176176

177177
/**
@@ -186,11 +186,11 @@ public static void enableSystemPrint(boolean systemprint) {
186186
/**
187187
* Enable printing of debug output.
188188
*/
189-
190189
public static void enableDebugPrint() {
191190
Log.enableSystemPrint(true);
192191
Log.setMinimumPrintLevel(DEBUG);
193192
}
193+
194194
public static void disablePrint() {
195195
Log.enableSystemPrint(false);
196196
}
@@ -200,7 +200,6 @@ public static void disablePrint() {
200200
*
201201
* @param flag the flag
202202
*/
203-
204203
public static void enableDebugPrint(boolean flag) {
205204
Log.enableSystemPrint(flag);
206205
Log.setMinimumPrintLevel(DEBUG);
@@ -209,7 +208,6 @@ public static void enableDebugPrint(boolean flag) {
209208
/**
210209
* Enable printing of debug output.
211210
*/
212-
213211
public static void enableInfoPrint() {
214212
Log.enableSystemPrint(true);
215213
Log.setMinimumPrintLevel(INFO);
@@ -218,7 +216,6 @@ public static void enableInfoPrint() {
218216
/**
219217
* Enable printing of debug output.
220218
*/
221-
222219
public static void enableWarningPrint() {
223220
Log.enableSystemPrint(true);
224221
Log.setMinimumPrintLevel(WARNING);
@@ -227,13 +224,11 @@ public static void enableWarningPrint() {
227224
/**
228225
* Enable printing of debug output.
229226
*/
230-
231227
public static void enableErrorPrint() {
232228
Log.enableSystemPrint(true);
233229
Log.setMinimumPrintLevel(ERROR);
234230
}
235231

236-
237232
/**
238233
* Set the minimum level of importance to dsplay.
239234
* Messages below this wont be displayed.
@@ -286,6 +281,7 @@ public String getImportance(int importance) {
286281
return "Log";
287282
}
288283
}
284+
289285
/**
290286
* Get a string describing the given importance level.
291287
*
@@ -310,9 +306,7 @@ public String getImportanceColor(int importance) {
310306
}
311307
return "";
312308
}
313-
314309

315-
316310
/**
317311
* Get the current output PrintStream.
318312
*
@@ -388,18 +382,19 @@ public String toString() {
388382

389383
// First logfile line
390384
if (lastCallingClass.isEmpty()) {
391-
lastCallingClass = "\n[" + dateFormat.format(datetime) + "] ======== Log file opened ========";
385+
386+
lastCallingClass = "\n======== [" + dateFormat.format(datetime) + "] " + message + " ========";
392387
dateFormat = new SimpleDateFormat("HH:mm:ss.SS");
393388

394-
return lastCallingClass.toString();
389+
return lastCallingClass;
395390
}
396391

397392
if (lastCallingClass.equals(getImportance(importance) + " " + callingClass))
398-
return getImportanceColor(importance) + " [" + dateFormat.format(datetime) + "] " + message + getColorNormalizationCode();
393+
return getImportanceColor(importance) + " [" + dateFormat.format(datetime) + "] " + getColorNormalizationCode() + message;
399394

400395
lastCallingClass = getImportance(importance) + " " + callingClass;
401396

402-
return "\n" + getImportanceColor(importance) + lastCallingClass + ":\n [" + dateFormat.format(datetime) + "] " + message + getColorNormalizationCode();
397+
return "\n" + getImportanceColor(importance) + lastCallingClass + ":\n [" + dateFormat.format(datetime) + "] " + getColorNormalizationCode() + message;
403398
}
404399
}
405400

@@ -482,12 +477,14 @@ public void write(int b) throws IOException {
482477
System.setOut(new PrintStream(streamOut));
483478
System.setErr(new PrintStream(streamErr));
484479
setOutStream(new PrintStream(streamErr));
480+
485481
while (instance.log != null) {
486482
try {
487483
Thread.sleep(149);
488484
} catch (InterruptedException e) {
489485
return;
490486
}
487+
491488
if (instance.incomingOut.size() > 0)
492489
try {
493490
String text = instance.incomingOut.asString();
@@ -501,6 +498,7 @@ public void write(int b) throws IOException {
501498
} catch (Exception e) {
502499
e.printStackTrace();
503500
}
501+
504502
if (instance.incomingErr.size() > 0)
505503
try {
506504
String text = instance.incomingErr.asString();
@@ -518,12 +516,13 @@ public void write(int b) throws IOException {
518516
});
519517
instance.logFileThread.start();
520518
}
519+
521520
public static void flush() {
522521
setOutStream(outStream);
523522
System.setOut(outStream);
524523
System.setErr(outStream);
525524
instance.log = null;
526-
while((instance.incomingOut.size() > 0) || (instance.incomingErr.size() > 0 )) {
525+
while ((instance.incomingOut.size() > 0) || (instance.incomingErr.size() > 0 )) {
527526
try {
528527
Thread.sleep(10);
529528
} catch (InterruptedException e) {

0 commit comments

Comments
 (0)