You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

mslog.cc 1.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * Copyright 2019 Huawei Technologies Co., Ltd
  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 "common/mslog.h"
  17. #include <iostream>
  18. #include <cstdlib>
  19. #include <climits>
  20. #include <string>
  21. #include "include/errorcode.h"
  22. namespace mindspore {
  23. namespace predict {
  24. std::string GetEnv(const std::string &envvar) {
  25. const char *value = std::getenv(envvar.c_str());
  26. if (value == nullptr) {
  27. return std::string();
  28. }
  29. return std::string(value);
  30. }
  31. bool IsPrint(int level) {
  32. auto envString = GetEnv("MSLOG");
  33. static int env = static_cast<int>(std::strtol(!envString.empty() ? envString.c_str() : "3", nullptr, 0));
  34. if (env == INT_MIN || env == INT_MAX) {
  35. env = WARN;
  36. // enable the SP for binscope checking
  37. std::string errorStr = "env exceeded the value that type int is able to represent";
  38. MS_LOGE("%s", errorStr.c_str());
  39. }
  40. return level >= env;
  41. }
  42. } // namespace predict
  43. } // namespace mindspore