Beispiel #1
0
func ChangeLogEnv(kind int) {
	//开发环境
	if kind == 1 {
		logger, err := log.LoggerFromConfigAsFile("config/logconfig_debug.xml")
		if err != nil {
			log.Errorf("create log error,error is %s ", err.Error())
		}
		log.UseLogger(logger)

	} else if kind == 2 { //生产环境
		logger, err := log.LoggerFromConfigAsFile("config/logconfig_production.xml")
		if err != nil {
			log.Errorf("create log error,error is %s ", err.Error())
		}
		log.UseLogger(logger)

	} else {
		Error("can't recognize log environment")
	}

}
Beispiel #2
0
// setLogger initialises the logger with the desired verbosity level
func setLogger(verbose bool) {
	var logLevel string
	if verbose {
		logLevel = "debug"
	} else {
		logLevel = "info"
	}

	logConfig := `
<seelog>
    <outputs>
        <filter levels="%s">
            <console />
        </filter>
    </outputs>
</seelog>`

	logger, _ := log.LoggerFromConfigAsBytes([]byte(fmt.Sprintf(logConfig, logLevel)))
	log.UseLogger(logger)
}
Beispiel #3
0
//创建新的上下文
func newContext() *Context {
	ch := make(chan int8)
	mods := make([]module.Module, 0, 10)

	curS := make(map[string]interface{})
	masterInfo := make(map[string]interface{})
	serverInfo := make(map[string][]map[string]interface{})
	allOpts := make(map[string]map[string]interface{})
	defaultComponents := make(map[string]interface{})
	logger, err := seelog.LoggerFromConfigAsFile("./logConfig.xml")

	if err != nil {
		fmt.Fprintf(os.Stderr, "Error: Fail to create logger,error message:<%v>\n", err.Error())
		os.Exit(1)
	}
	if err := seelog.UseLogger(logger); err != nil {
		fmt.Fprintf(os.Stderr, "Error: Fail to use logger,error message:<%v>\n", err.Error())
		os.Exit(1)
	}
	return &Context{ch, "", mods, nil, curS, masterInfo, serverInfo, allOpts, defaultComponents, logger}
}
Beispiel #4
0
// Initializer Func
func Initializer(conf string) bool {

	err := parseConfigFile(conf)
	if nil != err {
		fmt.Println("%v\n", err)
		return false
	}
	runtime.GOMAXPROCS(runtime.NumCPU())

	//seelog 配置
	logger, err := seelog.LoggerFromConfigAsFile(appConfig.Logconf)
	if nil != err {
		fmt.Println("%v\n", err)
		return false
	}
	seelog.UseLogger(logger)

	//redis 链接
	redisPool = NewRedisPool(appConfig.Redis.Host, appConfig.Redis.Db)
	return true
}
Beispiel #5
0
func syncLogger() {
	fmt.Println("Sync test")

	testConfig := `
<seelog type="sync">
	<outputs>
		<filter levels="trace">
			<file path="log.log"/>
		</filter>
		<filter levels="debug">
			<console />
		</filter>
	</outputs>
</seelog>
`

	logger, _ := log.LoggerFromConfigAsBytes([]byte(testConfig))
	log.UseLogger(logger)

	doTest()
}
func syncLogger() {

	// LogConfig seelog的配置文件
	var LogConfig = `
<seelog minlevel="info">
    <outputs formatid="common">
        <rollingfile type="date" filename="` + cmdPath + `/../log/mkafka.log" datepattern="2006010215" maxrolls="30"/>
        <filter levels="critical">
            <file path="` + cmdPath + `/../log/mkafka.log.wf" formatid="critical"/>
        </filter>
    </outputs>
    <formats>
        <format id="colored"  format="%Time %EscM(46)%Level%EscM(49) %Msg%n%EscM(0)"/>
        <format id="common" format="%Date/%Time [%LEV] [%File:%Line] %Msg%n" />
        <format id="critical" format="%Date/%Time %File:%Line %Func %Msg%n" />
    </formats>
</seelog>
`

	logger, _ := log.LoggerFromConfigAsBytes([]byte(LogConfig))
	log.UseLogger(logger)
}
Beispiel #7
0
func asyncTimerLogger() {
	fmt.Println("Async timer test")

	testConfig := `
<seelog type="asynctimer" asyncinterval="5000000">
	<outputs>
		<filter levels="trace">
			<file path="log.log"/>
		</filter>
		<filter levels="debug">
			<console />
		</filter>
	</outputs>
</seelog>`

	logger, _ := log.LoggerFromConfigAsBytes([]byte(testConfig))
	log.UseLogger(logger)

	doTest()

	time.Sleep(1e9)
}
Beispiel #8
0
// UseLogger is a wrapper for Seelog's UseLogger function. It sets the newLogger as the current logger.
func UseLogger(newLogger seelog.LoggerInterface) {
	logger = newLogger
	seelog.UseLogger(logger)
}
func main() {
	logger := lager.NewLogger("http")

	var request CheckRequest
	err := json.NewDecoder(os.Stdin).Decode(&request)
	fatalIf("failed to read request", err)

	os.Setenv("AWS_ACCESS_KEY_ID", request.Source.AWSAccessKeyID)
	os.Setenv("AWS_SECRET_ACCESS_KEY", request.Source.AWSSecretAccessKey)

	// silence benign ecr-login errors/warnings
	seelog.UseLogger(seelog.Disabled)

	ecrUser, ecrPass, err := ecr.ECRHelper{
		ClientFactory: ecrapi.DefaultClientFactory{},
	}.Get(request.Source.Repository)
	if err == nil {
		request.Source.Username = ecrUser
		request.Source.Password = ecrPass
	}

	registryHost, repo := parseRepository(request.Source.Repository)

	if len(request.Source.RegistryMirror) > 0 {
		registryMirrorUrl, err := url.Parse(request.Source.RegistryMirror)
		fatalIf("failed to parse registry mirror URL", err)
		registryHost = registryMirrorUrl.Host
	}

	tag := request.Source.Tag
	if tag == "" {
		tag = "latest"
	}

	transport, registryURL := makeTransport(logger, request, registryHost, repo)

	client := &http.Client{
		Transport: retryRoundTripper(logger, transport),
	}

	ub, err := v2.NewURLBuilderFromString(registryURL, false)
	fatalIf("failed to construct registry URL builder", err)

	namedRef, err := reference.WithName(repo)
	fatalIf("failed to construct named reference", err)

	var response CheckResponse

	taggedRef, err := reference.WithTag(namedRef, tag)
	fatalIf("failed to construct tagged reference", err)

	latestManifestURL, err := ub.BuildManifestURL(taggedRef)
	fatalIf("failed to build latest manifest URL", err)

	latestDigest, foundLatest := fetchDigest(client, latestManifestURL)

	if request.Version.Digest != "" {
		digestRef, err := reference.WithDigest(namedRef, digest.Digest(request.Version.Digest))
		fatalIf("failed to build cursor manifest URL", err)

		cursorManifestURL, err := ub.BuildManifestURL(digestRef)
		fatalIf("failed to build manifest URL", err)

		cursorDigest, foundCursor := fetchDigest(client, cursorManifestURL)

		if foundCursor && cursorDigest != latestDigest {
			response = append(response, Version{cursorDigest})
		}
	}

	if foundLatest {
		response = append(response, Version{latestDigest})
	}

	json.NewEncoder(os.Stdout).Encode(response)
}