通常、ロガーは、指定されたメッセージ(エラー、警告、または情報)をログファイル(単純なテキストファイルまたはxml)に記録するために使用されます。
1 に答える
0
明らかな選択肢は、Strategy(さまざまな出力オプションを使用するように構成できる1つのロガー)とComposite(複数の出力出力に出力を多重化する)です。
したがって、このようなもの(Javaの場合):
public class Logger {
public interface LogOutput {
void out(final String s);
}
// Composite - use to send logging to several destinations
public LogOutput makeComposite(final LogOutput... loggers) {
return new LogOutput() {
void out(final String s) {
for (final LogOutput l : loggers) {
l.out(s);
}
}
}
}
private static currentLogger = new LogOutput() {
void out(final String s) {
// Do nothing as default - no strategy set
}
}
public static log(final String s) {
currentLogger.out(s);
}
// Strategy: Set a new strategy for output
public static setLogger(final LogOutput l) {
currentLogger = l;
}
}
于 2012-10-11T06:59:09.053 に答える