work in progress: logging
This commit is contained in:
		
							parent
							
								
									3455b409fb
								
							
						
					
					
						commit
						2141e41241
					
				
					 5 changed files with 31 additions and 4 deletions
				
			
		| 
						 | 
				
			
			@ -4,11 +4,13 @@ import (
 | 
			
		|||
	"sync"
 | 
			
		||||
 | 
			
		||||
	"git.sr.ht/~cco/go-scopes/lib"
 | 
			
		||||
	"git.sr.ht/~cco/go-scopes/logging"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type appContext struct {
 | 
			
		||||
	*context
 | 
			
		||||
	services  Services
 | 
			
		||||
	logger    *logging.Logger
 | 
			
		||||
	waitgroup *sync.WaitGroup
 | 
			
		||||
	doneCh    chan struct{}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										9
									
								
								lib/system/system.go
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								lib/system/system.go
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,9 @@
 | 
			
		|||
package system
 | 
			
		||||
 | 
			
		||||
import "git.sr.ht/~cco/go-scopes/lib"
 | 
			
		||||
 | 
			
		||||
func RemoveFile(ctx lib.Context, fpath string) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func RemoveFiles(ctx lib.Context, path, pattern string) {
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -2,4 +2,4 @@ package log
 | 
			
		|||
 | 
			
		||||
import "git.sr.ht/~cco/go-scopes/logging"
 | 
			
		||||
 | 
			
		||||
var Info = logging.Logger.Info
 | 
			
		||||
var Info = logging.GetLogger(nil).Info
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,17 +3,33 @@ package logging
 | 
			
		|||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
 | 
			
		||||
	"git.sr.ht/~cco/go-scopes/lib"
 | 
			
		||||
	"github.com/rs/zerolog"
 | 
			
		||||
	"github.com/rs/zerolog/log"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var Logger = log.Logger
 | 
			
		||||
type Logger = zerolog.Logger
 | 
			
		||||
 | 
			
		||||
var globalLogger Logger = log.Logger
 | 
			
		||||
 | 
			
		||||
type Config struct {
 | 
			
		||||
	Logfile string
 | 
			
		||||
	Level   zerolog.Level
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func Setup(cfg *Config, home string) {
 | 
			
		||||
func Setup(ctx lib.Context, cfg *Config, home string) {
 | 
			
		||||
	if cfg != nil {
 | 
			
		||||
		fmt.Println("logging:", home, cfg.Logfile)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func New(cfg *Config, home string) *Logger {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetLogger(ctx lib.Context) *zerolog.Logger {
 | 
			
		||||
	if ctx == nil {
 | 
			
		||||
		return &globalLogger
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -41,9 +41,9 @@ func SetUp(tbase *testing.T) *T {
 | 
			
		|||
 | 
			
		||||
func SetUpApp(tbase *testing.T, cfg lib.Config) *T {
 | 
			
		||||
	appCfg := cfg.(*app.Cfg)
 | 
			
		||||
	logging.Setup(appCfg.Logging, appCfg.Home)
 | 
			
		||||
	t := SetUp(tbase)
 | 
			
		||||
	t.Ctx = context.AppContext(cfg).WithState(t)
 | 
			
		||||
	logging.Setup(t.Ctx, appCfg.Logging, appCfg.Home)
 | 
			
		||||
	cfg.Starter()(t.Ctx)
 | 
			
		||||
	time.Sleep(100 * time.Millisecond)
 | 
			
		||||
	return t
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue