(String text, int level)
| 440 | /// |
| 441 | /// - `level`: one of DEBUG, INFO, WARNING, ERROR |
| 442 | protected void print(String text, int level) { |
| 443 | if (!initialized) { |
| 444 | initialized = true; |
| 445 | try { |
| 446 | InputStream is = null; //NOPMD CloseResource |
| 447 | try { |
| 448 | is = Display.getInstance().getResourceAsStream(getClass(), "/cn1-version-numbers"); |
| 449 | if (is != null) { |
| 450 | print("Codename One revisions: " + Util.readToString(is), INFO); |
| 451 | } |
| 452 | } finally { |
| 453 | Util.cleanup(is); |
| 454 | } |
| 455 | } catch (IOException err) { |
| 456 | // shouldn't happen... |
| 457 | err.printStackTrace(); |
| 458 | } |
| 459 | } |
| 460 | if (this.level > level) { |
| 461 | return; |
| 462 | } |
| 463 | logDirty = true; |
| 464 | text = getThreadAndTimeStamp() + " - " + text; |
| 465 | CodenameOneImplementation impl = Util.getImplementation(); |
| 466 | if (impl != null) { |
| 467 | impl.systemOut(text); |
| 468 | } else { |
| 469 | System.out.println(text); |
| 470 | } |
| 471 | try { |
| 472 | synchronized (this) { |
| 473 | Writer w = getWriter(); //NOPMD CloseResource - shared writer managed by Log |
| 474 | w.write(text + "\n"); |
| 475 | w.flush(); |
| 476 | } |
| 477 | } catch (Throwable err) { |
| 478 | err.printStackTrace(); |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | /// Default method for creating the output writer into which we write, this method |
| 483 | /// creates a simple log file using the file connector |
no test coverage detected