1 16 package org.jboss.logging.jdk.format; 17 18 import java.util.logging.Formatter ; 19 import java.util.logging.LogRecord ; 20 21 24 390 public class PatternFormatter extends Formatter 391 { 392 393 398 public final static String DEFAULT_CONVERSION_PATTERN = "%m%n"; 399 400 404 public final static String TTCC_CONVERSION_PATTERN 405 = "%r [%t] %p %c %x - %m%n"; 406 407 408 protected final int BUF_SIZE = 256; 409 protected final int MAX_CAPACITY = 1024; 410 411 private String pattern; 412 413 private PatternConverter head; 414 415 private String timezone; 416 417 422 public PatternFormatter() 423 { 424 this(DEFAULT_CONVERSION_PATTERN); 425 } 426 427 430 public PatternFormatter(String pattern) 431 { 432 this.pattern = pattern; 433 head = createPatternParser((pattern == null) ? DEFAULT_CONVERSION_PATTERN : 434 pattern).parse(); 435 } 436 437 442 public void setConversionPattern(String conversionPattern) 443 { 444 pattern = conversionPattern; 445 head = createPatternParser(conversionPattern).parse(); 446 } 447 448 451 public String getConversionPattern() 452 { 453 return pattern; 454 } 455 456 459 public void activateOptions() 460 { 461 } 463 464 471 public boolean ignoresThrowable() 472 { 473 return true; 474 } 475 476 483 protected PatternParser createPatternParser(String pattern) 484 { 485 return new PatternParser(pattern); 486 } 487 488 489 492 public String format(LogRecord event) 493 { 494 StringBuffer sbuf = new StringBuffer (BUF_SIZE); 496 PatternConverter c = head; 497 while (c != null) 498 { 499 c.format(sbuf, event); 500 c = c.next; 501 } 502 return sbuf.toString(); 503 } 504 } 505 506 | Popular Tags |