1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.tradefed.log; 17 18 import com.android.ddmlib.Log.LogLevel; 19 import com.android.tradefed.config.Option; 20 import com.android.tradefed.config.Option.Importance; 21 import com.android.tradefed.config.OptionClass; 22 import com.android.tradefed.result.ByteArrayInputStreamSource; 23 import com.android.tradefed.result.InputStreamSource; 24 25 import java.io.IOException; 26 27 /** 28 * A {@link ILeveledLogOutput} that directs log messages to stdout. 29 */ 30 @OptionClass(alias = "stdout") 31 public class StdoutLogger implements ILeveledLogOutput { 32 33 @Option(name="log-level", description="minimum log level to display.", 34 importance = Importance.ALWAYS) 35 private LogLevel mLogLevel = LogLevel.INFO; 36 37 /** 38 * {@inheritDoc} 39 */ 40 @Override printAndPromptLog(LogLevel logLevel, String tag, String message)41 public void printAndPromptLog(LogLevel logLevel, String tag, String message) { 42 printLog(logLevel, tag, message); 43 44 } 45 46 /** 47 * {@inheritDoc} 48 */ 49 @Override printLog(LogLevel logLevel, String tag, String message)50 public void printLog(LogLevel logLevel, String tag, String message) { 51 LogUtil.printLog(logLevel, tag, message); 52 } 53 54 /** 55 * {@inheritDoc} 56 */ 57 @Override setLogLevel(LogLevel logLevel)58 public void setLogLevel(LogLevel logLevel) { 59 mLogLevel = logLevel; 60 } 61 62 /** 63 * {@inheritDoc} 64 */ 65 @Override getLogLevel()66 public LogLevel getLogLevel() { 67 return mLogLevel; 68 } 69 70 /** 71 * {@inheritDoc} 72 */ 73 @Override closeLog()74 public void closeLog() { 75 // ignore 76 } 77 78 /** 79 * {@inheritDoc} 80 */ 81 @Override getLog()82 public InputStreamSource getLog() { 83 // not supported - return empty stream 84 return new ByteArrayInputStreamSource(new byte[0]); 85 } 86 87 @Override clone()88 public ILeveledLogOutput clone() { 89 return new StdoutLogger(); 90 } 91 92 @Override init()93 public void init() throws IOException { 94 // ignore 95 } 96 } 97