mirror of
https://github.com/WiiLink24/wfc-server.git
synced 2026-03-21 17:44:58 -05:00
Merge pull request #48 from MikeIsAStar/allow-for-console-output-to-be-saved-to-a-file
Allow for console output to be saved to a file
This commit is contained in:
commit
5bdd9ddf0c
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -4,9 +4,11 @@ salt.bin
|
|||
*.der
|
||||
*.pem
|
||||
|
||||
# Logs
|
||||
logs
|
||||
|
||||
# Payload data
|
||||
payload
|
||||
|
||||
# Editor files
|
||||
.vscode
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ type Config struct {
|
|||
EnableHTTPSExploitWii *bool `xml:"enableHttpsExploitWii,omitempty"`
|
||||
EnableHTTPSExploitDS *bool `xml:"enableHttpsExploitDS,omitempty"`
|
||||
LogLevel *int `xml:"logLevel"`
|
||||
LogOutput string `xml:"logOutput"`
|
||||
CertPath string `xml:"certPath"`
|
||||
KeyPath string `xml:"keyPath"`
|
||||
CertPathWii string `xml:"certDerPathWii"`
|
||||
|
|
@ -78,5 +79,9 @@ func GetConfig() Config {
|
|||
config.LogLevel = &level
|
||||
}
|
||||
|
||||
if config.LogOutput == "" {
|
||||
config.LogOutput = "StdOutAndFile"
|
||||
}
|
||||
|
||||
return config
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,12 +33,25 @@
|
|||
<username>username</username>
|
||||
<password>password</password>
|
||||
|
||||
<!-- Database information-->
|
||||
<!-- Database information -->
|
||||
<databaseAddress>127.0.0.1</databaseAddress>
|
||||
<databaseName>wwfc</databaseName>
|
||||
|
||||
<!-- Log verbosity -->
|
||||
|
||||
<!-- Logging configuration -->
|
||||
<!-- Log verbosity
|
||||
0: No messages are logged.
|
||||
1: General messages are logged.
|
||||
2: General and error messages are logged.
|
||||
3: General, error, and warning messages are logged.
|
||||
4: General, error, warning, and informational messages are logged.
|
||||
-->
|
||||
<logLevel>4</logLevel>
|
||||
<!-- Log output
|
||||
None : Messages are discarded.
|
||||
StdOut : Messages are written to standard output.
|
||||
StdOutAndFile: Messages are written to both standard output and a file.
|
||||
-->
|
||||
<logOutput>StdOutAndFile</logOutput>
|
||||
|
||||
<!-- API secret -->
|
||||
<apiSecret>hQ3f57b3tW2WnjJH3v</apiSecret>
|
||||
|
|
|
|||
|
|
@ -1,18 +1,52 @@
|
|||
package logging
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/logrusorgru/aurora/v3"
|
||||
)
|
||||
|
||||
var logLevel = 0
|
||||
var (
|
||||
logDir = "./logs"
|
||||
logLevel = 0
|
||||
)
|
||||
|
||||
func SetLevel(level int) {
|
||||
logLevel = level
|
||||
}
|
||||
|
||||
func SetOutput(output string) error {
|
||||
switch output {
|
||||
case "None":
|
||||
log.SetOutput(io.Discard)
|
||||
case "StdOut":
|
||||
log.SetOutput(os.Stdout)
|
||||
case "StdOutAndFile":
|
||||
if err := os.MkdirAll(logDir, 0700); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
time := time.Now()
|
||||
logFilePath := time.Format(logDir + "/2006-01-02-15-04-05.log")
|
||||
|
||||
file, err := os.OpenFile(logFilePath, os.O_WRONLY|os.O_CREATE, 0400)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.SetOutput(io.MultiWriter(os.Stdout, file))
|
||||
default:
|
||||
return errors.New("invalid output value provided")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Notice(module string, arguments ...any) {
|
||||
if logLevel < 1 {
|
||||
return
|
||||
|
|
|
|||
3
main.go
3
main.go
|
|
@ -18,6 +18,9 @@ import (
|
|||
func main() {
|
||||
config := common.GetConfig()
|
||||
logging.SetLevel(*config.LogLevel)
|
||||
if err := logging.SetOutput(config.LogOutput); err != nil {
|
||||
logging.Error("MAIN", err)
|
||||
}
|
||||
|
||||
wg := &sync.WaitGroup{}
|
||||
actions := []func(){nas.StartServer, gpcm.StartServer, qr2.StartServer, gpsp.StartServer, serverbrowser.StartServer, sake.StartServer, natneg.StartServer, api.StartServer, gamestats.StartServer}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user