CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes
ztee.GZipLog Class Reference
Inheritance diagram for ztee.GZipLog:

Public Member Functions

def __init__ (self, log_file)
 
def finish (self)
 
def flush_block (self)
 
def handle_timeout (self)
 
def try_flush (self)
 
def write (self, bytes)
 
def write_block (self, data)
 

Public Attributes

 block
 
 block_size
 
 block_size_max
 
 block_timeout
 
 file
 
 file_max_size
 
 file_min_size
 
 file_truncate_pos
 
 file_truncate_state
 
 last_flush
 
 zstream
 

Detailed Description

Definition at line 13 of file ztee.py.

Constructor & Destructor Documentation

def ztee.GZipLog.__init__ (   self,
  log_file 
)

Definition at line 14 of file ztee.py.

14  def __init__(self, log_file):
15  self.file = None
16 
17  self.last_flush = time.time()
18  self.zstream = zlib.compressobj(6, zlib.DEFLATED, zlib.MAX_WBITS | 16)
19 
20  # 'gzip' block will be flushed if we reach max bytes or the timeout
21  self.block = []
22  self.block_size = 0
23  self.block_size_max = 2*1024*1024 # bytes
24  self.block_timeout = 15 # seconds
25 
26  self.file = open(log_file, "wb+")
27  self.file_min_size = 2*1024*1024 # this amount of space we keep after truncating
28  self.file_max_size = 64*1024*1024 # we truncate if file gets bigger
29 
30  self.file_truncate_pos = None
31  self.file_truncate_state = None
32 
file_min_size
Definition: ztee.py:27
last_flush
Definition: ztee.py:17
block_size
Definition: ztee.py:22
file_truncate_state
Definition: ztee.py:31
block_timeout
Definition: ztee.py:24
file_max_size
Definition: ztee.py:28
file_truncate_pos
Definition: ztee.py:30
block_size_max
Definition: ztee.py:23
def __init__(self, log_file)
Definition: ztee.py:14

Member Function Documentation

def ztee.GZipLog.finish (   self)
def ztee.GZipLog.flush_block (   self)

Definition at line 37 of file ztee.py.

References ztee.GZipLog.block, ztee.GZipLog.block_size, ztee.GZipLog.file_max_size, ztee.GZipLog.file_min_size, ztee.GZipLog.file_truncate_pos, ztee.GZipLog.file_truncate_state, join(), ztee.GZipLog.last_flush, ztee.GZipLog.write_block(), ztee.GZipLog.zstream, and ztail.Decoder.zstream.

Referenced by ztee.GZipLog.finish(), and ztee.GZipLog.try_flush().

37  def flush_block(self):
38  self.last_flush = time.time()
39 
40  data, size, = "".join(self.block), self.block_size
41  self.block, self.block_size = [], 0
42 
43  if size == 0:
44  # nothing to do
45  return
46 
47  # check if we need to truncate the file
48  # 'size' refers to uncompressed data, so the file be truncated at max_size -+ max_block_size
49  # there is no way know compressed size without collapsing the zlib state
50  if (self.file.tell() + size) > self.file_max_size:
51  if self.file_truncate_pos is not None:
52  # tell it to cleanup
53  self.zstream.flush(zlib.Z_FINISH)
54 
55  self.file.seek(self.file_truncate_pos, 0)
56  self.file.truncate()
57  self.zstream = self.file_truncate_state.copy()
58 
59  self.write_block("\n\n--- file was cut at this point ---\n\n")
60 
61  # write it
62  self.write_block(data)
63 
64  # check if we can save the ptr into truncate_position
65  if self.file_truncate_pos is None:
66  if self.file.tell() >= self.file_min_size:
67  self.file_truncate_pos = self.file.tell()
68  self.file_truncate_state = self.zstream.copy()
69 
file_min_size
Definition: ztee.py:27
last_flush
Definition: ztee.py:17
block_size
Definition: ztee.py:22
file_truncate_state
Definition: ztee.py:31
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def write_block(self, data)
Definition: ztee.py:33
def flush_block(self)
Definition: ztee.py:37
file_max_size
Definition: ztee.py:28
file_truncate_pos
Definition: ztee.py:30
def ztee.GZipLog.handle_timeout (   self)

Definition at line 90 of file ztee.py.

References ztee.GZipLog.try_flush().

Referenced by esMonitoring.AsyncLineReaderTimeoutMixin.readable().

90  def handle_timeout(self):
91  self.try_flush()
92 
93 
def handle_timeout(self)
Definition: ztee.py:90
def try_flush(self)
Definition: ztee.py:76
def ztee.GZipLog.try_flush (   self)

Definition at line 76 of file ztee.py.

References ztee.GZipLog.block_size, ztee.GZipLog.block_size_max, ztee.GZipLog.block_timeout, ztee.GZipLog.flush_block(), and ztee.GZipLog.last_flush.

Referenced by ztee.GZipLog.handle_timeout(), and ztee.GZipLog.write().

76  def try_flush(self):
77  timeout = (time.time() - self.last_flush) > self.block_timeout
78  large_block = self.block_size > self.block_size_max
79 
80  if timeout or large_block:
81  self.flush_block()
82 
last_flush
Definition: ztee.py:17
block_size
Definition: ztee.py:22
block_timeout
Definition: ztee.py:24
def flush_block(self)
Definition: ztee.py:37
def try_flush(self)
Definition: ztee.py:76
block_size_max
Definition: ztee.py:23
def ztee.GZipLog.write (   self,
  bytes 
)

Definition at line 83 of file ztee.py.

References ztee.GZipLog.block_size, and ztee.GZipLog.try_flush().

Referenced by pkg.AbstractPkg.generate().

83  def write(self, bytes):
84  if bytes:
85  self.block.append(bytes)
86  self.block_size += len(bytes)
87 
88  self.try_flush()
89 
block_size
Definition: ztee.py:22
def write(self, bytes)
Definition: ztee.py:83
def try_flush(self)
Definition: ztee.py:76
def ztee.GZipLog.write_block (   self,
  data 
)

Definition at line 33 of file ztee.py.

Referenced by ztee.GZipLog.flush_block().

33  def write_block(self, data):
34  self.file.write(self.zstream.compress(data))
35  self.file.write(self.zstream.flush(zlib.Z_FULL_FLUSH))
36 
def write_block(self, data)
Definition: ztee.py:33

Member Data Documentation

ztee.GZipLog.block

Definition at line 21 of file ztee.py.

Referenced by ztee.GZipLog.flush_block().

ztee.GZipLog.block_size

Definition at line 22 of file ztee.py.

Referenced by ztee.GZipLog.flush_block(), ztee.GZipLog.try_flush(), and ztee.GZipLog.write().

ztee.GZipLog.block_size_max

Definition at line 23 of file ztee.py.

Referenced by ztee.GZipLog.try_flush().

ztee.GZipLog.block_timeout

Definition at line 24 of file ztee.py.

Referenced by ztee.GZipLog.try_flush().

ztee.GZipLog.file

Definition at line 15 of file ztee.py.

Referenced by ztee.GZipLog.finish().

ztee.GZipLog.file_max_size

Definition at line 28 of file ztee.py.

Referenced by ztee.GZipLog.flush_block().

ztee.GZipLog.file_min_size

Definition at line 27 of file ztee.py.

Referenced by ztee.GZipLog.flush_block().

ztee.GZipLog.file_truncate_pos

Definition at line 30 of file ztee.py.

Referenced by ztee.GZipLog.flush_block().

ztee.GZipLog.file_truncate_state

Definition at line 31 of file ztee.py.

Referenced by ztee.GZipLog.flush_block().

ztee.GZipLog.last_flush

Definition at line 17 of file ztee.py.

Referenced by ztee.GZipLog.flush_block(), and ztee.GZipLog.try_flush().

ztee.GZipLog.zstream

Definition at line 18 of file ztee.py.

Referenced by ztee.GZipLog.flush_block().