Compare commits
2 commits
ccd2140c53
...
1527c198e0
Author | SHA1 | Date | |
---|---|---|---|
1527c198e0 | |||
2b84d7eb2a |
3 changed files with 40 additions and 11 deletions
39
flags.go
39
flags.go
|
@ -1,17 +1,23 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "flag"
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
flagPrettyPrint *bool = flag.Bool(
|
flagLogJson *bool = flag.Bool(
|
||||||
"pretty",
|
"jsonlogs",
|
||||||
false,
|
false,
|
||||||
"If set, pretty prints logging entries which would be json objects otherwise",
|
"If set, writes logging messages as json objects instead",
|
||||||
)
|
)
|
||||||
flagConfigFile *string = flag.String(
|
flagConfigFile *string = flag.String(
|
||||||
"config",
|
"config",
|
||||||
"config.toml",
|
"config.toml",
|
||||||
"Location of the config file. Defaults to \"config.toml\"",
|
"Location of the config file",
|
||||||
)
|
)
|
||||||
flagLogLevel *string = flag.String(
|
flagLogLevel *string = flag.String(
|
||||||
"loglevel",
|
"loglevel",
|
||||||
|
@ -25,6 +31,29 @@ var (
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func flagUsage() {
|
||||||
|
executable, err := os.Executable()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal().Err(err).Msg("Failed to get own path")
|
||||||
|
}
|
||||||
|
fmt.Fprintf(os.Stderr, "Usage of %s:\n", executable)
|
||||||
|
fmt.Fprintln(os.Stderr, "\t-config string")
|
||||||
|
fmt.Fprintln(os.Stderr, "\t\tLocation of the config file (default: \"config.toml\")")
|
||||||
|
fmt.Fprintln(os.Stderr, "\t-loglevel string")
|
||||||
|
fmt.Fprintln(
|
||||||
|
os.Stderr,
|
||||||
|
"\t\tSet the logging level. Options are: Trace, Debug, Info, Warning, Error and Fatal. Case insensitive (default: \"Info\")",
|
||||||
|
)
|
||||||
|
fmt.Fprintln(os.Stderr, "\t-validate-config")
|
||||||
|
fmt.Fprintln(
|
||||||
|
os.Stderr,
|
||||||
|
"\t\tIf set, the server will only validate the config (or write the default one) and then quit",
|
||||||
|
)
|
||||||
|
fmt.Fprintln(os.Stderr, "\t-jsonlogs")
|
||||||
|
fmt.Fprintln(os.Stderr, "\t\tIf set, writes logging messages as json objects instead")
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
flag.Usage = flagUsage
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
}
|
}
|
||||||
|
|
4
main.go
4
main.go
|
@ -96,7 +96,6 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func setLogLevel() {
|
func setLogLevel() {
|
||||||
log.Info().Str("new-level", *flagLogLevel).Msg("Attempting to set log level")
|
|
||||||
switch strings.ToLower(*flagLogLevel) {
|
switch strings.ToLower(*flagLogLevel) {
|
||||||
case "trace":
|
case "trace":
|
||||||
zerolog.SetGlobalLevel(zerolog.TraceLevel)
|
zerolog.SetGlobalLevel(zerolog.TraceLevel)
|
||||||
|
@ -113,10 +112,11 @@ func setLogLevel() {
|
||||||
default:
|
default:
|
||||||
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
||||||
}
|
}
|
||||||
|
log.Info().Str("new-level", *flagLogLevel).Msg("New logging level set")
|
||||||
}
|
}
|
||||||
|
|
||||||
func setLogger(extraLogWriters ...io.Writer) {
|
func setLogger(extraLogWriters ...io.Writer) {
|
||||||
if *flagPrettyPrint {
|
if !*flagLogJson {
|
||||||
console := zerolog.ConsoleWriter{Out: os.Stderr}
|
console := zerolog.ConsoleWriter{Out: os.Stderr}
|
||||||
log.Logger = zerolog.New(zerolog.MultiLevelWriter(append([]io.Writer{console}, extraLogWriters...)...)).
|
log.Logger = zerolog.New(zerolog.MultiLevelWriter(append([]io.Writer{console}, extraLogWriters...)...)).
|
||||||
With().
|
With().
|
||||||
|
|
|
@ -3,10 +3,10 @@ package server
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/google/jsonapi"
|
|
||||||
"github.com/rs/zerolog/hlog"
|
|
||||||
"git.mstar.dev/mstar/goutils/other"
|
"git.mstar.dev/mstar/goutils/other"
|
||||||
"git.mstar.dev/mstar/linstrom/storage"
|
"git.mstar.dev/mstar/linstrom/storage"
|
||||||
|
"github.com/google/jsonapi"
|
||||||
|
"github.com/rs/zerolog/hlog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Notes
|
// Notes
|
||||||
|
@ -59,7 +59,7 @@ func linstromGetNote(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func linstromUpdateNote(w http.ResponseWriter, r *http.Request) {}
|
func linstromUpdateNote(w http.ResponseWriter, r *http.Request) {}
|
||||||
func linstromNewNote(w http.ResponseWriter, r *http.Request) {
|
func linstromNewNote(w http.ResponseWriter, r *http.Request) {
|
||||||
store := StorageFromRequest(r)
|
// store := StorageFromRequest(r)
|
||||||
actorId, ok := ActorIdFromRequest(r)
|
actorId, ok := ActorIdFromRequest(r)
|
||||||
log := hlog.FromRequest(r)
|
log := hlog.FromRequest(r)
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ func linstromNewNote(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _ = store.CreateNote()
|
// _, _ = store.CreateNoteLocal(creatorId string, rawContent string, contentWarning *string, timestamp time.Time, attachmentIds []string, emoteIds []string, repliesToId *string, quotesId *string, accessLevel storage.NoteAccessLevel, tags []string)
|
||||||
}
|
}
|
||||||
func linstromDeleteNote(w http.ResponseWriter, r *http.Request) {}
|
func linstromDeleteNote(w http.ResponseWriter, r *http.Request) {}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue