示例#1
0
文件: main.go 项目: djui/necd
func init() {
	logger := log.Logger()
	if terminal.IsTerminal(int(os.Stdout.Fd())) {
		logger.Appender().SetLayout(layout.Pattern("%p: %m"))
	} else {
		logger.Appender().SetLayout(layout.Pattern("%d %p: %m"))
	}
	logger.SetLevel(levels.DEBUG)
}
示例#2
0
func configure() {
	loglevel := "INFO"
	flag.StringVar(&loglevel, "loglevel", "INFO", "Log level")

	cachedir := ".gopancache"
	flag.StringVar(&cachedir, "cachedir", ".gopancache", "GoPAN cache directory")

	index := "index"
	flag.StringVar(&index, "index", "index", "Name of the primary GoPAN index file")

	bind := ":7050"
	flag.StringVar(&bind, "bind", ":7050", "Interface to bind to")

	cpan := "cpan_index.gz"
	flag.StringVar(&cpan, "cpan", "cpan_index.gz", "Name of CPAN index to support readthrough")

	backpan := "backpan_index.gz"
	flag.StringVar(&backpan, "backpan", "backpan_index.gz", "Name of BackPAN index to support readthrough")

	remote := "http://localhost:7050"
	flag.StringVar(&remote, "remote", "http://localhost:7050", "Remote host and port to connect to")

	loglayout := "[%d] [%p] %m"
	flag.StringVar(&loglayout, "loglayout", loglayout, "Log layout (for github.com/ian-kent/go-log pattern layout)")

	indexes := make([]string, 0)
	flag.Var((*gopan.AppendSliceValue)(&indexes), "s-index", "Secondary indexes to load (can be provided multiple times)")

	testdeps := true
	flag.BoolVar(&testdeps, "test-deps", true, "Test dependencies on startup")

	flag.Parse()

	config = &Config{
		LogLevel:         loglevel,
		CacheDir:         cachedir,
		Index:            index,
		Bind:             bind,
		Indexes:          indexes,
		CanUpdate:        false,
		LatestRelease:    "0.0",
		CurrentRelease:   "0.0", // set in main.go so its in one place
		UpdateURL:        "",
		ImportAvailable:  false,
		CPANIndex:        cpan,
		HasCPANIndex:     false,
		CPANIndexDate:    "",
		BackPANIndex:     backpan,
		HasBackPANIndex:  false,
		BackPANIndexDate: "",
		BackPANStatus:    "Unavailable",
		CPANStatus:       "Unavailable",
		RemoteHost:       remote,
		TestDeps:         testdeps,
	}

	// log level and layout
	log.Logger().Appender().SetLayout(layout.Pattern(loglayout))
	log.Logger().SetLevel(log.Stol(loglevel))
}
func New(logFileName, prefix string, isDevMode bool) Logger {
	l := golog.Logger()

	if isDevMode {
		l.SetLevel(levels.DEBUG)
	} else {
		l.SetLevel(levels.INFO)
	}

	layoutToUse := layout.Pattern(getPrefixWithSpace(prefix) + "[%p] %m") //level/priority, message

	rollingFileAppender := appenders.RollingFile(logFileName, true)
	rollingFileAppender.MaxBackupIndex = 5
	rollingFileAppender.MaxFileSize = 20 * 1024 * 1024 // 20 MB
	rollingFileAppender.SetLayout(layoutToUse)

	consoleAppender := appenders.Console()
	consoleAppender.SetLayout(layoutToUse)
	l.SetAppender(
		Multiple( //appenders.Multiple( ONCE PULL REQUEST OF ABOVE IS IN
			layoutToUse,
			rollingFileAppender,
			consoleAppender,
		))

	return &logger{l}
}
示例#4
0
文件: main.go 项目: sogko/gotcha
func main() {
	// Create our Gotcha application
	var app = gotcha.Create(Asset)

	// Set the logger output pattern
	log.Logger().Appender().SetLayout(layout.Pattern("[%d] [%p] %m"))
	log.Logger().SetLevel(log.Stol("TRACE"))

	// Get the router
	r := app.Router

	// Create some routes
	r.Get("/", example)
	r.Post("/", examplepost)
	r.Get("/foo", example2)
	r.Get("/bar", example3)
	r.Get("/stream", streamed)
	r.Get("/err", err)

	// Serve static content (but really use a CDN)
	r.Get("/images/(?P<file>.*)", r.Static("assets/images/{{file}}"))
	r.Get("/css/(?P<file>.*)", r.Static("assets/css/{{file}}"))

	// Listen to some events
	app.On(events.BeforeHandler, func(session *http.Session, next func()) {
		n := 0
		c, ok := session.Request.Cookies["test"]
		if ok {
			n, _ = strconv.Atoi(c.Value)
		}
		session.Stash["test"] = n
		log.Printf("Got BeforeHandler event! n = %d", n)
		next()
	})
	app.On(events.AfterHandler, func(session *http.Session, next func()) {
		n := session.Stash["test"].(int) + 1
		session.Response.Cookies.Set(&nethttp.Cookie{
			Name:  "test",
			Value: strconv.Itoa(n),
		})
		log.Println("Got AfterHandler event!")
		next()
	})
	app.On(events.AfterResponse, func(session *http.Session, next func()) {
		log.Println("Got AfterResponse event!")
		next()
	})

	// Start our application
	app.Start()

	<-make(chan int)
}
func New(svcLogger service.Logger, prefix string, isDevMode bool) Logger {
	l := golog.Logger()

	if isDevMode {
		l.SetLevel(levels.DEBUG)
	} else {
		l.SetLevel(levels.INFO)
	}

	layoutToUse := layout.Pattern(getPrefixWithSpace(prefix) + "[%p] %m") //level/priority, message

	serviceAppender1 := newAppender(layoutToUse, svcLogger)
	l.SetAppender(serviceAppender1)

	return &logger{l}
}
示例#6
0
func getLogger() logger.Logger {
	logger := log.Logger()

	layoutToUse := layout.Pattern("%d [%p] %m") //date, level/priority, message

	rollingFileAppender := appenders.RollingFile("rolling-log.log", true)
	rollingFileAppender.MaxBackupIndex = 5
	rollingFileAppender.MaxFileSize = 20 * 1024 * 1024 // 20 MB
	rollingFileAppender.SetLayout(layoutToUse)

	consoleAppender := appenders.Console()
	consoleAppender.SetLayout(layoutToUse)
	logger.SetAppender(
		Multiple( //appenders.Multiple( ONCE PULL REQUEST OF ABOVE IS IN
			layoutToUse,
			rollingFileAppender,
			consoleAppender,
		))

	return logger
}
示例#7
0
func Configure() *Config {
	conf := DefaultConfig()

	cpan := make([]string, 0)
	flag.Var((*gopan.AppendSliceValue)(&cpan), "cpan", "A CPAN mirror (can be specified multiple times)")

	backpan := make([]string, 0)
	flag.Var((*gopan.AppendSliceValue)(&backpan), "backpan", "A BackPAN mirror (can be specified multiple times)")

	smart := make([]string, 0)
	flag.Var((*gopan.AppendSliceValue)(&smart), "smart", "A SmartPAN mirror (can be specified multiple times)")

	test := make([]string, 0)
	flag.Var((*gopan.AppendSliceValue)(&test), "test", "A module to install with testing (can be specified multiple times)")

	tests := false
	flag.BoolVar(&tests, "tests", false, "Enables all tests during installation phase")

	nocpan := false
	flag.BoolVar(&nocpan, "nocpan", false, "Disables the default CPAN source")

	nobackpan := false
	flag.BoolVar(&nobackpan, "nobackpan", false, "Disables the default BackCPAN source")

	cpanfile := "cpanfile"
	flag.StringVar(&cpanfile, "cpanfile", "cpanfile", "The cpanfile to install")

	numcpus := runtime.NumCPU()
	flag.IntVar(&numcpus, "cpus", numcpus, "The number of CPUs to use, defaults to "+strconv.Itoa(numcpus)+" for your environment")

	nodepdump := false
	flag.BoolVar(&nodepdump, "nodepdump", nodepdump, "Disables dumping resolved dependencies listing")

	noinstall := false
	flag.BoolVar(&noinstall, "noinstall", noinstall, "Disables installation phase")

	metacpan := false
	flag.BoolVar(&metacpan, "metacpan", metacpan, "Enable resolving source via MetaCPAN")

	loglevel := "INFO"
	flag.StringVar(&loglevel, "loglevel", loglevel, "Log output level (ERROR, INFO, WARN, DEBUG, TRACE)")

	loglayout := "[%d] [%p] %m"
	flag.StringVar(&loglayout, "loglayout", loglayout, "Log layout (for github.com/ian-kent/go-log pattern layout)")

	cachedir := "./.gopancache"
	flag.StringVar(&cachedir, "cachedir", cachedir, "Cache directory for CPAN modules")

	installdir := "./local"
	flag.StringVar(&installdir, "installdir", installdir, "Install directory for CPAN modules")

	flag.Parse()

	if nocpan || nobackpan {
		conf.Sources = DefaultSources(!nocpan, !nobackpan)
	}

	// parse cpan mirrors
	for _, url := range cpan {
		mirror := strings.TrimSuffix(url, "/")
		m := NewSource("CPAN", mirror+"/modules/02packages.details.txt.gz", mirror)
		conf.Sources = append(conf.Sources, m)
	}

	// parse backpan mirrors
	for _, url := range backpan {
		mirror := strings.TrimSuffix(url, "/")
		m := NewSource("BackPAN", mirror+"/backpan-index", mirror) // FIXME
		conf.Sources = append(conf.Sources, m)
	}

	// parse smartpan mirrors
	for _, url := range smart {
		mirror := strings.TrimSuffix(url, "/")
		m := NewSource("SmartPAN", mirror, mirror)
		conf.Sources = append(conf.Sources, m)
	}

	// resolve via metacpan
	conf.MetaCPAN = metacpan
	if metacpan {
		m := NewSource("MetaCPAN", "", "")
		conf.Sources = append(conf.Sources, m)
		c := NewMetaSource("cpan", "", "http://www.cpan.org", m.ModuleList)
		conf.MetaSources = append(conf.MetaSources, c)
		b := NewMetaSource("backpan", "", "http://backpan.perl.org", m.ModuleList)
		conf.MetaSources = append(conf.MetaSources, b)
	}

	sort.Sort(sortSources(conf.Sources))

	// parse notest
	for _, n := range test {
		conf.Test.Modules[n] = true
	}
	conf.Test.Global = tests

	// parse cpanfile
	conf.CPANFile = cpanfile

	// numcpus
	conf.CPUs = numcpus

	// nodepdeump
	conf.NoDepdump = nodepdump

	// noinstall
	conf.NoInstall = noinstall

	// install dir
	conf.InstallDir = installdir

	// cache dir
	conf.CacheDir = cachedir

	// log level and layout
	log.Logger().Appender().SetLayout(layout.Pattern(loglayout))
	log.Logger().SetLevel(log.Stol(loglevel))

	// create cache dir
	os.MkdirAll(conf.CacheDir, 0777)

	config = conf

	return conf
}