1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one * 3 * or more contributor license agreements. See the NOTICE file * 4 * distributed with this work for additional information * 5 * regarding copyright ownership. The ASF licenses this file * 6 * to you under the Apache License, Version 2.0 (the * 7 * "License"); you may not use this file except in compliance * 8 * with the License. You may obtain a copy of the License at * 9 * * 10 * http://www.apache.org/licenses/LICENSE-2.0 * 11 * * 12 * Unless required by applicable law or agreed to in writing, * 13 * software distributed under the License is distributed on an * 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * 15 * KIND, either express or implied. See the License for the * 16 * specific language governing permissions and limitations * 17 * under the License. * 18 */ 19 package org.apache.rat.utils; 20 21 /** 22 * A default implementation of Log that writes to System.out and System.err 23 */ 24 public class DefaultLog implements Log { 25 26 /** 27 * The instance of the default log. 28 */ 29 public static final DefaultLog INSTANCE = new DefaultLog(); 30 31 private Level level; 32 33 private DefaultLog() { 34 level = Level.WARN; 35 } 36 37 public void setLevel(Level level) { 38 this.level = level; 39 } 40 41 public Level getLevel() { 42 return level; 43 } 44 45 @Override 46 public void log(Level level, String msg) { 47 if (this.level.ordinal() <= level.ordinal()) 48 switch (level) { 49 case DEBUG: 50 case INFO: 51 case WARN: 52 System.out.format("%s: %s%n", level, msg); 53 break; 54 case ERROR: 55 System.err.format("%s: %s%n", level, msg); 56 break; 57 case OFF: 58 break; 59 default: 60 break; 61 } 62 } 63 }