本文整理汇总了Golang中gopkg/in/inconshreveable/log15/v2.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: sockHandler
func sockHandler(d *Daemon, w *websocket.Conn) {
r := w.Request()
raddr := r.RemoteAddr
if !d.isTrustedClient(r) {
d.log.Warn("untrusted client connected", log.Ctx{"raddr": raddr})
return
}
d.log.Debug("handing over client connection", log.Ctx{"raddr": raddr})
clog := log.New(log.Ctx{"module": "socks", "raddr": raddr})
handler := log.StdoutHandler
if quiet {
clog.SetHandler(log.DiscardHandler())
} else if verbose {
clog.SetHandler(log.LvlFilterHandler(log.LvlInfo, handler))
} else if debug {
clog.SetHandler(log.LvlFilterHandler(log.LvlDebug, handler))
} else {
clog.SetHandler(log.LvlFilterHandler(log.LvlError, handler))
}
client := &clientConnection{
websocket: w,
log: clog,
raddr: raddr,
}
go client.run()
}
开发者ID:jsimonetti,项目名称:tlstun,代码行数:30,代码来源:handler.go
示例2: NewPeer
// NewPeer returns a new peer, which can join a cluster
func NewPeer(config *PeerConfig) (*Peer, error) {
advertise := config.Bind
if len(config.Advertise) > 0 {
advertise = config.Advertise
}
logger := log.New("module", "peer", "bind", config.Bind)
peer := &Peer{
config: config,
logger: logger,
pingChMap: make(map[int64]chan *ackRequest),
indirectPingChMap: make(map[int64]chan *indirectPingResponse),
recentlyPinged: make(map[string]*RemotePeer),
store: newStore(advertise, logger),
}
// create udp server
udpServer := multiserver.NewUDPServer(config.Bind, peer.execUDP)
udpServer.UDPBufferSizeSet(config.UDPBufferSize)
peer.udpServer = udpServer
// create tcp server
tcpServer := multiserver.NewTCPServer(config.Bind, peer.handleTCPRequest, nil)
peer.tcpServer = tcpServer
// add callback if configured
peer.store.peerEventCallback = config.PeerEventCallback
return peer, nil
}
开发者ID:sisatech,项目名称:cluster,代码行数:32,代码来源:peer.go
示例3: NewConnPool
// NewConnPool creates a new ConnPool. config.ConnConfig is passed through to
// Connect directly.
func NewConnPool(config ConnPoolConfig) (p *ConnPool, err error) {
p = new(ConnPool)
p.config = config.ConnConfig
p.maxConnections = config.MaxConnections
if p.maxConnections == 0 {
p.maxConnections = 5
}
if p.maxConnections < 2 {
return nil, errors.New("MaxConnections must be at least 2")
}
p.afterConnect = config.AfterConnect
if config.Logger != nil {
p.logger = config.Logger
} else {
p.logger = log.New()
p.logger.SetHandler(log.DiscardHandler())
}
p.allConnections = make([]*Conn, 0, p.maxConnections)
p.availableConnections = make([]*Conn, 0, p.maxConnections)
p.cond = sync.NewCond(new(sync.Mutex))
// Initially establish one connection
var c *Conn
c, err = p.createConnection()
if err != nil {
return
}
p.allConnections = append(p.allConnections, c)
p.availableConnections = append(p.availableConnections, c)
return
}
开发者ID:rjammala,项目名称:pgx,代码行数:36,代码来源:conn_pool.go
示例4: NewBot
// NewBot creates a new instance of Bot
func NewBot(host, nick string, options ...func(*Bot)) (*Bot, error) {
// Defaults are set here
bot := Bot{
Incoming: make(chan *Message, 16),
outgoing: make(chan string, 16),
started: time.Now(),
unixastr: fmt.Sprintf("@%s-%s/bot", host, nick),
Host: host,
Nick: nick,
ThrottleDelay: 200 * time.Millisecond,
PingTimeout: 300 * time.Second,
HijackSession: false,
SSL: false,
SASL: false,
Channels: []string{"#test"},
Password: "",
}
for _, option := range options {
option(&bot)
}
// Discard logs by default
bot.Logger = log.New("id", logext.RandId(8), "host", bot.Host, "nick", log.Lazy{bot.getNick})
bot.Logger.SetHandler(log.DiscardHandler())
bot.AddTrigger(pingPong)
bot.AddTrigger(joinChannels)
return &bot, nil
}
开发者ID:flexd,项目名称:hellabot,代码行数:29,代码来源:hellabot.go
示例5: main
func main() {
flag.Parse()
if helpflag {
flag.Usage()
return
}
logger = log.New()
handler := log.StdoutHandler
if quietflag {
logger.SetHandler(log.DiscardHandler())
} else if verboseflag {
logger.SetHandler(log.LvlFilterHandler(log.LvlInfo, handler))
} else if debugflag {
logger.SetHandler(log.LvlFilterHandler(log.LvlDebug, handler))
} else {
logger.SetHandler(log.LvlFilterHandler(log.LvlError, handler))
}
ldifstore := &ldif.LdifBackend{
Path: "./ldif",
Log: logger.New(log.Ctx{"type": "backend", "backend": "ldif"}),
}
if err := ldifstore.Start(); err != nil {
logger.Error("error loading backend", log.Ctx{"error": err})
os.Exit(1)
}
//Create a new LDAP Server
server := ldap.NewServer(logger)
fallback := &debug.DebugBackend{
Log: logger.New(log.Ctx{"type": "backend", "backend": "debug"}),
}
//Create routes bindings
routes := newRouter(fallback, logger)
// backend specific routes
routes.Bind(ldifstore).BaseDn("dc=enterprise,dc=org").Label("Bind LDIF")
routes.Search(ldifstore).BaseDn("dc=enterprise,dc=org").Label("Search LDIF")
routes.Add(ldifstore).BaseDn("dc=enterprise,dc=org").Label("Add LDIF")
//Attach routes to server
server.Handle(routes)
// listen on 3389 and serve
go server.ListenAndServe(":6389")
// When CTRL+C, SIGINT and SIGTERM signal occurs
// Then stop server gracefully
ch := make(chan os.Signal)
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
<-ch
close(ch)
server.Stop()
}
开发者ID:jsimonetti,项目名称:ldapserv,代码行数:60,代码来源:main.go
示例6: main
func main() {
start := false
logDir := flag.String("log", "./logs", "path to log directory")
confPath := flag.String("config", "./config.json", "path to cofig file")
// docker := flag.Bool("docker", false, "for docker")
flag.Parse()
// Create log directory
if err := os.Mkdir(*logDir, 0777); err != nil && os.IsNotExist(err) {
log.Fatal(err)
}
// Write log in file:
// Change file every 24 hours
go func() {
Log = llog.New()
t := time.Now()
for {
// Day_Month_Year
name := fmt.Sprintf("%v.%v.%v", t.Month(), t.Day(), t.Year())
h, f, err := MyFileHandler(path.Join(*logDir, name), llog.LogfmtFormat())
if err != nil {
log.Println(err)
return
}
Log.SetHandler(llog.SyncHandler(h))
if !start {
start = true
}
t = <-time.After(24 * time.Second)
Log.SetHandler(llog.DiscardHandler())
f.Close()
}
}()
// Wait for log setup
for {
if start {
break
}
time.Sleep(time.Second * 5)
}
file, err := ioutil.ReadFile(*confPath)
if err != nil {
fmt.Println("No config.json provided, using default values!")
os.Exit(1)
}
var conf proxy.Config
if err := json.Unmarshal(file, &conf); err != nil {
os.Exit(1)
}
// creates new server instance using config.json
s := proxy.NewServer(Log, conf)
if err := s.Listen(); err != nil {
Log.Error("Listen", "error", err)
os.Exit(1)
}
}
开发者ID:seka17,项目名称:bracelet,代码行数:60,代码来源:main.go
示例7: main
func main() {
var err error
connPoolConfig := pgx.ConnPoolConfig{
ConnConfig: pgx.ConnConfig{
Host: "127.0.0.1",
User: "jack",
Password: "jack",
Database: "url_shortener",
Logger: log.New("module", "pgx"),
},
MaxConnections: 5,
AfterConnect: afterConnect,
}
pool, err = pgx.NewConnPool(connPoolConfig)
if err != nil {
log.Crit("Unable to create connection pool", "error", err)
os.Exit(1)
}
http.HandleFunc("/", urlHandler)
log.Info("Starting URL shortener on localhost:8080")
err = http.ListenAndServe("localhost:8080", nil)
if err != nil {
log.Crit("Unable to start web server", "error", err)
os.Exit(1)
}
}
开发者ID:jgrossophoff,项目名称:pgx,代码行数:28,代码来源:main.go
示例8: Log
// Log gets the log from the context
func Log(ctx context.Context) log15.Logger {
l, ok := FromContext(ctx)
if !ok {
l = log15.New()
}
return l
}
开发者ID:sheenobu,项目名称:quicklog,代码行数:8,代码来源:log.go
示例9: NewRouter
func NewRouter() *mux.Router {
var handler http.Handler
logger := log.New("module", "web.router")
router := mux.NewRouter().StrictSlash(true)
for _, route := range routes {
handler = route.HandlerFunc
handler = Logger(handler, route.Name, logger)
router.
Methods(route.Method).
Path(route.Pattern).
Name(route.Name).
Handler(handler)
}
currentFolder, err := osext.ExecutableFolder()
if err != nil {
panic(err)
}
handler = http.FileServer(http.Dir(currentFolder + "/html/lib/"))
handler = http.StripPrefix("/resources/", handler)
handler = Logger(handler, "Resources", logger)
router.
Methods("GET").
PathPrefix("/resources/").
Name("Resources").
Handler(handler)
return router
}
开发者ID:otaviokr,项目名称:check-my-speed,代码行数:32,代码来源:router.go
示例10: Init
func (d *Daemon) Init() error {
/* Setup the TLS authentication */
certf, keyf, err := shared.ReadMyCert("client.crt", "client.key")
if err != nil {
return err
}
d.certf = certf
d.keyf = keyf
d.tlsConfig, err = shared.GetTLSConfig(d.certf, d.keyf)
if err != nil {
return err
}
srvlog := log.New(log.Ctx{"module": "client"})
d.log = srvlog
handler := log.StdoutHandler
if quiet {
d.log.SetHandler(log.DiscardHandler())
} else if verbose {
d.log.SetHandler(log.LvlFilterHandler(log.LvlInfo, handler))
} else if debug {
d.log.SetHandler(log.LvlFilterHandler(log.LvlDebug, handler))
} else {
d.log.SetHandler(log.LvlFilterHandler(log.LvlError, handler))
}
d.Run()
return nil
}
开发者ID:jsimonetti,项目名称:tlstun,代码行数:31,代码来源:daemon.go
示例11: SetLogger
// SetLogger defines the *log.Logger where log messages are sent to.
func SetLogger(syslog string, logfile string, verbose bool, debug bool) error {
Log = log.New()
var handlers []log.Handler
var syshandler log.Handler
// System specific handler
syshandler = GetSystemHandler(syslog, debug)
if syshandler != nil {
handlers = append(handlers, syshandler)
}
// FileHandler
if logfile != "" {
if !PathExists(filepath.Dir(logfile)) {
return fmt.Errorf("Log file path doesn't exist: %s", filepath.Dir(logfile))
}
if !debug {
handlers = append(
handlers,
log.LvlFilterHandler(
log.LvlInfo,
log.Must.FileHandler(logfile, log.LogfmtFormat()),
),
)
} else {
handlers = append(handlers, log.Must.FileHandler(logfile, log.LogfmtFormat()))
}
}
// StderrHandler
if verbose || debug {
if !debug {
handlers = append(
handlers,
log.LvlFilterHandler(
log.LvlInfo,
log.StderrHandler,
),
)
} else {
handlers = append(handlers, log.StderrHandler)
}
} else {
handlers = append(
handlers,
log.LvlFilterHandler(
log.LvlWarn,
log.StderrHandler,
),
)
}
Log.SetHandler(log.MultiHandler(handlers...))
return nil
}
开发者ID:rockstar,项目名称:lxd,代码行数:60,代码来源:log.go
示例12: Initialize
func Initialize(logOut string, lvl interface{}) error {
if Log == nil {
Log = &Logger{
Logger: log.New(),
}
}
return Log.InitializeWithContext("main", logOut, lvl)
}
开发者ID:cloud66,项目名称:cxlogger,代码行数:8,代码来源:cxlogger.go
示例13: SetLogger
// SetLogger defines the *log.Logger where log messages are sent to.
func SetLogger(syslog string, logfile string, verbose bool, debug bool) error {
Log = log.New()
var handlers []log.Handler
// SyslogHandler
if syslog != "" {
if !debug {
handlers = append(
handlers,
log.LvlFilterHandler(
log.LvlError,
log.Must.SyslogHandler(syslog, log.LogfmtFormat()),
),
)
} else {
handlers = append(handlers, log.Must.SyslogHandler(syslog, log.LogfmtFormat()))
}
}
// FileHandler
if logfile != "" {
if !PathExists(filepath.Dir(logfile)) {
return fmt.Errorf("Log file path doesn't exist: %s\n", filepath.Dir(logfile))
}
if !debug {
handlers = append(
handlers,
log.LvlFilterHandler(
log.LvlError,
log.Must.FileHandler(logfile, log.LogfmtFormat()),
),
)
} else {
handlers = append(handlers, log.Must.FileHandler(logfile, log.LogfmtFormat()))
}
}
// StderrHandler
if verbose || debug {
if !debug {
handlers = append(
handlers,
log.LvlFilterHandler(
log.LvlError,
log.StderrHandler,
),
)
} else {
handlers = append(handlers, log.StderrHandler)
}
}
Log.SetHandler(log.MultiHandler(handlers...))
return nil
}
开发者ID:RuneTM,项目名称:lxd,代码行数:59,代码来源:log.go
示例14: log15LoggingMiddleware
func log15LoggingMiddleware(next http.Handler) http.Handler {
srvlog := log15.New("module", "app/server")
fn := func(w http.ResponseWriter, r *http.Request) {
t1 := time.Now()
next.ServeHTTP(w, r)
t2 := time.Now()
srvlog.Info("access", "method", r.Method, "path", r.URL.String(), "req_time", t2.Sub(t1))
}
return http.HandlerFunc(fn)
}
开发者ID:achiku,项目名称:sample-golang-logging,代码行数:10,代码来源:main.go
示例15: TestMain
func TestMain(m *testing.M) {
data, _ := ioutil.ReadFile("../simulation/test_data/demo.json")
var s simulation.Simulation
json.Unmarshal(data, &s)
mainLogger := log.New()
InitializeLogger(mainLogger)
simulation.InitializeLogger(mainLogger)
go Run(&s, "0.0.0.0", "22222")
os.Exit(m.Run())
}
开发者ID:ts2,项目名称:ts2-sim-server,代码行数:10,代码来源:main_test.go
示例16: NewUpdater
func NewUpdater(equinoxAppId, publicKeyPEM string) *Updater {
logger := log.New()
logger.SetHandler(log.DiscardHandler())
return &Updater{
Logger: logger,
EquinoxAppId: equinoxAppId,
PublicKeyPEM: publicKeyPEM,
DefaultChannel: "stable",
}
}
开发者ID:postfix,项目名称:axiom,代码行数:10,代码来源:axiom.go
示例17: baseServerCreate
func baseServerCreate(serverType string, addr string, tlsConfig *tls.Config) *baseServer {
return &baseServer{
address: addr,
logger: log15.New("module", serverType, "addr", addr),
stopCh: make(chan chan struct{}, 1),
serverStatus: stopped,
tlsConfig: tlsConfig,
}
}
开发者ID:sisatech,项目名称:raft,代码行数:11,代码来源:server.go
示例18: newLogger
func newLogger(conf ini.File) (log.Logger, error) {
level, _ := conf.Get("log", "level")
if level == "" {
level = "warn"
}
logger := log.New()
setFilterHandler(level, logger, log.StdoutHandler)
return logger, nil
}
开发者ID:jackc,项目名称:tpr,代码行数:11,代码来源:main.go
示例19: InitLog
// InitLog ...
func (logM *LogManager) InitLog() {
var svrlog = log.New(logM.LogContext, logM.LogContext)
svrlog.SetHandler(log.MultiHandler(log.StreamHandler(os.Stderr, log.LogfmtFormat()),
log.LvlFilterHandler(log.LvlError, log.Must.FileHandler(logM.LogDir+logM.ErrorFile, log.JsonFormat())),
log.LvlFilterHandler(log.LvlInfo, log.Must.FileHandler(logM.LogDir+logM.InfoFile, log.JsonFormat())),
log.LvlFilterHandler(log.LvlCrit, log.Must.FileHandler(logM.LogDir+logM.CritFile, log.JsonFormat())),
log.LvlFilterHandler(log.LvlDebug, log.Must.FileHandler(logM.LogDir+logM.DebugFile, log.JsonFormat()))))
logM.Logger = svrlog
}
开发者ID:amosunfemi,项目名称:xtremepay,代码行数:13,代码来源:log_manager.go
示例20: SetLogger
// SetLogger defines the *log.Logger where log messages are sent to.
func SetLogger(syslog string, logfile string, verbose bool, debug bool) {
Log = log.New()
var handlers []log.Handler
// SyslogHandler
if syslog != "" {
if !debug {
handlers = append(
handlers,
log.LvlFilterHandler(
log.LvlError,
log.Must.SyslogHandler(syslog, log.LogfmtFormat()),
),
)
} else {
handlers = append(handlers, log.Must.SyslogHandler(syslog, log.LogfmtFormat()))
}
}
// FileHandler
if logfile != "" {
if !debug {
handlers = append(
handlers,
log.LvlFilterHandler(
log.LvlError,
log.Must.FileHandler(logfile, log.LogfmtFormat()),
),
)
} else {
handlers = append(handlers, log.Must.FileHandler(logfile, log.LogfmtFormat()))
}
}
// StderrHandler
if verbose || debug {
if !debug {
handlers = append(
handlers,
log.LvlFilterHandler(
log.LvlError,
log.StderrHandler,
),
)
} else {
handlers = append(handlers, log.StderrHandler)
}
}
Log.SetHandler(log.MultiHandler(handlers...))
}
开发者ID:joker042,项目名称:lxd,代码行数:53,代码来源:log.go
注:本文中的gopkg/in/inconshreveable/log15/v2.New函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论