diff --git a/CHANGELOG.md b/CHANGELOG.md index 785f624..3740d9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,19 @@ Before any major/minor/patch bump all unit tests will be run to verify they pass - [x] +# [0.3.0] - 2025-04-05 + +### Changed + +- `-loglevel` flag is now of type string. It accepts any one of trace, debug, info, warn, error, fatal or panic. + - It defaults to warn. + +# [0.2.0] - 2025-02-03 + +### Added + +- If neither the interactive flag is passed or any command line arguments then a *rcon status* command will be run. + # [0.1.0] - 2024-11-29 ### Changed diff --git a/README.md b/README.md index 889a38c..488268c 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ Arguments following the flags will be sent as rcon commands. You may send multip Pass `interactive (-i shorthand)` flag to enable interactive mode, for example: -``` +```bash q3rcon -h=localhost -p=30000 -r="rconpassword" -i ``` @@ -123,16 +123,31 @@ Since you can include the q3rcon package into your own package you can easily ma ## Logging -Log level may be set by passing the `-l` flag with a number from 0 up to 6 where +The `-loglevel` flag allows you to control the verbosity of the application's logging output. -0 = Panic, 1 = Fatal, 2 = Error, 3 = Warning, 4 = Info, 5 = Debug, 6 = Trace +Acceptable values for this flag are: -[status]: ./img/status.png -[mapname]: ./img/mapname.png +- `trace` +- `debug` +- `info` +- `warn` +- `error` +- `fatal` +- `panic` + +For example, to set the log level to `debug`, you can use: + +```bash +q3rcon -p=28960 -r="rconpassword" -loglevel=debug -i +``` + +The default log level is `warn` if the flag is not specified. ## Further Notes This rcon client is fully compatible with the [Q3 Rcon Proxy][q3rcon-proxy] package. +[status]: ./img/status.png +[mapname]: ./img/mapname.png [q3rcon-proxy]: https://github.com/onyx-and-iris/q3rcon-proxy/tree/dev \ No newline at end of file diff --git a/cmd/q3rcon/main.go b/cmd/q3rcon/main.go index 8058e31..9d5b85c 100644 --- a/cmd/q3rcon/main.go +++ b/cmd/q3rcon/main.go @@ -6,7 +6,6 @@ import ( "fmt" "io" "os" - "slices" "strings" "github.com/onyx-and-iris/q3rcon" @@ -25,7 +24,7 @@ func main() { port int rconpass string interactive bool - loglevel int + loglevel string ) flag.StringVar(&host, "host", "localhost", "hostname of the gameserver") @@ -38,13 +37,16 @@ func main() { flag.BoolVar(&interactive, "interactive", false, "run in interactive mode") flag.BoolVar(&interactive, "i", false, "run in interactive mode") - flag.IntVar(&loglevel, "loglevel", int(log.WarnLevel), "log level") - flag.IntVar(&loglevel, "l", int(log.WarnLevel), "log level (shorthand)") + flag.StringVar(&loglevel, "loglevel", "warn", "log level") + flag.StringVar(&loglevel, "l", "warn", "log level (shorthand)") + flag.Parse() - if slices.Contains(log.AllLevels, log.Level(loglevel)) { - log.SetLevel(log.Level(loglevel)) + level, err := log.ParseLevel(loglevel) + if err != nil { + exitOnError(fmt.Errorf("invalid log level: %s", loglevel)) } + log.SetLevel(level) if port < 1024 || port > 65535 { exitOnError(fmt.Errorf("invalid port value, got: (%d) expected: in range 1024-65535", port)) diff --git a/internal/packet/request.go b/internal/packet/request.go index 58f93a6..b77d0b4 100644 --- a/internal/packet/request.go +++ b/internal/packet/request.go @@ -3,6 +3,8 @@ package packet import ( "bytes" "fmt" + + log "github.com/sirupsen/logrus" ) const bufSz = 512 @@ -29,5 +31,6 @@ func (r Request) Encode(cmd string) []byte { r.buf.Reset() r.buf.Write(r.Header()) r.buf.WriteString(fmt.Sprintf(" %s %s", r.password, cmd)) + log.Tracef("Encoded request: %s", r.buf.String()) return r.buf.Bytes() }