@@ -10,16 +10,18 @@ program
1010  . arguments ( '[name]' ) 
1111  . option ( '-f, --nofollow' ,  'Disable live updates.' ) 
1212  . option ( '-r, --raw' ,  'Enable raw JSON outputs.' ) 
13+   . option ( '-b, --logbuffer [lines]' ,  'Log buffering in lines [100]' ,  100 ) 
1314  . action ( name  => 
1415    log ( { 
1516      name : name , 
1617      raw : program . raw , 
17-       follow : ! Boolean ( program . nofollow ) 
18+       follow : ! Boolean ( program . nofollow ) , 
19+       logbuffer : parseInt ( program . logbuffer ) 
1820    } ) 
1921  ) 
2022  . parse ( process . argv ) ; 
2123
22- function  log ( { name,  follow,  raw} )  { 
24+ function  log ( { name,  follow,  raw,  logbuffer } )  { 
2325  configuration 
2426    . load ( ) 
2527    . then ( settings  =>  { 
@@ -39,22 +41,23 @@ function log({name, follow, raw}) {
3941    . then ( settings  =>  { 
4042      process . stderr . write ( '\x1B[?25l' ) ;  //hide terminal cursor 
4143      const  es  =  new  EventSource ( 
42-         `${ settings . url } ${ name  ||  settings . serviceName } ${ ! follow  ? 'follow='  +  follow  : 'follow=true' }  , 
44+         `${ settings . url } ${ name  ||  settings . serviceName } ${ ! follow  
45+           ? 'follow='  +  follow  
46+           : 'follow=true' }  &tail=${ logbuffer } , 
4347        { headers : { connection : 'keep-alive' ,  'cache-control' : 'no-cache' ,  authorization : `Bearer ${ settings . token }  } } 
4448      ) ; 
45-       if  ( ! raw )  process . stdout . write ( chalk . gray ( `Connecting ...` ) ) ; 
49+       if  ( ! raw )  process . stdout . write ( chalk . gray ( `Waiting for logs ...` ) ) ; 
4650
4751      es . onopen  =  ( )  =>  { 
4852        if  ( ! raw )  { 
4953          process . stdout . cursorTo ( 0 ) ; 
5054          process . stdout . clearLine ( ) ; 
51-           process . stdout . write ( `${ chalk . green ( 'Connected!' ) } ${ chalk . gray ( 'Receiving data  ...' ) }  ) ; 
55+           process . stdout . write ( `${ chalk . green ( 'Connected!' ) } ${ chalk . gray ( 'Receiving logs  ...' ) }  ) ; 
5256        } 
5357      } ; 
5458
5559      es . onerror  =  ( )  =>  { 
5660        process . stderr . write ( '\x1B[?25h' ) ;  //show terminal cursor 
57-         console . error ( 'Log-Stream error occurred. Retry...' ) ; 
5861      } ; 
5962      es . onmessage  =  e  =>  { 
6063        if  ( raw  &&  e . data  &&  e . data  !==  '{}' )  return  console . log ( e . data ) ; 
0 commit comments