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.

log_config.py 1.7 kB

5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. """
  2. /**
  3. * Copyright 2020 Zhejiang Lab. All Rights Reserved.
  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. """
  19. # !/usr/bin/env python3
  20. # -*- coding: utf-8 -*-
  21. import os
  22. import logging
  23. import re
  24. from logging.handlers import TimedRotatingFileHandler
  25. def setup_log(mode, log_name):
  26. logger = logging.getLogger(log_name)
  27. log_name = os.path.join('./log', mode, log_name)
  28. logger.setLevel(logging.DEBUG)
  29. file_handler = TimedRotatingFileHandler(
  30. filename=log_name, when="MIDNIGHT", interval=1, backupCount=7
  31. )
  32. stream_handler = logging.StreamHandler()
  33. stream_handler.setLevel(logging.DEBUG)
  34. file_handler.suffix = "%Y-%m-%d.log"
  35. file_handler.extMatch = re.compile(r"^\d{4}-\d{2}-\d{2}.log$")
  36. #
  37. file_handler.setFormatter(
  38. logging.Formatter(
  39. "[%(asctime)s][%(levelname)s] - %(message)s"
  40. )
  41. )
  42. stream_handler.setFormatter(
  43. logging.Formatter(
  44. "[%(asctime)s][%(levelname)s] - %(message)s"
  45. )
  46. )
  47. logger.addHandler(file_handler)
  48. logger.addHandler(stream_handler)
  49. return logger

一站式算法开发平台、高性能分布式深度学习框架、先进算法模型库、视觉模型炼知平台、数据可视化分析平台等一系列平台及工具,在模型高效分布式训练、数据处理和可视分析、模型炼知和轻量化等技术上形成独特优势,目前已在产学研等各领域近千家单位及个人提供AI应用赋能

Contributors (1)