You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LogWriter.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. *
  3. * This is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This software is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this software; if not, write to the Free Software
  15. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
  16. * USA.
  17. */
  18. package com.tigervnc.rfb;
  19. public class LogWriter {
  20. public LogWriter(String name_) {
  21. name = name_;
  22. level = globalLogLevel;
  23. next = log_writers;
  24. log_writers = this;
  25. }
  26. public void setLevel(int level_) { level = level_; }
  27. public void write(int level, String str) {
  28. if (level <= this.level) {
  29. System.err.println(name+": "+str);
  30. }
  31. }
  32. public void error(String fmt, Object... args) {
  33. write(0, String.format(fmt, args));
  34. }
  35. public void status(String fmt, Object... args) {
  36. write(10, String.format(fmt, args));
  37. }
  38. public void info(String fmt, Object... args) {
  39. write(30, String.format(fmt, args));
  40. }
  41. public void debug(String fmt, Object... args) {
  42. write(100, String.format(fmt, args));
  43. }
  44. public static boolean setLogParams(String params) {
  45. globalLogLevel = Integer.parseInt(params);
  46. LogWriter current = log_writers;
  47. while (current != null) {
  48. current.setLevel(globalLogLevel);
  49. current = current.next;
  50. }
  51. return true;
  52. // int colon = params.indexOf(':');
  53. // String logwriter_name = params.substring(0, colon);
  54. // params = params.substring(colon+1);
  55. // colon = params.indexOf(':');
  56. // String logger_name = params.substring(0, colon);
  57. // params = params.substring(colon+1);
  58. // int level = Integer.parseInt(params);
  59. // // XXX ignore logger name for the moment
  60. // System.err.println("setting level to "+level);
  61. // System.err.println("logwriters is "+log_writers);
  62. // if (logwriter_name.equals("*")) {
  63. // LogWriter current = log_writers;
  64. // while (current != null) {
  65. // //current.setLog(logger);
  66. // System.err.println("setting level of "+current.name+" to "+level);
  67. // current.setLevel(level);
  68. // current = current.next;
  69. // }
  70. // return true;
  71. // }
  72. // LogWriter logwriter = getLogWriter(logwriter_name);
  73. // if (logwriter == null) {
  74. // System.err.println("no logwriter found: "+logwriter_name);
  75. // return false;
  76. // }
  77. // //logwriter.setLog(logger);
  78. // logwriter.setLevel(level);
  79. // return true;
  80. }
  81. static LogWriter getLogWriter(String name) {
  82. LogWriter current = log_writers;
  83. while (current != null) {
  84. if (name.equalsIgnoreCase(current.name)) return current;
  85. current = current.next;
  86. }
  87. return null;
  88. }
  89. String name;
  90. int level;
  91. LogWriter next;
  92. static LogWriter log_writers;
  93. static int globalLogLevel = 30;
  94. }