Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #
  2. # Copyright 2024 The InfiniFlow Authors. All Rights Reserved.
  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. import os
  17. import logging
  18. from logging.handlers import RotatingFileHandler
  19. from api.utils.file_utils import get_project_base_directory
  20. LOG_LEVEL = logging.INFO
  21. LOG_FILE = os.path.abspath(os.path.join(get_project_base_directory(), "logs", f"ragflow_{os.getpid()}.log"))
  22. LOG_FORMAT = "%(asctime)-15s %(levelname)-8s %(process)d %(message)s"
  23. logger = None
  24. def getLogger():
  25. global logger
  26. if logger is not None:
  27. return logger
  28. print(f"log file path: {LOG_FILE}")
  29. os.makedirs(os.path.dirname(LOG_FILE), exist_ok=True)
  30. logger = logging.getLogger("ragflow")
  31. logger.setLevel(LOG_LEVEL)
  32. handler1 = RotatingFileHandler(LOG_FILE, maxBytes=10*1024*1024, backupCount=5)
  33. handler1.setLevel(LOG_LEVEL)
  34. formatter1 = logging.Formatter(LOG_FORMAT)
  35. handler1.setFormatter(formatter1)
  36. logger.addHandler(handler1)
  37. handler2 = logging.StreamHandler()
  38. handler2.setLevel(LOG_LEVEL)
  39. formatter2 = logging.Formatter(LOG_FORMAT)
  40. handler2.setFormatter(formatter2)
  41. logger.addHandler(handler2)
  42. return logger
  43. logger = getLogger()