001    /*
002     * Copyright 2010-2015 JetBrains s.r.o.
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    
017    package org.jetbrains.kotlin.utils;
018    
019    import com.intellij.openapi.diagnostic.Logger;
020    import org.apache.log4j.Level;
021    import org.jetbrains.annotations.NonNls;
022    import org.jetbrains.annotations.NotNull;
023    import org.jetbrains.annotations.Nullable;
024    
025    import java.io.PrintStream;
026    
027    @SuppressWarnings("UseOfSystemOutOrSystemErr")
028    public class PrintingLogger extends Logger {
029    
030        public static final Logger SYSTEM_OUT = new PrintingLogger(System.out);
031        public static final Logger SYSTEM_ERR = new PrintingLogger(System.err);
032    
033        private final PrintStream out;
034    
035        public PrintingLogger(@NotNull PrintStream out) {
036            this.out = out;
037        }
038    
039        @Override
040        public boolean isDebugEnabled() {
041            return true;
042        }
043    
044        @Override
045        public void debug(@NonNls String message) {
046            out.println(message);
047        }
048    
049        @Override
050        public void debug(@Nullable Throwable t) {
051            //noinspection ConstantConditions
052            t.printStackTrace(out);
053        }
054    
055        @Override
056        public void debug(@NonNls String message, @Nullable Throwable t) {
057            debug(message);
058            debug(t);
059        }
060    
061        @Override
062        public void info(@NonNls String message) {
063            debug(message);
064        }
065    
066        @Override
067        public void info(@NonNls String message, @Nullable Throwable t) {
068            debug(message, t);
069        }
070    
071        @Override
072        public void warn(@NonNls String message, @Nullable Throwable t) {
073            debug(message, t);
074        }
075    
076        @Override
077        public void error(@NonNls String message, @Nullable Throwable t, @NonNls @NotNull String... details) {
078            debug(message, t);
079            for (String detail : details) {
080                debug(detail);
081            }
082        }
083    
084        @Override
085        public void setLevel(Level level) {
086        }
087    }