PageRenderTime 80ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/apache-log4j-1.2.17/src/main/java/org/apache/log4j/SimpleLayout.java

#
Java | 78 lines | 23 code | 9 blank | 46 comment | 0 complexity | 84313ed29c45c96c6bbf5da0abfdf7c1 MD5 | raw file
Possible License(s): Apache-2.0
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package org.apache.log4j;
  18. import org.apache.log4j.spi.LoggingEvent;
  19. /**
  20. SimpleLayout consists of the level of the log statement,
  21. followed by " - " and then the log message itself. For example,
  22. <pre>
  23. DEBUG - Hello world
  24. </pre>
  25. <p>
  26. @author Ceki G&uuml;lc&uuml;
  27. @since version 0.7.0
  28. <p>{@link PatternLayout} offers a much more powerful alternative.
  29. */
  30. public class SimpleLayout extends Layout {
  31. StringBuffer sbuf = new StringBuffer(128);
  32. public SimpleLayout() {
  33. }
  34. public
  35. void activateOptions() {
  36. }
  37. /**
  38. Returns the log statement in a format consisting of the
  39. <code>level</code>, followed by " - " and then the
  40. <code>message</code>. For example, <pre> INFO - "A message"
  41. </pre>
  42. <p>The <code>category</code> parameter is ignored.
  43. <p>
  44. @return A byte array in SimpleLayout format.
  45. */
  46. public
  47. String format(LoggingEvent event) {
  48. sbuf.setLength(0);
  49. sbuf.append(event.getLevel().toString());
  50. sbuf.append(" - ");
  51. sbuf.append(event.getRenderedMessage());
  52. sbuf.append(LINE_SEP);
  53. return sbuf.toString();
  54. }
  55. /**
  56. The SimpleLayout does not handle the throwable contained within
  57. {@link LoggingEvent LoggingEvents}. Thus, it returns
  58. <code>true</code>.
  59. @since version 0.8.4 */
  60. public
  61. boolean ignoresThrowable() {
  62. return true;
  63. }
  64. }