Compare commits
2 Commits
8143c2d08a
...
6b17bec30c
Author | SHA1 | Date | |
---|---|---|---|
6b17bec30c | |||
47c2d3b2ec |
21
env/env.go
vendored
Normal file
21
env/env.go
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
package env
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func Env() {
|
||||
os.Setenv("GOBYEXAMPLE", "WORKS")
|
||||
fmt.Println("$GOBYEXAMPLE=", os.Getenv("GOBYEXAMPLE"))
|
||||
envGoRoot := os.Getenv("GOROOT")
|
||||
fmt.Println("$GOROOT=", envGoRoot)
|
||||
|
||||
fmt.Println()
|
||||
fmt.Println("All env vars:")
|
||||
for _, envLine := range os.Environ() {
|
||||
pair := strings.SplitN(envLine, "=", 2)
|
||||
fmt.Printf("%s=%s\n", pair[0], pair[1])
|
||||
}
|
||||
}
|
42
logging/logging.go
Normal file
42
logging/logging.go
Normal file
@ -0,0 +1,42 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"log"
|
||||
"log/slog"
|
||||
"os"
|
||||
)
|
||||
|
||||
func Logging() {
|
||||
log.Println("Baby's first log!")
|
||||
|
||||
log.SetFlags(log.LstdFlags | log.Lmicroseconds)
|
||||
log.Println("Log with microseconds!")
|
||||
|
||||
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
||||
log.Println("Now with filename!")
|
||||
|
||||
mlog := log.New(os.Stdout, "[mlog] ", log.LstdFlags|log.Lshortfile)
|
||||
mlog.Println("My own logger!")
|
||||
|
||||
mlog.SetPrefix("[mlog with SetPrefix] ")
|
||||
mlog.Println("Changed prefix")
|
||||
|
||||
var logBuffer bytes.Buffer
|
||||
buflog := log.New(&logBuffer, "[bytes] ", log.LstdFlags|log.Lshortfile)
|
||||
|
||||
buflog.Println("Writing to a bytes buffer")
|
||||
buflog.Println("Writing more to the bytes buffer")
|
||||
|
||||
fmt.Println()
|
||||
fmt.Println("Printing logs from bytes buffer below:")
|
||||
fmt.Println(logBuffer.String())
|
||||
|
||||
jsonHandler := slog.NewJSONHandler(os.Stderr, nil)
|
||||
jlog := slog.New(jsonHandler)
|
||||
jlog.Info("First json log entry")
|
||||
jlog.Info("kv args", "key1", 1, "key2", 2, "key3", true)
|
||||
jlog.Warn("warning!!!")
|
||||
jlog.Error("error!!!")
|
||||
}
|
8
main.go
8
main.go
@ -43,7 +43,9 @@ import (
|
||||
// "git.sangeeth.dev/gobyexample/tmp"
|
||||
// "git.sangeeth.dev/gobyexample/embed"
|
||||
// "git.sangeeth.dev/gobyexample/cli"
|
||||
"git.sangeeth.dev/gobyexample/subcmd"
|
||||
// "git.sangeeth.dev/gobyexample/subcmd"
|
||||
// "git.sangeeth.dev/gobyexample/env"
|
||||
"git.sangeeth.dev/gobyexample/logging"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -89,5 +91,7 @@ func main() {
|
||||
// tmp.Tmp()
|
||||
// embed.Embed()
|
||||
// cli.Cli()
|
||||
subcmd.SubCmd()
|
||||
// subcmd.SubCmd()
|
||||
// env.Env()
|
||||
logging.Logging()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user