本文整理汇总了Golang中github.com/astaxie/beego/logs.BeeLogger类的典型用法代码示例。如果您正苦于以下问题:Golang BeeLogger类的具体用法?Golang BeeLogger怎么用?Golang BeeLogger使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BeeLogger类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetTagsListV2Handler
func GetTagsListV2Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
namespace := ctx.Params(":namespace")
repository := ctx.Params(":repository")
r := new(models.Repository)
if _, err := r.Get(namespace, repository); err != nil {
log.Error("[REGISTRY API V2] Failed to get repository %v/%v: %v", namespace, repository, err.Error())
result, _ := json.Marshal(map[string]string{"message": "Failed to get repository"})
return http.StatusBadRequest, result
}
data := map[string]interface{}{}
data["name"] = fmt.Sprintf("%s/%s", namespace, repository)
tagslist := r.GetTagslist()
if len(tagslist) <= 0 {
log.Error("[REGISTRY API V2] Repository %v/%v tags list is empty", namespace, repository)
result, _ := json.Marshal(map[string]string{"message": "Tags list is empty"})
return http.StatusNotFound, result
}
data["tags"] = tagslist
result, _ := json.Marshal(data)
return http.StatusOK, result
}
示例2: GetTagsListV2Handler
func GetTagsListV2Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
namespace := ctx.Params(":namespace")
repository := ctx.Params(":repository")
r := new(models.Repository)
if has, _, err := r.Has(namespace, repository); err != nil || has == false {
log.Error("[REGISTRY API V2] Repository not found: %v", repository)
result, _ := json.Marshal(map[string]string{"message": "Repository not found"})
return http.StatusNotFound, result
}
data := map[string]interface{}{}
tags := []string{}
data["name"] = fmt.Sprintf("%s/%s", namespace, repository)
for _, value := range r.Tags {
t := new(models.Tag)
if err := t.GetByKey(value); err != nil {
log.Error("[REGISTRY API V2] Tag not found: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Tag not found"})
return http.StatusNotFound, result
}
tags = append(tags, t.Name)
}
data["tags"] = tags
result, _ := json.Marshal(data)
return http.StatusOK, result
}
示例3: DiscoveryACIHandler
// TBD: discovery template should be updated to keep in line with ACI
func DiscoveryACIHandler(ctx *macaron.Context, log *logs.BeeLogger) {
img := ctx.Params(":imagename")
t, err := template.ParseFiles("conf/acifetchtemplate.html")
if err != nil {
log.Error("[ACI API] Discovery parse template file failed: %v", err.Error())
ctx.Resp.WriteHeader(http.StatusInternalServerError)
fmt.Fprintf(ctx.Resp, fmt.Sprintf("%v", err))
return
}
err = t.Execute(ctx.Resp, struct {
Name string
ServerName string
ListenMode string
}{
Name: img,
ServerName: setting.Domains,
ListenMode: setting.ListenMode,
})
if err != nil {
log.Error("[ACI API] Discovery respond failed: %v", err.Error())
fmt.Fprintf(ctx.Resp, fmt.Sprintf("%v", err))
}
}
示例4: HeadBlobsV2Handler
func HeadBlobsV2Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
digest := ctx.Params(":digest")
tarsum := strings.Split(digest, ":")[1]
ctx.Resp.Header().Set("Content-Type", "application/json; charset=utf-8")
i := new(models.Image)
if exists, err := i.Get(tarsum); err != nil {
log.Info("[REGISTRY API V2] Failed to get tarsum %v: %v", tarsum, err.Error())
result, _ := json.Marshal(map[string]string{"message": "Failed to get tarsum"})
return http.StatusBadRequest, result
} else if !exists {
log.Info("[REGISTRY API V2] Not found tarsum: %v", tarsum)
result, _ := json.Marshal(map[string]string{"message": "Not found tarsum"})
return http.StatusNotFound, result
}
ctx.Resp.Header().Set("Content-Type", "application/octet-stream")
ctx.Resp.Header().Set("Docker-Content-Digest", digest)
ctx.Resp.Header().Set("Content-Length", fmt.Sprint(i.Size))
result, _ := json.Marshal(map[string]string{})
return http.StatusOK, result
}
示例5: PutImageLayerv1Handler
func PutImageLayerv1Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
imageId := ctx.Params(":imageId")
basePath := setting.ImagePath
imagePath := fmt.Sprintf("%v/images/%v", basePath, imageId)
layerfile := fmt.Sprintf("%v/images/%v/layer", basePath, imageId)
if !utils.IsDirExist(imagePath) {
os.MkdirAll(imagePath, os.ModePerm)
}
if _, err := os.Stat(layerfile); err == nil {
os.Remove(layerfile)
}
data, _ := ioutil.ReadAll(ctx.Req.Request.Body)
if err := ioutil.WriteFile(layerfile, data, 0777); err != nil {
log.Error("[REGISTRY API V1] Put Image Layer File Error: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Put Image Layer File Error"})
return http.StatusBadRequest, result
}
i := new(models.Image)
if err := i.PutLayer(imageId, layerfile, true, int64(len(data))); err != nil {
log.Error("[REGISTRY API V1] Put Image Layer File Data Error: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Put Image Layer File Data Error"})
return http.StatusBadRequest, result
}
result, _ := json.Marshal(map[string]string{})
return http.StatusOK, result
}
示例6: GetImageJSONV1Handler
func GetImageJSONV1Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
var jsonInfo string
var payload string
var err error
imageId := ctx.Params(":imageId")
i := new(models.Image)
if jsonInfo, err = i.GetJSON(imageId); err != nil {
log.Error("[REGISTRY API V1] Search Image JSON Error: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Search Image JSON Error"})
return http.StatusNotFound, result
}
if payload, err = i.GetChecksumPayload(imageId); err != nil {
log.Error("[REGISTRY API V1] Search Image Checksum Error: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Search Image Checksum Error"})
return http.StatusNotFound, result
}
ctx.Resp.Header().Set("X-Docker-Checksum-Payload", fmt.Sprintf("sha256:%v", payload))
ctx.Resp.Header().Set("X-Docker-Size", fmt.Sprint(i.Size))
ctx.Resp.Header().Set("Content-Length", fmt.Sprint(len(jsonInfo)))
return http.StatusOK, []byte(jsonInfo)
}
示例7: GetManifestsV2Handler
func GetManifestsV2Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
namespace := ctx.Params(":namespace")
repository := ctx.Params(":repository")
tag := ctx.Params(":tag")
t := new(models.Tag)
if exists, err := t.Get(namespace, repository, tag); err != nil || !exists {
log.Error("[REGISTRY API V2] Not found manifest: %v", err)
result, _ := json.Marshal(map[string]string{"message": "Not found manifest"})
return http.StatusNotFound, result
}
digest, err := signature.DigestManifest([]byte(t.Manifest))
if err != nil {
log.Error("[REGISTRY API V2] Failed to get manifest digest: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Failed to get manifest digest"})
return http.StatusInternalServerError, result
}
contenttype := []string{"", "application/json; charset=utf-8", "application/vnd.docker.distribution.manifest.v2+json"}
ctx.Resp.Header().Set("Content-Type", contenttype[t.Schema])
ctx.Resp.Header().Set("Docker-Content-Digest", digest)
ctx.Resp.Header().Set("Content-Length", fmt.Sprint(len(t.Manifest)))
return http.StatusOK, []byte(t.Manifest)
}
示例8: InitiateUpload
func InitiateUpload(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
image := ctx.Params(":image")
if image == "" {
log.Error("[ACI API]Get image name failed")
result, _ := json.Marshal(map[string]string{"message": "Get image name failed"})
return http.StatusNotFound, result
}
uploadNum := strconv.Itoa(newUpload(image))
var prefix string
prefix = setting.ListenMode + "://" + setting.Domains + "/ac-push"
deets := initiateDetails{
ACIPushVersion: "0.0.1",
Multipart: false,
ManifestURL: prefix + "/manifest/" + uploadNum,
SignatureURL: prefix + "/signature/" + uploadNum,
ACIURL: prefix + "/aci/" + uploadNum,
CompletedURL: prefix + "/complete/" + uploadNum,
}
result, _ := json.Marshal(deets)
return http.StatusInternalServerError, result
}
示例9: GetFileInfo
func GetFileInfo(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
path := ctx.Req.Header.Get(headerPath)
log.Info("[OSS][getFileInfo] Path: %s", path)
result, err := metaDriver.GetFileMetaInfo(path, false)
if err != nil {
log.Error("[OSS][getFileInfo] get metainfo error, key: %s, error: %s", path, err)
return http.StatusInternalServerError, []byte(err.Error())
}
if len(result) == 0 {
log.Info("[OSS][getFileInfo] metainfo not exists, key: %s", path)
return http.StatusNotFound, []byte(err.Error())
}
resultMap := make(map[string]interface{})
resultMap["fragment-info"] = result
jsonResult, err := json.Marshal(resultMap)
if err != nil {
log.Error("json.Marshal error, key: %s, error: %s", path, err)
return http.StatusInternalServerError, []byte(err.Error())
}
log.Info("[getFileInfo] success, path: %s, result: %s", path, string(jsonResult))
return http.StatusOK, jsonResult
}
示例10: UploadFile
func UploadFile(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
metaInfo, _, err := uploadFileReadParam(&ctx.Req.Header)
if err != nil {
log.Error("[OSS][uploadFile] read param error: %v", err)
return http.StatusBadRequest, []byte(err.Error())
}
data, err := ctx.Req.Body().Bytes()
if err != nil {
log.Error("[OSS]read request body error: %s", err)
return http.StatusBadRequest, []byte(err.Error())
}
statusCode, err := ossupload(data, metaInfo)
if err != nil {
log.Error("[OSS][uploadFile] upload error: %v", err)
return statusCode, []byte(err.Error())
}
if err = metaDriver.StoreMetaInfoV1(metaInfo); err != nil {
log.Error("[OSS]store metaInfo error: %s", err)
return http.StatusInternalServerError, []byte(err.Error())
}
log.Info("[OSS][postFile] success. path: %s, fragmentIndex: %d, bytesRange: %d-%d, isLast: %v", metaInfo.Path, metaInfo.Value.Index, metaInfo.Value.Start, metaInfo.Value.End, metaInfo.Value.IsLast)
return http.StatusOK, nil
}
示例11: GetManifestsV2Handler
func GetManifestsV2Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
t := new(models.Tag)
namespace := ctx.Params(":namespace")
repository := ctx.Params(":repository")
if err := t.Get(namespace, repository, ctx.Params(":tag")); err != nil {
log.Error("[REGISTRY API V2] Manifest not found: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Manifest not found"})
return http.StatusNotFound, result
}
digest, err := utils.DigestManifest([]byte(t.Manifest))
if err != nil {
log.Error("[REGISTRY API V2] Get manifest digest failed: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Get manifest digest failed"})
return http.StatusBadRequest, result
}
ctx.Resp.Header().Set("Content-Type", "application/json; charset=utf-8")
ctx.Resp.Header().Set("Docker-Content-Digest", digest)
ctx.Resp.Header().Set("Content-Length", fmt.Sprint(len(t.Manifest)))
return http.StatusOK, []byte(t.Manifest)
}
示例12: PutRepositoryImagesV1Handler
func PutRepositoryImagesV1Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
namespace := ctx.Params(":namespace")
repository := ctx.Params(":repository")
r := new(models.Repository)
if err := r.PutImages(namespace, repository); err != nil {
log.Error("[REGISTRY API V1] Put images error: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Put V1 images error"})
return http.StatusBadRequest, result
}
if ctx.Req.Header.Get("X-Docker-Token") == "true" {
username, _, _ := utils.DecodeBasicAuth(ctx.Req.Header.Get("Authorization"))
token := fmt.Sprintf("Token signature=%v,repository=\"%v/%v\",access=%v",
utils.MD5(username),
namespace,
repository,
"write")
ctx.Resp.Header().Set("X-Docker-Token", token)
ctx.Resp.Header().Set("WWW-Authenticate", token)
}
result, _ := json.Marshal(map[string]string{})
return http.StatusNoContent, result
}
示例13: PutRepositoryV1Handler
func PutRepositoryV1Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
username, _, _ := utils.DecodeBasicAuth(ctx.Req.Header.Get("Authorization"))
namespace := ctx.Params(":namespace")
repository := ctx.Params(":repository")
body, err := ctx.Req.Body().String()
if err != nil {
log.Error("[REGISTRY API V1] Get request body error: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Put V1 repository failed,request body is empty"})
return http.StatusBadRequest, result
}
r := new(models.Repository)
if err := r.Put(namespace, repository, body, ctx.Req.Header.Get("User-Agent"), setting.APIVERSION_V1); err != nil {
log.Error("[REGISTRY API V1] Put repository error: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": err.Error()})
return http.StatusBadRequest, result
}
if ctx.Req.Header.Get("X-Docker-Token") == "true" {
token := fmt.Sprintf("Token signature=%v,repository=\"%v/%v\",access=%v",
utils.MD5(username),
namespace,
repository,
"write")
ctx.Resp.Header().Set("X-Docker-Token", token)
ctx.Resp.Header().Set("WWW-Authenticate", token)
}
result, _ := json.Marshal(map[string]string{})
return http.StatusOK, result
}
示例14: GetPubkeys
func GetPubkeys(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
var pubkey []byte
var err error
pubkeypath := setting.ImagePath + "/acpool/" + "pubkeys.gpg"
if pubkey, err = ioutil.ReadFile(pubkeypath); err != nil {
log.Error("[ACI API] Get pubkey file failed: %v", err.Error())
result, _ := json.Marshal(map[string]string{"message": "Get pubkey file failed"})
return http.StatusNotFound, result
}
return http.StatusOK, pubkey
}
示例15: newLogger
// 初始化日志模块
func newLogger(config LogConfig, isDaily bool) (*logs.BeeLogger, error) {
var logger *logs.BeeLogger
var configInner logConfigInner
if config.Filename == "" {
return logger, errors.New("文件名不能为空哈")
}
configInner.Filename = config.Filename
if config.Maxlines == 0 {
config.Maxlines = 1000000
}
configInner.Maxlines = config.Maxlines
configInner.Daily = isDaily
if config.Maxdays == 0 {
config.Maxdays = 7
}
configInner.Maxdays = config.Maxdays
logLevel := map[string]int{
"error": logs.LevelError,
"warn": logs.LevelWarning,
"info": logs.LevelInformational,
}
var logLevelInt int
if config.Level == "" {
logLevelInt = logs.LevelInformational
} else {
var ok bool
logLevelInt, ok = logLevel[config.Level]
if ok == false {
return logger, errors.New("日志等级设置不正确")
}
}
configInner.Level = logLevelInt
configInner.Rotate = true
// 普通日志
logger = logs.NewLogger(10000)
logConfigString, err := json.Marshal(&configInner)
if err != nil {
return logger, err
}
err = logger.SetLogger("file", string(logConfigString))
if err != nil {
return logger, err
}
return logger, nil
}