3737
3838from .utils import \
3939 get_bin_path , \
40+ file_tail as _file_tail , \
4041 pg_version_ge as _pg_version_ge , \
4142 reserve_port as _reserve_port , \
4243 release_port as _release_port , \
@@ -168,12 +169,12 @@ def _maybe_stop_logger(self):
168169 self ._logger .stop ()
169170
170171 def _format_verbose_error (self , message = None ):
171- # list of important files
172+ # list of important files + N of last lines
172173 files = [
173- os .path .join (self .data_dir , "postgresql.conf" ),
174- os .path .join (self .data_dir , "recovery.conf" ),
175- os .path .join (self .data_dir , "pg_hba.conf" ),
176- self .pg_log_name # main log file
174+ ( os .path .join (self .data_dir , "postgresql.conf" ), 0 ),
175+ ( os .path .join (self .data_dir , "recovery.conf" ), 0 ),
176+ ( os .path .join (self .data_dir , "pg_hba.conf" ), 0 ),
177+ ( self .pg_log_name , TestgresConfig . error_log_lines )
177178 ]
178179
179180 error_text = ""
@@ -183,14 +184,20 @@ def _format_verbose_error(self, message=None):
183184 error_text += message
184185 error_text += '\n ' * 2
185186
186- for f in files :
187+ for f , num_lines in files :
187188 # skip missing files
188189 if not os .path .exists (f ):
189190 continue
190191
191- # append contents
192- with io .open (f , "r" ) as _f :
193- lines = _f .read ()
192+ with io .open (f , "rb" ) as _f :
193+ if num_lines > 0 :
194+ # take last N lines of file
195+ lines = b'' .join (_file_tail (_f , num_lines )).decode ('utf-8' )
196+ else :
197+ # read whole file
198+ lines = _f .read ().decode ('utf-8' )
199+
200+ # append contents
194201 error_text += u"{}:\n ----\n {}\n " .format (f , lines )
195202
196203 return error_text
0 commit comments