I'm using the Golang Docker SDK to output container logs. The container is running a scan and outputs specific information about the scan job start time, end time, mean scan duration as below:
Selected XML parser javax.xml.bind.util.JAXBSource$1 does not recognize the feature http://xml.org/sax/features/validation
Generated ./reports/CSR1000V_RTR2.json
Generated ./reports/CSR1000V_RTR6.json
Generated ./reports/CSR1000V_RTR3.json
Scan start time: Mon Aug 27 03:39:24 GMT 2018
Scan end time: Mon Aug 27 03:39:40 GMT 2018
Mean target scan duration: 3906ms
I use code below to convert the io.Reader into a string:
out, err := cli.ContainerLogs(ctx, resp.ID, types.ContainerLogsOptions{
ShowStdout: true,
Follow: true})
if err != nil {
panic(err)
}
defer out.Close()
//io.Copy(os.Stdout, out)
b, err := ioutil.ReadAll(out)
fmt.Println(string(b))
How in Golang can I parse only the last 3 lines and capture the following values only from the stdout:
fmt.Println("The scan has started at: " +startime)
fmt.Println("The scan has ended at: " +endtime)
fmt.Println("The scan job took xxx ms to scan each device")