Python日志记录不会在每个日志后生成换行符(Linux)
我在Windows上使用了相同的Python脚本,该脚本运行良好,每次运行时都会生成几个日志。问题是,当我在Linux上运行脚本时,日志记录将所有日志记录到一行 我在不同的地方尝试过\n,例如在格式化程序中,在每一行中 以下是日志记录的设置方式:Python日志记录不会在每个日志后生成换行符(Linux),python,linux,logging,Python,Linux,Logging,我在Windows上使用了相同的Python脚本,该脚本运行良好,每次运行时都会生成几个日志。问题是,当我在Linux上运行脚本时,日志记录将所有日志记录到一行 我在不同的地方尝试过\n,例如在格式化程序中,在每一行中 以下是日志记录的设置方式: # This is the setup of the logging system for the program. logger = logging.getLogger(__name__) # Sets the name of the log fi
# This is the setup of the logging system for the program.
logger = logging.getLogger(__name__)
# Sets the name of the log file to 'login.log'
handler = logging.FileHandler(config.path['logger'])
# Sets up the format of the log file: Time, Function Name, Error Level (e.g. Warning Info, Critical),
# and then the message that follows the format.
formatter = logging.Formatter('%(asctime)-5s %(funcName)-20s %(levelname)-10s %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
# Sets the lowest level of messages to info.
logger.setLevel(logging.INFO)
下面是每个日志的制作方法:
logger.warning('%-15s' % client + ' Failed: Logout Error')
提前感谢您确定不是您的编辑器没有将
\n
呈现为新行(而是期望\r\n
)?您阅读了吗?是的,它很有效,但没有代表投票!