comparison src/goodjava/logger/ListLayout.java @ 1448:6fc083e1d08c

start logger
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 23 Feb 2020 18:14:32 -0700
parents
children
comparison
equal deleted inserted replaced
1447:851b9a48cc44 1448:6fc083e1d08c
1 package goodjava.logger;
2
3
4 public final class ListLayout implements Layout {
5 private final Layout[] layouts;
6
7 public ListLayout(final Object... args) {
8 layouts = new Layout[args.length];
9 for( int i=0; i<args.length; i++ ) {
10 Object obj = args[i];
11 if( obj instanceof Layout ) {
12 layouts[i] = (Layout)obj;
13 } else if( obj instanceof String ) {
14 layouts[i] = new StringLayout((String)obj);
15 } else {
16 throw new IllegalArgumentException("arg "+i);
17 }
18 }
19 }
20
21 public String format(LoggingEvent event) {
22 StringBuilder sb = new StringBuilder();
23 for( Layout layout : layouts ) {
24 sb.append( layout.format(event) );
25 }
26 return sb.toString();
27 }
28
29 private static final class StringLayout implements Layout {
30 final String s;
31
32 StringLayout(String s) {
33 this.s = s;
34 }
35
36 public String format(LoggingEvent event) {
37 return s;
38 }
39 }
40 }