How to Name the 'Screen' Logfile from the -L Flag

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 mode O_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



Leave a reply



Submit