Improve logs ()

This commit is contained in:
Antonio Navarro Perez 2021-11-20 11:57:25 -08:00 committed by GitHub
parent 66eadf35dc
commit 5d4e48f0f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 343 additions and 33 deletions

View file

@ -11,6 +11,7 @@ const (
const (
metadataFolder = "./distribyted-data/metadata"
mountFolder = "./distribyted-data/mount"
logsFolder = "./distribyted-data/logs"
)
func DefaultConfig() *Root {
@ -24,13 +25,19 @@ func DefaultConfig() *Root {
Pass: "admin",
},
Torrent: &TorrentGlobal{
GlobalCacheSize: 1024,
GlobalCacheSize: 2048,
MetadataFolder: metadataFolder,
AddTimeout: 60,
},
Fuse: &FuseGlobal{
AllowOther: false,
Path: mountFolder,
},
Log: &Log{
Path: logsFolder,
MaxBackups: 2,
MaxSize: 50,
},
Routes: []*Route{
{
Name: "multimedia",

View file

@ -7,7 +7,6 @@ import (
"path/filepath"
"github.com/distribyted/distribyted"
"github.com/rs/zerolog/log"
"gopkg.in/yaml.v3"
)
@ -43,7 +42,7 @@ func (c *Handler) createFromTemplateFile() ([]byte, error) {
func (c *Handler) GetRaw() ([]byte, error) {
f, err := ioutil.ReadFile(c.p)
if os.IsNotExist(err) {
log.Info().Str("file", c.p).Msg("configuration file does not exist, creating from template file")
fmt.Println("configuration file does not exist, creating from template file:", c.p)
return c.createFromTemplateFile()
}
@ -69,11 +68,3 @@ func (c *Handler) Get() (*Root, error) {
return conf, nil
}
func (c *Handler) Set(b []byte) error {
if err := yaml.Unmarshal(b, &Root{}); err != nil {
return fmt.Errorf("error parsing configuration file: %w", err)
}
return ioutil.WriteFile(c.p, b, 0644)
}

View file

@ -6,11 +6,21 @@ type Root struct {
WebDAV *WebDAVGlobal `yaml:"webdav"`
Torrent *TorrentGlobal `yaml:"torrent"`
Fuse *FuseGlobal `yaml:"fuse"`
Log *Log `yaml:"log"`
Routes []*Route `yaml:"routes"`
}
type Log struct {
Debug bool `yaml:"debug"`
MaxBackups int `yaml:"max_backups"`
MaxSize int `yaml:"max_size"`
MaxAge int `yaml:"max_age"`
Path string `yaml:"path"`
}
type TorrentGlobal struct {
AddTimeout int `yaml:"add_timeout,omitempty"`
GlobalCacheSize int64 `yaml:"global_cache_size,omitempty"`
MetadataFolder string `yaml:"metadata_folder,omitempty"`
DisableIPv6 bool `yaml:"disable_ipv6,omitempty"`