52
52
53
53
"""
54
54
55
+ import io
55
56
import os
56
57
import sys
57
58
import time
63
64
64
65
from portalocker import LOCK_EX , lock , unlock
65
66
66
- try :
67
- import codecs
68
- except ImportError :
69
- codecs = None
70
-
71
67
try :
72
68
import pwd
73
69
import grp
@@ -122,7 +118,7 @@ class ConcurrentRotatingFileHandler(BaseRotatingHandler):
122
118
123
119
def __init__ (self , filename , mode = 'a' , maxBytes = 0 , backupCount = 0 ,
124
120
encoding = None , debug = False , delay = None , use_gzip = False ,
125
- owner = None , chmod = None , umask = None ):
121
+ owner = None , chmod = None , umask = None , newline = None , terminator = " \n " ):
126
122
"""
127
123
Open the specified file and use it as the stream for logging.
128
124
@@ -140,6 +136,10 @@ def __init__(self, filename, mode='a', maxBytes=0, backupCount=0,
140
136
This is an alternative to chmod. It is mainly for Unix systems but
141
137
can also be used on Windows. The Windows security model is more complex
142
138
and this is not the same as changing access control entries.
139
+ :param newline: None (default): use CRLF on Windows, LF on Unix. Set to '' for
140
+ no translation, in which case the 'terminator' argument determines the line ending.
141
+ :param terminator: set to '\r \n ' along with newline='' to force Windows style
142
+ newlines regardless of OS platform.
143
143
144
144
By default, the file grows indefinitely. You can specify particular
145
145
values of maxBytes and backupCount to allow the file to rollover at
@@ -177,6 +177,7 @@ def __init__(self, filename, mode='a', maxBytes=0, backupCount=0,
177
177
self ._rotateFailed = False
178
178
self .maxBytes = maxBytes
179
179
self .backupCount = backupCount
180
+ self .newline = newline
180
181
181
182
self ._debug = debug
182
183
self .use_gzip = True if gzip and use_gzip else False
@@ -194,8 +195,7 @@ def __init__(self, filename, mode='a', maxBytes=0, backupCount=0,
194
195
super (ConcurrentRotatingFileHandler , self ).__init__ (
195
196
filename , mode , encoding = encoding , delay = True )
196
197
197
- if not hasattr (self , "terminator" ):
198
- self .terminator = "\n "
198
+ self .terminator = terminator or "\n "
199
199
200
200
if owner and os .chown and pwd and grp :
201
201
self ._set_uid = pwd .getpwnam (self .owner [0 ]).pw_uid
@@ -250,10 +250,9 @@ def do_open(self, mode=None):
250
250
mode = self .mode
251
251
252
252
with self ._alter_umask ():
253
- if self .encoding is None :
254
- stream = open (self .baseFilename , mode )
255
- else :
256
- stream = codecs .open (self .baseFilename , mode , self .encoding )
253
+ # noinspection PyArgumentList
254
+ stream = io .open (
255
+ self .baseFilename , mode = mode , encoding = self .encoding , newline = self .newline )
257
256
258
257
self ._do_chown_and_chmod (self .baseFilename )
259
258
0 commit comments