diff --git a/Debugging.md b/Debugging.md index 989eab3..f332d54 100644 --- a/Debugging.md +++ b/Debugging.md @@ -8,6 +8,23 @@ The `log` package has a function that allows redirection of all logged messages https://godoc.org/log#SetOutput +Example: +```go +f, err := os.Create("debug.log") +if err != nil { + log.Fatal(err) +} +log.SetOutput(f) +``` + +Now we can add debug statement anywhere in the code like this: + +```go +log.Printf("Debugging: %v", someVar) +``` + +The log messages will be written into a file named `debug.log`. + ## Using the text widget. `Termdash` comes with a `Text` widget which is capable of displaying any text messages. If your application allows it, consider including a separate `Text` widget in your layout and have it display any debug messages directly on the terminal.