xyproto / algernon

Small self-contained pure-Go web server with Lua, Teal, Markdown, Ollama, HTTP/2, QUIC, Redis, SQLite and PostgreSQL support ++
https://algernon.roboticoverlords.org
BSD 3-Clause "New" or "Revised" License
2.78k stars 138 forks source link

Command line arg --internal=filename ignores filename #122

Open esumerfd opened 2 years ago

esumerfd commented 2 years ago

Starting the server like this:

algernon --verbose --accesslog=ssl.log --internal=algernon.log

Writes the internal log to a file called internal.log while the ServerInfo() says

Internal log file:  algernon.log

: algernon --version Algernon 1.14.0

xyproto commented 2 years ago

Thanks for reporting!

esumerfd commented 2 years ago

SCRATCH THIS: bad info: config.go:694 should reference ac.internalLogFilename instead of hard coding "internal.log"

esumerfd commented 2 years ago

Now perhaps I understand. Perhaps if the os.Open was an OpenFile with a O_CREATE option it would create the custom file name.

I can make it work by touching the file before running then it choose it. Feels like the flows for selecting the default filename may need to be done before the open.

    // Direct internal logging elsewhere
    internalLogFile, err := os.Open(ac.internalLogFilename)
    if err != nil {
        // Could not open the internalLogFilename filename, try using another filename
        internalLogFile, err = os.OpenFile("internal.log", os.O_CREATE|os.O_APPEND|os.O_WRONLY, ac.defaultPermissions)