11# Builtin modules
22from __future__ import annotations
33import re , os , traceback
4- from threading import Lock
54from glob import glob
65from datetime import datetime , timezone
76from typing import List , Tuple , Any , Optional
87# Third party modules
98# Local modules
109from .abcs import T_Logger , T_ModuleBase
1110from .logger import Logger
11+ from .globalLocker import lock
1212# Program
1313class STDErrModule :
1414 log :T_Logger
@@ -73,11 +73,9 @@ def close(self) -> None:
7373class FileStream (T_ModuleBase ):
7474 fullPath :str
7575 stream :Any
76- lock :Lock
7776 isClosed :bool
7877 def __init__ (self , fullPath :str ):
7978 self .fullPath = fullPath
80- self .lock = Lock ()
8179 self .stream = None
8280 self .isClosed = False
8381 def open (self ) -> None :
@@ -96,7 +94,7 @@ def write(self, data:str) -> None:
9694 traceback .print_exc ()
9795 self .isClosed = True
9896 def emit (self , message :str ) -> None :
99- with self . lock :
97+ with lock :
10098 self .write (message )
10199 def close (self ) -> None :
102100 if self .stream is not None :
@@ -120,7 +118,7 @@ def __init__(self, fullPath:str, maxBytes:int=0, rotateDaily:bool=False, maxBack
120118 self .timezone = timezone .utc if useUTCTimezone else None
121119 super ().__init__ (fullPath )
122120 def emit (self , message :str ) -> None :
123- with self . lock :
121+ with lock :
124122 if self .shouldRotate (message ):
125123 self .doRotate ()
126124 self .write (message )
@@ -150,6 +148,7 @@ def doRotate(self) -> None:
150148 traceback .print_exc ()
151149 self .stream = None
152150 self .isClosed = True
151+ self .lastFileSize = 0
153152 self .open ()
154153 def shiftLogFiles (self ) -> None :
155154 def sortFileNums (e :str ) -> Tuple [int , str ]:
@@ -191,7 +190,7 @@ def buildPath(self) -> str:
191190 )
192191 )
193192 def emit (self , message :str ) -> None :
194- with self . lock :
193+ with lock :
195194 if self .shouldRotate (message ):
196195 self .doRotate ()
197196 self .write (message )
0 commit comments