52 lines
		
	
	
	
		
			924 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			52 lines
		
	
	
	
		
			924 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package config
 | 
						|
 | 
						|
import (
 | 
						|
	"fmt"
 | 
						|
	"os"
 | 
						|
	fp "path/filepath"
 | 
						|
 | 
						|
	"github.com/BurntSushi/toml"
 | 
						|
)
 | 
						|
 | 
						|
const ConfigStr = `# Configuration for my-log
 | 
						|
 | 
						|
[input]
 | 
						|
# Path to where the log files are stored
 | 
						|
path = "%s"
 | 
						|
# File extension for log files
 | 
						|
ext = "txt"
 | 
						|
# Whether to look in sub-folders
 | 
						|
recurse = true
 | 
						|
# Whether to use a dot as a folder separator in log names
 | 
						|
dotFolder = true
 | 
						|
 | 
						|
# config for output types
 | 
						|
[output]
 | 
						|
 | 
						|
# This one just prints the logs to stdout when run
 | 
						|
[output.stdout]
 | 
						|
enabled = true
 | 
						|
[output.stdout.config]
 | 
						|
# Formatter to use when outputting to stdout
 | 
						|
formatter = "plain"
 | 
						|
 | 
						|
[formatters]
 | 
						|
 | 
						|
[formatters.json]
 | 
						|
# Set to true to pretty print JSON output
 | 
						|
pretty_print = false
 | 
						|
 | 
						|
`
 | 
						|
 | 
						|
func DefaultStr() string {
 | 
						|
	home, _ := os.UserHomeDir()
 | 
						|
	inDir := fp.Join(home, "my-log")
 | 
						|
	return fmt.Sprintf(ConfigStr, inDir)
 | 
						|
}
 | 
						|
 | 
						|
func DefaultConfig() (Config, error) {
 | 
						|
	s := DefaultStr()
 | 
						|
	c := Config{}
 | 
						|
	_, err := toml.Decode(s, &c)
 | 
						|
	return c, err
 | 
						|
}
 |