11import { logger } from "./logger.js"
22import * as NodeShell from "node:child_process"
3- import * as fs from "node:fs"
43import { Namespace } from "./model.js"
54
5+ export const TAIL_SCRIPT = "k8s-deployer/scripts/tail-container-log.sh"
6+
67export class PodLogTail {
78
89 private tailer ?: NodeShell . ChildProcess
@@ -16,16 +17,12 @@ export class PodLogTail {
1617 start ( containerName = "" ) : PodLogTail {
1718 if ( this . tailer ) throw new Error ( `Tailer is already attached to process with PID: ${ this . tailer . pid } ` )
1819
19- // creating streams
20- const out = fs . openSync ( this . logFilePath , 'a' )
21- const err = fs . openSync ( this . logFilePath , 'a' )
22-
2320 this . tailer = NodeShell . spawn (
24- "k8s-deployer/scripts/tail-container-log.sh" ,
25- [ this . namespace , this . service , containerName ] ,
21+ TAIL_SCRIPT ,
22+ [ this . namespace , this . service , containerName , "" , this . logFilePath . replace ( / \. l o g $ / , "" ) ] ,
2623 {
2724 detached : true ,
28- stdio : [ 'ignore' , out , err ]
25+ stdio : 'ignore'
2926 }
3027 )
3128
@@ -43,7 +40,7 @@ export class PodLogTail {
4340 if ( wasStopped ) {
4441 logger . info ( "PodLogTail.stop(): The log tailer with PID %s has been stopped" , pid )
4542 } else {
46- logger . warn ( "PodLogTail.stop(): Unable to stop the log tailer with PID %s. Has it been stopped already?" , pid )
43+ logger . warn ( "PodLogTail.stop(): Unable to stop the log tailer with PID %s. Has it been stopped already?" , pid )
4744 }
4845
4946 return wasStopped
0 commit comments