Junior — Middle
How can you open a log file for real-time monitoring of its current state?
sobes.tech AI
Answer from AI
To monitor a log file in real-time, the tail command with the -f option is often used in Unix-like systems:
tail -f /path/to/logfile.log
This command displays the last lines of the file and continues to show new lines as they are added.
In Windows, PowerShell can be used:
Get-Content -Path "C:\path\to\logfile.log" -Wait
For automation in tests, you can write a script that reads the file line by line, waiting for new data to appear, or use specialized libraries for log handling.