@@ -91,9 +91,10 @@ def cmd_sol(args, mc):
9191 """Fetch SOL logs."""
9292 color = args .color
9393 if args .follow :
94- # Fetch last 10 lines to start, then poll for new ones
94+ # Fetch last lines to start, then poll for new ones
95+ tail_n = args .tail or 10
9596 data = mc .get_sol_logs (args .machine_id , start_id = args .start_id ,
96- limit = 10 , sort = 'desc' )
97+ limit = tail_n , sort = 'desc' )
9798 lines = list (reversed (data .get ('lines' , [])))
9899 for entry in lines :
99100 ts = entry .get ('ts' , '' )
@@ -114,6 +115,19 @@ def cmd_sol(args, mc):
114115 except KeyboardInterrupt :
115116 return 0
116117
118+ if args .tail :
119+ data = mc .get_sol_logs (args .machine_id , limit = args .tail , sort = 'desc' )
120+ if args .json :
121+ print (json .dumps (data , indent = 2 ))
122+ return 0
123+ lines = list (reversed (data .get ('lines' , [])))
124+ for entry in lines :
125+ ts = entry .get ('ts' , '' )
126+ print (f"{ ts } { _sanitize (entry ['line' ], keep_color = color )} " , end = '' )
127+ last_id = data .get ('last_id' , 0 )
128+ print (f"last_id={ last_id } " , file = sys .stderr )
129+ return 0
130+
117131 data = mc .get_sol_logs (args .machine_id , start_id = args .start_id ,
118132 limit = args .limit )
119133 if args .json :
@@ -238,6 +252,8 @@ def main(argv=None):
238252 help = 'follow output like tail -f' )
239253 p_sol .add_argument ('--interval' , type = float , default = 2 ,
240254 help = 'poll interval in seconds for -f (default: 2)' )
255+ p_sol .add_argument ('-n' , '--tail' , type = int , default = None ,
256+ help = 'show last N lines (like tail -N)' )
241257 p_sol .add_argument ('--color' , action = 'store_true' ,
242258 help = 'preserve ANSI color/formatting in output' )
243259
0 commit comments