Example #1
0
func TestLog4Go1() {

	l4g.Error("..RRR.")
	l4g.Warn("...")
	log := l4g.NewLogger()
	defer log.Close()
	log.AddFilter("stdout", l4g.WARNING, l4g.NewConsoleLogWriter())
	log.Info("The time is now: %s", time.Now().Format("15:04:05 MST 2006/01/02"))
}
Example #2
0
func main() {
	SetLog()
	defer log.Close()

	var name = "skoo"
	log.Debug("log4go by %s", name)
	log.Info("log4go by %s", name)
	log.Warn("log4go by %s", name)
	log.Error("log4go by %s", name)
	log.Fatal("log4go by %s", name)
}
func main() {
	// Load the configuration (isn't this easy?)
	l4g.LoadConfiguration("example.xml")

	l4g.Finest("This will only go to those of you really cool UDP kids!  If you change enabled=true.")
	l4g.Info("About .....")
	l4g.Trace("About that time, eh chaps?")
	l4g.Trace("About that time, eh chaps?")
	l4g.Trace("About that time, eh chaps?")
	l4g.Debug("About that time, eh chaps?")
	l4g.Info("About that time, eh chaps?")
	l4g.Warn("About that time, eh chaps?")
	select {}
}
Example #4
0
func main() {
	SetLog()
	defer log.Close()

	var name = "skoo"

	for {
		log.Debug("log4go by %s", name)
		log.Info("log4go by %s", name)
		log.Warn("log4go by %s", name)
		log.Error("log4go by %s", name)
		log.Fatal("log4go by %s", name)

		time.Sleep(time.Second * 1)
	}
}
Example #5
0
func (server *Server) Serve() {
	for {
		// accept connection
		conn, err := server.listener.Accept()
		if err != nil {
			log.Warn("Error in accept() loop: %v", err)
			continue
		}

		// output this new connection
		log.Info("Got connection from %v on local socket %v", conn.RemoteAddr(), conn.LocalAddr())

		// start client
		connection.HandleConnection(server.daemon, conn)
	}
}
Example #6
0
func (this *Pixivspy) download(req *http.Request) ([]byte, error) {
	client := http.Client{Jar: this.cookie}

	err := errors.New("")
	resp := &http.Response{}
	retry := 0
	for retry < 5 {
		resp, err = client.Do(req)
		if err == nil {
			break
		}

		if resp != nil {
			resp.Body.Close()
		}

		retry++
	}

	if retry == 5 {
		return nil, err
	}

	defer resp.Body.Close()

	b := bytes.NewBuffer(nil)
	if resp.StatusCode == http.StatusOK {
		switch resp.Header.Get("Content-Encoding") {
		case "gzip":

			reader, err := gzip.NewReader(resp.Body)
			defer reader.Close()

			io.Copy(b, reader)
			return b.Bytes(), err

		default:
			io.Copy(b, resp.Body)
			return b.Bytes(), nil
		}
	} else {
		log4go.Warn("访问%s失败, 错误码: %s", req.URL.String(), resp.Status)
	}

	return nil, err
}
Example #7
0
func (this *Pixivspy) parseMemberIllusts(memberID string) []*pixivIllust {
	works := []*pixivIllust{}
	pageNum := 1

	for {
		page, ok := this.downloadMemberPage(memberID, pageNum)

		if ok {
			log4go.Debug("正在解析[%s]P主作品第[%d]页", memberID, pageNum)

			query, err := goquery.ParseString(string(page))
			if err != nil {
				log4go.Debug("解析[%s]P主作品第[%d]页失败", memberID, pageNum)
				return works
			}

			workItem := query.Find(".work")
			if workItem.Length() == 0 {
				log4go.Info("已经访问到最后一页")
				return works
			}
			illustNameItem := query.Find("a h1.title")

			for i := 0; i < workItem.Length(); i++ {
				href := workItem.Eq(i).Attr("href")
				class := workItem.Eq(i).Attr("class")
				id := href[strings.Index(href, "illust_id=")+len("illust_id="):]

				works = append(works,
					&pixivIllust{
						href:  href,
						class: class,
						id:    id,
						title: illustNameItem.Eq(i).Text(),
					})
			}
			pageNum++
		} else {
			log4go.Warn("访问[%s]P主主页失败", memberID)
			return works
		}
	}

	return works
}
Example #8
0
func (this *Pixivspy) DownloadMemberIllusts(memberID string) {

	// 获取P主名称
	MemberName := this.parseMemberNameFromMemberID(memberID)
	log4go.Info("获取P主的昵称: %s", MemberName)

	// 获取P主图片集
	illusts := this.parseMemberIllusts(memberID)
	if illusts == nil {
		return
	}

	log4go.Info("准备解析[%s]P主的图片集", memberID)

	ch := make(chan *pixivImage, 8)
	go func() {
		defer close(ch)
		// 匹配图片集并获取图片地址
		for _, v := range illusts {
			page, ok := this.parseIllustPage(v)

			if ok {
				query, err := goquery.ParseString(page)
				if err != nil {
					log4go.Warn("解析[%s]图片集失败", v.title)
					return
				}

				downloadPath := util.FixPathName(config.Info.DownloadPath + "/" + MemberName + "/" + v.title)

				log4go.Info("检查图片集目录: %s", downloadPath)
				if !util.CheckFileIsExist(downloadPath) {
					log4go.Info("创建图片集目录: %s", downloadPath)
					os.MkdirAll(downloadPath, 0777)
				}

				imageItem := query.Find(".original-image")
				for i := 0; i < imageItem.Length(); i++ {
					url := imageItem.Eq(i).Attr("data-src")
					title := imageItem.Eq(i).Attr("alt")
					width := imageItem.Eq(i).Attr("width")
					height := imageItem.Eq(i).Attr("height")
					ch <- &pixivImage{url: url,
						title:        title,
						width:        width,
						height:       height,
						downloadPath: downloadPath,
						href:         config.Info.HostPageUrl.Url + v.href}
				}
			}
		}
	}()

	for v := range ch {
		pictureName := v.width + "_" + v.height + "_" + v.url[strings.LastIndex(v.url, "/")+1:]
		downloadName := util.FixPathName(v.downloadPath + "/" + pictureName)

		this.waitDownloader.Add(1)
		atomic.AddInt32(&this.maxTaskNum, 1)

		log4go.Info("当前任务数:%d, 正在获取空闲任务下载图片[%s]", atomic.LoadInt32(&this.maxTaskNum), downloadName)

		for atomic.LoadInt32(&this.maxTaskNum) >= config.Info.MaxTaskNum {
			time.Sleep(time.Second)
		}

		go func() {
			defer this.waitDownloader.Done()
			defer atomic.AddInt32(&this.maxTaskNum, -1)

			if util.CheckFileIsExist(downloadName) {
				log4go.Info("图片[%s]已存在, 跳过本次下载", downloadName)
				return
			}

			log4go.Info("正在下载图片[%s]", pictureName)

			req, _ := http.NewRequest("GET", v.url, nil)
			this.setImageHeader(req, v.href)
			image, err := this.download(req)
			if err != nil {
				log4go.Warn("图片[%s]下载失败", pictureName)
			} else {
				ioutil.WriteFile(downloadName, image, 0777)
			}
		}()
	}
}