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