Is it possible to name the 'screen' logfile from the -L flag?
Probably the easiest way is to use the following (starting from Screen version 4.06.02 and up):
screen -L -Logfile log_filename your_command
Save Screen (program) output to a file
There is a command line option for logging. The output is saved to screenlog.n file, where n is a number of the screen.
From man pages of screen:
‘-L’ Tell screen to turn on automatic output logging for the windows.
How do I view a log file generated by screen (screenlog.0)
I just found a screenlog.0 on the net; it is plain text, with some escape sequences. Just 'cat' the file, you should be able to view it just fine.
[after more checking]
Control-A H is what generates the screenlog on my system. And though 'cat' works, you'll miss a lot of data. Use 'more' instead of 'less' to interpolate the escape codes.
Copy screenlog.n file and restart log?
I found that screen will create a new screenlog.n file automatically if I delete the existing one while a screen session is detached. I simply scheduled a cronjob to copy and rename the existing file and then delete it. A new screenlog.n file is created as soon as there is something new to log.
How to write log to file
os.Open()
must have worked differently in the past, but this works for me:
f, err := os.OpenFile("testlogfile", os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666)
if err != nil {
log.Fatalf("error opening file: %v", err)
}
defer f.Close()
log.SetOutput(f)
log.Println("This is a test log entry")
Based on the Go docs, os.Open()
can't work for log.SetOutput
, because it opens the file "for reading:"
func Open
func Open(name string) (file *File, err error)
Open
opens the named
file for reading. If successful, methods on the returned file can be
used for reading; the associated file descriptor has modeO_RDONLY
. If
there is an error, it will be of type*PathError
.
EDIT
Moved defer f.Close()
to after if err != nil
check
Related Topics
Is It Ok (Performance-Wise) to Have Hundreds or Thousands of Files in the Same Linux Directory
How to Toggle Cr/Lf in Gnu Screen
How to Mmap the Stack for the Clone() System Call on Linux
Set Environment Variable with Space in Linux
How to Store the Output of a Git Command in a Variable
Tracking Threads Memory and CPU Consumption
How to Write Conditional Import Statements in Qml
Nasm - Symbol 'Printf' Causes Overflow in R_X86_64_Pc32 Relocation
How to Use Stdin with Caption in Imagemagick
Vim Background with Gnu Screen
Add Blank Line After Every Result in Grep
Parsing Shell Script Arguments
Replace a Text with a Variable
How to Start Redis-Server on a Different Port Than the Default Port 6379 in Ubuntu
Is There a Core Linux API Analogous to Windows Winapi, in Particular for Creating Gui Applications