ConsoleLogFormatter.java 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.log;
  16. import java.io.PrintWriter;
  17. import java.io.StringWriter;
  18. import java.util.logging.Formatter;
  19. import java.util.logging.LogRecord;
  20. import com.l2jserver.util.StringUtil;
  21. /**
  22. * This class ...
  23. *
  24. * @version $Revision: 1.1.4.2 $ $Date: 2005/03/27 15:30:08 $
  25. */
  26. public class ConsoleLogFormatter extends Formatter
  27. {
  28. /*
  29. * (non-Javadoc)
  30. *
  31. * @see java.util.logging.Formatter#format(java.util.logging.LogRecord)
  32. */
  33. // private static final String _ = " ";
  34. private static final String CRLF = "\r\n";
  35. @Override
  36. public String format(LogRecord record)
  37. {
  38. final StringBuilder output = new StringBuilder(500);
  39. // output.append(record.getLevel().getName());
  40. // output.append(_);
  41. // output.append(record.getLoggerName());
  42. // output.append(_);
  43. StringUtil.append(output, record.getMessage(), CRLF);
  44. if (record.getThrown() != null)
  45. {
  46. StringWriter sw = null;
  47. PrintWriter pw = null;
  48. try
  49. {
  50. sw = new StringWriter();
  51. pw = new PrintWriter(sw);
  52. record.getThrown().printStackTrace(pw);
  53. StringUtil.append(output, sw.toString(), CRLF);
  54. }
  55. catch (Exception ex)
  56. {
  57. }
  58. finally
  59. {
  60. try
  61. {
  62. pw.close();
  63. }
  64. catch (Exception e)
  65. {
  66. }
  67. try
  68. {
  69. sw.close();
  70. }
  71. catch (Exception e)
  72. {
  73. }
  74. }
  75. }
  76. return output.toString();
  77. }
  78. }