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.InputStreamSource; 23 24 import java.io.IOException; 25 26 /** 27 * A {@link ILeveledLogOutput} that directs log messages to stdout. 28 */ 29 @OptionClass(alias = "stdout") 30 public class StdoutLogger implements ILeveledLogOutput { 31 32 @Option(name="log-level", description="minimum log level to display.", 33 importance = Importance.ALWAYS) 34 private LogLevel mLogLevel = LogLevel.INFO; 35 36 /** 37 * {@inheritDoc} 38 */ 39 @Override printAndPromptLog(LogLevel logLevel, String tag, String message)40 public void printAndPromptLog(LogLevel logLevel, String tag, String message) { 41 printLog(logLevel, tag, message); 42 43 } 44 45 /** 46 * {@inheritDoc} 47 */ 48 @Override printLog(LogLevel logLevel, String tag, String message)49 public void printLog(LogLevel logLevel, String tag, String message) { 50 LogUtil.printLog(logLevel, tag, message); 51 } 52 53 /** 54 * {@inheritDoc} 55 */ 56 @Override setLogLevel(LogLevel logLevel)57 public void setLogLevel(LogLevel logLevel) { 58 mLogLevel = logLevel; 59 } 60 61 /** 62 * {@inheritDoc} 63 */ 64 @Override getLogLevel()65 public LogLevel getLogLevel() { 66 return mLogLevel; 67 } 68 69 /** 70 * {@inheritDoc} 71 */ 72 @Override closeLog()73 public void closeLog() { 74 // ignore 75 } 76 77 /** 78 * {@inheritDoc} 79 */ 80 @Override getLog()81 public InputStreamSource getLog() { 82 // Not supported - return null 83 return null; 84 } 85 86 @Override clone()87 public ILeveledLogOutput clone() { 88 return new StdoutLogger(); 89 } 90 91 @Override init()92 public void init() throws IOException { 93 // ignore 94 } 95 } 96