bte_init_cpp_logging.cc 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /******************************************************************************
  2. *
  3. * Copyright 2016 Android Open Source Project
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at:
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. ******************************************************************************/
  18. #include <base/command_line.h>
  19. #include "main_int.h"
  20. void init_cpp_logging(config_t* config) {
  21. // Command line and log level might be also configured in service/main.cpp
  22. // when running the bluetoothtbd daemon. If it's already configured, skip
  23. // configuring.
  24. if (base::CommandLine::InitializedForCurrentProcess()) return;
  25. const std::string* loggingV =
  26. config_get_string(*config, CONFIG_DEFAULT_SECTION, "LoggingV", NULL);
  27. const std::string* loggingVModule = config_get_string(
  28. *config, CONFIG_DEFAULT_SECTION, "LoggingVModule", NULL);
  29. int argc = 1;
  30. const char* argv[] = {"bt_stack", NULL, NULL};
  31. if (loggingV != NULL) {
  32. argv[argc] = loggingV->c_str();
  33. argc++;
  34. }
  35. if (loggingVModule != NULL) {
  36. argv[argc] = loggingVModule->c_str();
  37. argc++;
  38. }
  39. // Init command line object with logging switches
  40. base::CommandLine::Init(argc, argv);
  41. logging::LoggingSettings log_settings;
  42. if (!logging::InitLogging(log_settings)) {
  43. LOG(ERROR) << "Failed to set up logging";
  44. }
  45. // Android already logs thread_id, proc_id, timestamp, so disable those.
  46. logging::SetLogItems(false, false, false, false);
  47. }