Reworked logging. Store all actions in one file.log.
This commit is contained in:
parent
31d2c4fd21
commit
33ec19647b
@ -44,23 +44,11 @@ func main() {
|
||||
}
|
||||
defer logErr.Close()
|
||||
|
||||
logUpload, err := logging.New(config.Log.Upload)
|
||||
logFile, err := logging.New(config.Log.File)
|
||||
if err != nil {
|
||||
log.Fatalln("upload logger:", err)
|
||||
log.Fatalln("file logger:", err)
|
||||
}
|
||||
defer logUpload.Close()
|
||||
|
||||
logDownload, err := logging.New(config.Log.Download)
|
||||
if err != nil {
|
||||
log.Fatalln("download logger:", err)
|
||||
}
|
||||
defer logDownload.Close()
|
||||
|
||||
logDelete, err := logging.New(config.Log.Delete)
|
||||
if err != nil {
|
||||
log.Fatalln("delete logger:", err)
|
||||
}
|
||||
defer logDelete.Close()
|
||||
defer logFile.Close()
|
||||
|
||||
watcha, err := watcher.NewInotifyWatcher()
|
||||
if err != nil {
|
||||
@ -80,7 +68,7 @@ func main() {
|
||||
|
||||
watcha.WatchForMask(uploadDirNotify, watcher.CrDelMask)
|
||||
|
||||
hand := http.NewUploadHandlers(config, logErr, logUpload, logDownload, logDelete, &uploadDirSize)
|
||||
hand := http.NewUploadHandlers(config, logErr, logFile, &uploadDirSize)
|
||||
srv := http.NewHttpServer()
|
||||
|
||||
srv.SetNotFoundHandler(http.NotFound)
|
||||
@ -109,8 +97,7 @@ func main() {
|
||||
select {
|
||||
case <-logReopenSignal:
|
||||
logErr.Reopen(config.Log.Error)
|
||||
logUpload.Reopen(config.Log.Upload)
|
||||
logDownload.Reopen(config.Log.Download)
|
||||
logFile.Reopen(config.Log.File)
|
||||
case <-uploadDirNotify:
|
||||
uploadDirSize, err = utils.DirectorySize(config.Uploads.Directory)
|
||||
if err != nil {
|
||||
|
@ -9,9 +9,7 @@ hash_salt: "iyP3oZWHI3xO3XBF7s78Vg"
|
||||
log:
|
||||
# dwelling-upload logs.
|
||||
error: "/var/log/dwelling-upload/error.log"
|
||||
upload: "/var/log/dwelling-upload/upload.log"
|
||||
download: "/var/log/dwelling-upload/download.log"
|
||||
delete: "/var/log/dwelling-upload/delete.log"
|
||||
file: "/var/log/dwelling-upload/file.log"
|
||||
# dwelling-upload-clean logs.
|
||||
clean: "/var/log/dwelling-upload/clean.log"
|
||||
clean_error: "/var/log/dwelling-upload/clean_error.log"
|
||||
|
@ -15,9 +15,7 @@ type Configuration struct {
|
||||
User string `yaml:"user"`
|
||||
Log struct {
|
||||
Error string `yaml:"error"`
|
||||
Upload string `yaml:"upload"`
|
||||
Download string `yaml:"download"`
|
||||
Delete string `yaml:"delete"`
|
||||
File string `yaml:"file"`
|
||||
Clean string `yaml:"clean"`
|
||||
CleanError string `yaml:"clean_error"`
|
||||
} `yaml:"log"`
|
||||
|
@ -21,20 +21,16 @@ import (
|
||||
type UploadHandlers struct {
|
||||
conf *configuration.Configuration
|
||||
logErr *logging.Logger
|
||||
logUpload *logging.Logger
|
||||
logDownload *logging.Logger
|
||||
logDelete *logging.Logger
|
||||
logFile *logging.Logger
|
||||
|
||||
uploadDirSize *int64
|
||||
}
|
||||
|
||||
func NewUploadHandlers(conf *configuration.Configuration, lErr, lUp, lDown, lDel *logging.Logger, uploadDirSize *int64) *UploadHandlers {
|
||||
func NewUploadHandlers(conf *configuration.Configuration, lErr, lFile *logging.Logger, uploadDirSize *int64) *UploadHandlers {
|
||||
return &UploadHandlers{
|
||||
conf: conf,
|
||||
logErr: lErr,
|
||||
logUpload: lUp,
|
||||
logDownload: lDown,
|
||||
logDelete: lDel,
|
||||
logFile: lFile,
|
||||
uploadDirSize: uploadDirSize}
|
||||
}
|
||||
|
||||
@ -128,7 +124,7 @@ func (h *UploadHandlers) Upload(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
typ, _ := utils.NetworkType(r.Host)
|
||||
|
||||
h.logUpload.Printf("| %s | %s | %s | SHA256 %s | %s | %d | %s", r.Header.Get("X-Real-IP"), typ,
|
||||
h.logFile.Printf("up | %s | %s | %s | SHA256 %s | %s | %d | %s", r.Header.Get("X-Real-IP"), typ,
|
||||
fHandler.Filename, fHash, fSaltedHash, fHandler.Size, r.UserAgent())
|
||||
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
@ -176,7 +172,7 @@ func (h *UploadHandlers) Download(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
netTyp, _ := utils.NetworkType(r.Host)
|
||||
|
||||
h.logDownload.Printf("| %s | %s | %s | %s | %s", r.Header.Get("X-Real-IP"), netTyp, name, saltedHash, r.UserAgent())
|
||||
h.logFile.Printf("dw | %s | %s | %s | %s | %s", r.Header.Get("X-Real-IP"), netTyp, name, saltedHash, r.UserAgent())
|
||||
|
||||
http.ServeContent(w, r, path, stat.ModTime(), fd)
|
||||
}
|
||||
@ -207,7 +203,7 @@ func (h *UploadHandlers) Delete(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
netTyp, _ := utils.NetworkType(r.Host)
|
||||
|
||||
h.logDelete.Printf("| %s | %s | %s | %s", r.Header.Get("X-Real-IP"), netTyp, saltedHash, r.UserAgent())
|
||||
h.logFile.Printf("dt | %s | %s | %s | %s", r.Header.Get("X-Real-IP"), netTyp, saltedHash, r.UserAgent())
|
||||
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
web.Deleted(utils.MainSite(r.Host))
|
||||
|
Loading…
Reference in New Issue
Block a user