Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python日志记录不会在每个日志后生成换行符(Linux)_Python_Linux_Logging - Fatal编程技术网

Python日志记录不会在每个日志后生成换行符(Linux)

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

我在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 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
)?您阅读了吗?是的,它很有效,但没有代表投票!