1 4 package org.oddjob.logging; 5 6 import org.oddjob.Oddjob; 7 8 17 public class LocalConsoleArchiver implements ConsoleArchiver { 18 19 20 private ConsoleArchiverCache cache; 21 22 25 private ConsoleArchiverCache.Resolver resolver = new ConsoleArchiverCache.Resolver() { 26 public LogArchive archiveFor(Object component) { 27 if (component instanceof ConsoleArchive) { 28 return ((ConsoleArchive) component).consoleLog(); 29 } 30 else { 31 return Oddjob.CONSOLE.consoleLog(); 32 } 33 } 34 public String idFor(Object component) { 35 if (component instanceof ConsoleArchive) { 36 return ((ConsoleArchive) component).consoleLog().getArchive(); 37 } 38 else { 39 return Oddjob.CONSOLE.consoleLog().getArchive(); 40 } 41 } 42 }; 43 44 49 public LocalConsoleArchiver(Object root) { 50 this(root, LogArchiver.MAX_HISTORY); 51 } 52 53 59 public LocalConsoleArchiver(Object root, int maxHistory) { 60 cache = new ConsoleArchiverCache(root, maxHistory, resolver); 61 } 62 63 67 public void addConsoleListener(LogListener l, Object component, 68 long last, int history) { 69 cache.addLogListener(l, 70 resolver.idFor(component), LogLevel.DEBUG, last, history); 71 } 72 73 77 public void removeConsoleListener(LogListener l, Object component) { 78 cache.removeLogListener(l, 79 resolver.idFor(component)); 80 } 81 82 85 public String consoleIdFor(Object component) { 86 return resolver.idFor(component); 87 } 88 89 93 public void destroy() { 94 cache.destroy(); 95 } 96 97 98 } 99 | Popular Tags |