1 // 2 // Copyright (C) 2020 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 #include "logging.h" 17 18 #include <android-base/logging.h> 19 20 #include "common/libs/utils/tee_logging.h" 21 #include "host/libs/config/cuttlefish_config.h" 22 23 using android::base::SetLogger; 24 25 namespace cuttlefish { 26 DefaultSubprocessLogging(char * argv[])27void DefaultSubprocessLogging(char* argv[]) { 28 ::android::base::InitLogging(argv, android::base::StderrLogger); 29 30 auto config = CuttlefishConfig::Get(); 31 32 CHECK(config) << "Could not open cuttlefish config"; 33 34 auto instance = config->ForDefaultInstance(); 35 36 std::string prefix = ""; 37 if (config->Instances().size() > 1) { 38 prefix = instance.instance_name() + ": "; 39 } 40 41 if (config->run_as_daemon()) { 42 SetLogger(LogToFiles({instance.launcher_log_path()})); 43 } else { 44 SetLogger(LogToStderrAndFiles({instance.launcher_log_path()}, prefix)); 45 } 46 } 47 48 } // namespace cuttlefish 49