• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang golog.LoggerFor函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/getlantern/golog.LoggerFor函数的典型用法代码示例。如果您正苦于以下问题:Golang LoggerFor函数的具体用法?Golang LoggerFor怎么用?Golang LoggerFor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了LoggerFor函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestLoggly

func TestLoggly(t *testing.T) {
	var buf bytes.Buffer
	var result map[string]interface{}
	loggly := loggly.New("token not required")
	loggly.Writer = &buf
	lw := logglyErrorWriter{client: loggly}
	golog.SetOutputs(lw, nil)
	log := golog.LoggerFor("test")

	log.Error("")
	if assert.NoError(t, json.Unmarshal(buf.Bytes(), &result), "Unmarshal error") {
		assert.Equal(t, "ERROR test", result["locationInfo"])
		assert.Regexp(t, regexp.MustCompile("logging_test.go:([0-9]+)"), result["message"])
	}

	buf.Reset()
	log.Error("short message")
	if assert.NoError(t, json.Unmarshal(buf.Bytes(), &result), "Unmarshal error") {
		assert.Equal(t, "ERROR test", result["locationInfo"])
		assert.Regexp(t, regexp.MustCompile("logging_test.go:([0-9]+) short message"), result["message"])
	}

	buf.Reset()
	log.Error("message with: reason")
	if assert.NoError(t, json.Unmarshal(buf.Bytes(), &result), "Unmarshal error") {
		assert.Equal(t, "ERROR test", result["locationInfo"])
		assert.Regexp(t, "logging_test.go:([0-9]+) message with: reason", result["message"])
	}

	buf.Reset()
	log.Error("deep reason: message with: reason")
	if assert.NoError(t, json.Unmarshal(buf.Bytes(), &result), "Unmarshal error") {
		assert.Equal(t, "ERROR test", result["locationInfo"])
		assert.Equal(t, "message with: reason", result["message"], "message should be last 2 chunks")
	}

	buf.Reset()
	log.Error("deep reason: an url https://a.com in message: reason")
	if assert.NoError(t, json.Unmarshal(buf.Bytes(), &result), "Unmarshal error") {
		assert.Equal(t, "an url https://a.com in message: reason", result["message"], "should not truncate url")
	}

	buf.Reset()
	log.Error("deep reason: an url 127.0.0.1:8787 in message: reason")
	if assert.NoError(t, json.Unmarshal(buf.Bytes(), &result), "Unmarshal error") {
		assert.Equal(t, "ERROR test", result["locationInfo"])
		assert.Equal(t, "an url 127.0.0.1:8787 in message: reason", result["message"], "should not truncate url")
	}

	buf.Reset()
	longPrefix := "message with: really l"
	longMsg := longPrefix + strings.Repeat("o", 100) + "ng reason"
	log.Error(longMsg)
	if assert.NoError(t, json.Unmarshal(buf.Bytes(), &result), "Unmarshal error") {
		assert.Equal(t, "ERROR test", result["locationInfo"])

		assert.Regexp(t, regexp.MustCompile("logging_test.go:([0-9]+) "+longPrefix+"(o+)"), result["message"])
		assert.Equal(t, 100, len(result["message"].(string)))
	}
}
开发者ID:journeyqiao,项目名称:http-proxy,代码行数:60,代码来源:logging_test.go


示例2: sendTestRequest

func sendTestRequest(client *http.Client, addr string) error {
	log := golog.LoggerFor("protected")

	req, err := http.NewRequest("GET", "http://"+addr+"/", nil)
	if err != nil {
		return fmt.Errorf("Error constructing new HTTP request: %s", err)
	}
	req.Header.Add("Connection", "keep-alive")
	resp, err := client.Do(req)
	if err != nil {
		return fmt.Errorf("Could not make request to %s: %s", addr, err)
	}
	_, err = ioutil.ReadAll(resp.Body)
	if err != nil {
		return fmt.Errorf("Error reading response body: %s", err)
	}
	resp.Body.Close()
	log.Debugf("Successfully processed request to %s", addr)
	return nil
}
开发者ID:2722,项目名称:lantern,代码行数:20,代码来源:protected_test.go


示例3: GetLocation

	"github.com/getlantern/golog"

	"github.com/getlantern/flashlight/pubsub"
	"github.com/getlantern/flashlight/ui"
)

const (
	messageType = `GeoLookup`

	basePublishSeconds     = 30
	publishSecondsVariance = basePublishSeconds - 10
	retryWaitMillis        = 100
)

var (
	log = golog.LoggerFor("flashlight.geolookup")

	service  *ui.Service
	client   atomic.Value
	cfgMutex sync.Mutex
	location atomic.Value
)

func GetLocation() *geolookup.City {
	l := location.Load()
	if l == nil {
		return nil
	}
	return l.(*geolookup.City)
}
开发者ID:shizhh,项目名称:lantern,代码行数:30,代码来源:geolookup.go


示例4:

	"github.com/getlantern/flashlight/client"
	"github.com/getlantern/flashlight/globals"
	"github.com/getlantern/flashlight/server"
	"github.com/getlantern/flashlight/statreporter"
)

const (
	CloudConfigPollInterval = 1 * time.Minute
	cloudflare              = "cloudflare"
	etag                    = "X-Lantern-Etag"
	ifNoneMatch             = "X-Lantern-If-None-Match"
)

var (
	log                 = golog.LoggerFor("flashlight.config")
	m                   *yamlconf.Manager
	lastCloudConfigETag = map[string]string{}
	httpClient          atomic.Value
)

type Config struct {
	Version       int
	CloudConfig   string
	CloudConfigCA string
	Addr          string
	Role          string
	InstanceId    string
	CpuProfile    string
	MemProfile    string
	UIAddr        string // UI HTTP server address
开发者ID:shizhh,项目名称:lantern,代码行数:30,代码来源:config.go


示例5: main

import (
	"os"
	"runtime"
	"sync"

	"github.com/getlantern/aws-sdk-go/gen/cloudfront"
	"github.com/getlantern/golog"
	"github.com/getlantern/peerscanner/cfr"
)

const (
	COMMENT = "TEST -- DELETE"
)

var (
	log = golog.LoggerFor("cfrjanitor")
)

func main() {
	numProcs := runtime.NumCPU() * 2
	runtime.GOMAXPROCS(numProcs)
	numWorkers := numProcs * 4
	c := getCfr()
	workCh := make(chan *cfr.Distribution)
	wg := sync.WaitGroup{}
	wg.Add(numWorkers)
	log.Debugf("Spawning %v workers", numWorkers)
	for i := 0; i < numWorkers; i++ {
		go work(c, workCh, &wg)
	}
	dists, err := cfr.ListDistributions(c)
开发者ID:2722,项目名称:lantern,代码行数:31,代码来源:cfrjanitor.go


示例6:

	"sync"
	"time"

	"github.com/getlantern/connpool"
	"github.com/getlantern/enproxy"
	"github.com/getlantern/golog"
	"github.com/getlantern/proxy"
	"github.com/getlantern/tlsdialer"
)

const (
	CONNECT = "CONNECT" // HTTP CONNECT method
)

var (
	log = golog.LoggerFor("fronted")

	// Cutoff for logging warnings about a dial having taken a long time.
	longDialLimit = 10 * time.Second

	// idleTimeout needs to be small enough that we stop using connections
	// before the upstream server/CDN closes them itself.
	// TODO: make this configurable.
	idleTimeout = 10 * time.Second
)

// Dialer is a domain-fronted proxy.Dialer.
type Dialer interface {
	proxy.Dialer

	// HttpClientUsing creates a simple domain-fronted HTTP client using the
开发者ID:shizhh,项目名称:lantern,代码行数:31,代码来源:dialer.go


示例7:

var (
	help                = flag.Bool("help", false, "Get usage help")
	masqueradesInFile   = flag.String("masquerades", "", "Path to file containing list of pasquerades to use, with one space-separated 'ip domain' pair per line (e.g. masquerades.txt)")
	masqueradesOutFile  = flag.String("masquerades-out", "", "Path, if any, to write the go-formatted masquerades configuration.")
	blacklistFile       = flag.String("blacklist", "", "Path to file containing list of blacklisted domains, which will be excluded from the configuration even if present in the masquerades file (e.g. blacklist.txt)")
	proxiedSitesDir     = flag.String("proxiedsites", "proxiedsites", "Path to directory containing proxied site lists, which will be combined and proxied by Lantern")
	proxiedSitesOutFile = flag.String("proxiedsites-out", "", "Path, if any, to write the go-formatted proxied sites configuration.")
	minFreq             = flag.Float64("minfreq", 3.0, "Minimum frequency (percentage) for including CA cert in list of trusted certs, defaults to 3.0%")

	fallbacksFile    = flag.String("fallbacks", "fallbacks.yaml", "File containing yaml dict of fallback information")
	fallbacksOutFile = flag.String("fallbacks-out", "", "Path, if any, to write the go-formatted fallback configuration.")
)

var (
	log = golog.LoggerFor("genconfig")

	masquerades []string

	blacklist    = make(filter)
	proxiedSites = make(filter)
	fallbacks    map[string]*client.ChainedServerInfo
	ftVersion    string

	inputCh       = make(chan string)
	masqueradesCh = make(chan *masquerade)
	wg            sync.WaitGroup
)

type filter map[string]bool
开发者ID:Christeefym,项目名称:lantern,代码行数:29,代码来源:genconfig.go


示例8: New

	"net/http"
	"net/http/httputil"
	"strconv"
	"time"

	"github.com/getlantern/errors"
	"github.com/getlantern/golog"
	"github.com/getlantern/idletiming"
	"github.com/getlantern/ops"
	"github.com/getlantern/proxy"

	"github.com/getlantern/http-proxy/buffers"
	"github.com/getlantern/http-proxy/filters"
)

var log = golog.LoggerFor("httpconnect")

type Options struct {
	IdleTimeout  time.Duration
	AllowedPorts []int
	Dialer       func(network, address string) (net.Conn, error)
}

type httpConnectHandler struct {
	*Options
	intercept proxy.Interceptor
}

func New(opts *Options) filters.Filter {
	if opts.Dialer == nil {
		opts.Dialer = func(network, address string) (net.Conn, error) {
开发者ID:getlantern,项目名称:http-proxy,代码行数:31,代码来源:httpconnect.go


示例9: New

	r Reporter
}

// Measured is the controller to report statistics
type Measured struct {
	reporters     []Reporter
	maxBufferSize int
	chTraffic     chan *Traffic
	traffic       map[string]*TrafficTracker
	chStop        chan struct{}
	stopped       int32
	mutex         sync.Mutex
}

var (
	log = golog.LoggerFor("measured")
)

// DialFunc is the type of function measured can wrap
type DialFunc func(net, addr string) (net.Conn, error)

// New creates a new Measured instance
func New(maxBufferSize int) *Measured {
	return &Measured{
		maxBufferSize: maxBufferSize,
		chTraffic:     make(chan *Traffic, maxBufferSize),
		traffic:       make(map[string]*TrafficTracker, maxBufferSize),
		chStop:        make(chan struct{}),
		stopped:       1,
	}
}
开发者ID:getlantern,项目名称:measured,代码行数:31,代码来源:measured.go


示例10: Configure

	"sync"

	"github.com/getlantern/detour"
	"github.com/getlantern/golog"
	"github.com/getlantern/proxiedsites"

	"github.com/getlantern/flashlight/config"
	"github.com/getlantern/flashlight/ui"
)

const (
	messageType = `ProxiedSites`
)

var (
	log = golog.LoggerFor("flashlight.proxiedsites")

	service    *ui.Service
	PACURL     string
	startMutex sync.Mutex
)

func Configure(cfg *proxiedsites.Config) {
	delta := proxiedsites.Configure(cfg)
	startMutex.Lock()

	if delta != nil {
		updateDetour(delta)
	}
	if service == nil {
		// Initializing service.
开发者ID:Christeefym,项目名称:lantern,代码行数:31,代码来源:proxiedsites.go


示例11:

	"github.com/getlantern/go-igdman/igdman"
	"github.com/getlantern/golog"
	"github.com/getlantern/yaml"
	"github.com/hashicorp/golang-lru"

	"github.com/getlantern/flashlight/globals"
	"github.com/getlantern/flashlight/statreporter"
	"github.com/getlantern/flashlight/statserver"
)

const (
	PortmapFailure = 50
)

var (
	log               = golog.LoggerFor("flashlight.server")
	registerPeriod    = 5 * time.Minute
	frontingProviders = map[string]func(*http.Request) bool{
		// WARNING: If you add a provider here, keep in mind that Go's http
		// library normalizes all header names so the first letter of every
		// dash-separated "word" is uppercase while all others are lowercase.
		// Also, try and check more than one header to lean on the safe side.
		"cloudflare": func(req *http.Request) bool {
			return hasHeader(req, "Cf-Connecting-Ip") || hasHeader(req, "Cf-Ipcountry") || hasHeader(req, "Cf-Ray") || hasHeader(req, "Cf-Visitor")
		},
		"cloudfront": func(req *http.Request) bool {
			return hasHeader(req, "X-Amz-Cf-Id") || headerMatches(req, "User-Agent", "Amazon Cloudfront")
		},
	}
)
开发者ID:shizhh,项目名称:lantern,代码行数:30,代码来源:server.go


示例12:

	"github.com/getlantern/flashlight/client"
	"github.com/getlantern/golog"

	socks "github.com/getlantern/lantern-mobile/lantern/socks"
)

// Errors introduced by the interceptor service
var (
	defaultClient Interceptor
	dialTimeout   = 20 * time.Second
	// threshold of errors that we are withstanding
	maxErrCount = 15

	statsInterval = 15 * time.Second
	log           = golog.LoggerFor("lantern-android.interceptor")

	ErrTooManyFailures = errors.New("Too many connection failures")
	ErrNoSocksProxy    = errors.New("Unable to start local SOCKS proxy")
	ErrDialTimeout     = errors.New("Error dialing tunnel: timeout")
)

type DialFunc func(network, addr string) (net.Conn, error)

// Interceptor is responsible for intercepting
// traffic on the VPN interface.
type Interceptor struct {
	client *client.Client

	clientGone bool
开发者ID:Christeefym,项目名称:lantern,代码行数:29,代码来源:interceptor.go


示例13: NewLimitedListener

package listeners

import (
	"errors"
	"math"
	"net"
	"net/http"
	"sync/atomic"
	"time"

	"github.com/getlantern/golog"
)

var (
	log = golog.LoggerFor("listeners")
)

type limitedListener struct {
	net.Listener

	maxConns    uint64
	numConns    uint64
	idleTimeout time.Duration

	stopped int32
	stop    chan bool
	restart chan bool
}

func NewLimitedListener(l net.Listener, maxConns uint64) net.Listener {
	if maxConns <= 0 {
开发者ID:getlantern,项目名称:http-proxy,代码行数:31,代码来源:limited.go


示例14:

	"net/url"
	"runtime"
	"strconv"

	"github.com/getlantern/flashlight/util"
	"github.com/getlantern/golog"
)

const (
	ApiEndpoint       = `https://ssl.google-analytics.com/collect`
	ProtocolVersion   = "1"
	DefaultInstanceId = "555"
)

var (
	log        = golog.LoggerFor("analytics")
	httpClient *http.Client
	ip         string
)

type HitType string

const (
	PageViewType HitType = "pageview"
	EventType    HitType = "event"
)

type PageView struct {
	Hostname string `param:"dh"`
	Pagename string `param:"dp"`
	Title    string `param:"dt"`
开发者ID:kidaa,项目名称:lantern,代码行数:31,代码来源:analytics.go


示例15: New

// clients can make requests to specific domains.
package ratelimiter

import (
	"fmt"
	"net"
	"net/http"
	"sync"
	"time"

	"github.com/getlantern/golog"
	"github.com/getlantern/http-proxy/filters"
	"github.com/hashicorp/golang-lru"
)

var log = golog.LoggerFor("ratelimiter")

type ratelimiter struct {
	hostPeriods          map[string]time.Duration
	hostAccessesByClient *lru.Cache
	mx                   sync.Mutex
}

// New creates a new rate limiting filter that only allows access to the hosts
// listed in the given hostPeriods, and limits the periodicity of requests to
// each host to the given duration. It limits the number of clients tracked to
// the the numClients with the most recent activity.
func New(numClients int, hostPeriods map[string]time.Duration) filters.Filter {
	if numClients <= 0 {
		numClients = 5000
	}
开发者ID:getlantern,项目名称:http-proxy,代码行数:31,代码来源:ratelimiter.go


示例16:

package yamlconf

import (
	"fmt"
	"os"
	"sync"
	"time"

	"github.com/getlantern/deepcopy"
	"github.com/getlantern/golog"
)

var (
	log = golog.LoggerFor("yamlconf")
)

// Config is the interface for configuration objects that provide the in-memory
// representation of yaml configuration managed by yamlconf.
type Config interface {
	GetVersion() int

	SetVersion(version int)

	ApplyDefaults()
}

// Manager exposes a facility for managing configuration a YAML configuration
// file. After creating a Manager, one must call the Init() method to start the
// necessary background processing.  If you set a CustomPoll function, you need
// to call StartPolling() also.
//
开发者ID:shizhh,项目名称:lantern,代码行数:31,代码来源:yamlconf.go


示例17:

	"time"

	"github.com/getlantern/golog"
)

const (
	// Addresses for Administratively Scoped IP Multicast are in the space 239/8
	multicastIP       = "232.77.77.77"
	multicastPort     = "9864"
	multicastAddress  = multicastIP + ":" + multicastPort
	defaultPeriod     = 9
	defaultFailedTime = 30 // Seconds until a peer is considered failed
)

var (
	log = golog.LoggerFor("multicast")
)

type eventCallback func(string, []PeerInfo)

// Multicast servent main structure
type Multicast struct {
	period             int    // multicast period (in secs, 10 by default)
	payload            string // Will be appended to the messages
	conn               *net.UDPConn
	addr               *net.UDPAddr
	failedTime         int           // timeout for peers' hello messages, 0 means no timeout
	addPeerCallback    eventCallback // Callback called when a peer is added (added, all)
	removePeerCallback eventCallback // Callback called when a peer is removed (removed, all)
	quit               chan bool
	helloTicker        *time.Ticker
开发者ID:Christeefym,项目名称:lantern,代码行数:31,代码来源:multicast.go


示例18: main

	"os"
	"time"

	"github.com/getlantern/golog"

	"github.com/getlantern/http-proxy/commonfilter"
	"github.com/getlantern/http-proxy/forward"
	"github.com/getlantern/http-proxy/httpconnect"
	"github.com/getlantern/http-proxy/listeners"
	"github.com/getlantern/http-proxy/logging"
	"github.com/getlantern/http-proxy/server"
)

var (
	testingLocal = false
	log          = golog.LoggerFor("http-proxy")

	help      = flag.Bool("help", false, "Get usage help")
	keyfile   = flag.String("key", "", "Private key file name")
	certfile  = flag.String("cert", "", "Certificate file name")
	https     = flag.Bool("https", false, "Use TLS for client to proxy communication")
	addr      = flag.String("addr", ":8080", "Address to listen")
	maxConns  = flag.Uint64("maxconns", 0, "Max number of simultaneous connections allowed connections")
	idleClose = flag.Uint64("idleclose", 30, "Time in seconds that an idle connection will be allowed before closing it")
)

func main() {
	var err error

	_ = flag.CommandLine.Parse(os.Args[1:])
	if *help {
开发者ID:journeyqiao,项目名称:http-proxy,代码行数:31,代码来源:http_proxy.go


示例19: bestPackageVersion

	"github.com/getlantern/flashlight/client"
	"github.com/getlantern/flashlight/config"
	"github.com/getlantern/flashlight/geolookup"
	"github.com/getlantern/flashlight/logging"
)

const (
	// While in development mode we probably would not want auto-updates to be
	// applied. Using a big number here prevents such auto-updates without
	// disabling the feature completely. The "make package-*" tool will take care
	// of bumping this version number so you don't have to do it by hand.
	DefaultPackageVersion = "9999.99.99"
)

var (
	log = golog.LoggerFor("flashlight")

	// compileTimePackageVersion is set at compile-time for production builds
	compileTimePackageVersion string

	PackageVersion = bestPackageVersion()

	Version      string
	RevisionDate string // The revision date and time that is associated with the version string.
	BuildDate    string // The actual date and time the binary was built.

	cfgMutex sync.Mutex
)

func bestPackageVersion() string {
	if compileTimePackageVersion != "" {
开发者ID:2722,项目名称:lantern,代码行数:31,代码来源:flashlight.go


示例20:

	"net/http"
	"os"
	"path"
	"path/filepath"
	"strings"
	"time"

	"github.com/getlantern/golog"
)

const (
	ExitLocalDirUnavailable = 1
)

var (
	log            = golog.LoggerFor("tarfs")
	fileTimestamp  = time.Now()
	emptyFileInfos = []os.FileInfo{}
)

// FileSystem is a tarfs filesystem. It exposes a Get method for accessing
// resources by path. It also implements http.FileSystem for use with
// http.FileServer.
type FileSystem struct {
	files map[string][]byte
	local string
}

// New creates a new FileSystem using the given in-memory tar data. If local is
// a non-empty string, the resulting FileSystem will first look for resources in
// the local file system before returning an embedded resource.
开发者ID:shizhh,项目名称:lantern,代码行数:31,代码来源:tarfs.go



注:本文中的github.com/getlantern/golog.LoggerFor函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang assert.Equal函数代码示例发布时间:2022-05-23
下一篇:
Golang fdcount.Matching函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap