當前位置: 首頁>>代碼示例>>Golang>>正文


Golang log.Prefix函數代碼示例

本文整理匯總了Golang中log.Prefix函數的典型用法代碼示例。如果您正苦於以下問題:Golang Prefix函數的具體用法?Golang Prefix怎麽用?Golang Prefix使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Prefix函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Capture

// Capture creates a new *Logger instance with an internal buffer. The prefix
// and flags default to the values of log.Prefix() and log.Flags(), respectively.
// This function is meant to be called from test code. See the godoc for the
// Logger struct for details.
func Capture() *Logger {
	out := new(bytes.Buffer)
	return &Logger{
		Log:    out,
		Logger: log.New(out, log.Prefix(), log.Flags()),
	}
}
開發者ID:smartystreets,項目名稱:logging,代碼行數:11,代碼來源:logging.go

示例2: main

func main() {

	r := Rectangle{length: 5, width: 3}
	fmt.Println("Rectangle r details are: ", r)
	fmt.Println("Rectangle r's area is: ", r.Area())

	s := Shaper(r)
	fmt.Println("Area of the Shape r is: ", s.Area())
	fmt.Println("Area of the Shape r is: ", s.Shit())

	return

	cfgFile := "file.txt"

	f, err := os.OpenFile(cfgFile, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0666) // For read access.
	if err != nil {
		checkError(err)
	}

	//	var l int
	myLog := log.New(f, "PREFIXIO ", log.Lshortfile|log.Ldate|log.Ltime)
	//	l, err = f.WriteString("HELLO THERE n");
	//	fmt.Printf("length is :%d\n", l);
	if err != nil {
		checkError2(err)
	}
	myLog.Println("from logger")
	//myFileAppendLine(cfgFile, "HELLO THERE \n");

	fmt.Printf("Flags:%q   Prefix:%q\n", log.Flags(), log.Prefix())
	os.Exit(0)
}
開發者ID:nandopeters,項目名稱:goplay,代碼行數:32,代碼來源:log1.go

示例3: Prefix

// Prefix -> log.Prefix
func (this *Logger) Prefix() string {
	if this == nil {
		return log.Prefix()
	}
	this.Calls++
	return this.Logger.Prefix()
}
開發者ID:smartystreets,項目名稱:logging,代碼行數:8,代碼來源:logging.go

示例4: Test_initLog_SetsLogFlagsIfDebugging

func (s *MainSuite) Test_initLog_SetsLogFlagsIfDebugging(c *C) {
	log.SetFlags(0)
	*config.DebugFlag = true
	initLog()
	c.Assert(log.Flags(), Equals, log.Ldate|log.Ltime|log.Llongfile)
	c.Assert(log.Prefix(), Equals, "[CoyIM] ")
}
開發者ID:twstrike,項目名稱:coyim,代碼行數:7,代碼來源:main_test.go

示例5: logMsg

func logMsg(level string, L *lua.LState) int {
	old := log.Prefix()
	log.SetPrefix(level)
	tpl := L.CheckString(1)
	top := L.GetTop()

	// Optimization for the case where no formatter needs to be
	// applied.
	if top <= 1 {
		log.Print(tpl)
		log.SetPrefix(old)
		return 0
	}

	args := make([]interface{}, top-1)
	for i := 2; i <= top; i++ {
		args[i-2] = L.Get(i)
	}

	// FIXME: If more args are supplied than placeholders, this will
	// generate an error.
	log.Printf(tpl, args...)
	log.SetPrefix(old)
	return 0
}
開發者ID:andars,項目名稱:caddy-lua,代碼行數:25,代碼來源:log.go

示例6: TestBeforeNotifyPanic

func TestBeforeNotifyPanic(t *testing.T) {

	stack := middlewareStack{}

	stack.OnBeforeNotify(func(e *Event, c *Configuration) error {
		panic("oops")
	})

	called := false
	b := &bytes.Buffer{}

	stack.Run(nil, &Configuration{Logger: log.New(b, log.Prefix(), 0)}, func() error {
		called = true
		return nil
	})

	logged := b.String()

	if logged != "bugsnag/middleware: unexpected panic: oops\n" {
		t.Errorf("Logged: %s", logged)
	}

	if called == false {
		t.Errorf("Notify was not called when BeforeNotify panicked")
	}
}
開發者ID:kyrylo,項目名稱:bugsnag-go,代碼行數:26,代碼來源:middleware_test.go

示例7: init

func init() {
	// Set up builtin middlewarez
	OnBeforeNotify(httpRequestMiddleware)

	// Default configuration
	Config.update(&Configuration{
		APIKey:        "",
		Endpoint:      "https://notify.bugsnag.com/",
		Hostname:      "",
		AppVersion:    "",
		ReleaseStage:  "",
		ParamsFilters: []string{"password", "secret"},
		// * for app-engine
		ProjectPackages:     []string{"main*"},
		NotifyReleaseStages: nil,
		Logger:              log.New(os.Stdout, log.Prefix(), log.Flags()),
		PanicHandler:        defaultPanicHandler,
		Transport:           http.DefaultTransport,
	})

	hostname, err := os.Hostname()
	if err == nil {
		Config.Hostname = hostname
	}
}
開發者ID:MerlinDMC,項目名稱:machine,代碼行數:25,代碼來源:bugsnag.go

示例8: Register

// Register sets CoLog as output for the default logger.
// It "hijacks" the standard logger flags and prefix previously set.
// It's not possible to know the output previously set, so the
// default os.Stderr is assumed.
func Register() {
	// Inherit standard logger flags and prefix if appropriate
	if !std.customFmt {
		std.formatter.SetFlags(log.Flags())
	}

	if log.Prefix() != "" && std.prefix == "" {
		std.SetPrefix(log.Prefix())
	}

	// Disable all extras
	log.SetPrefix("")
	log.SetFlags(0)

	// Set CoLog as output
	log.SetOutput(std)
}
開發者ID:bmbernie,項目名稱:socks,代碼行數:21,代碼來源:colog.go

示例9: pc

// print log in console, default log string wont be print in console
// NOTICE: when console is on, the process will really slowly
func (f *FileLogger) pc(str string) {
	if f.logConsole {
		if log.Prefix() != f.prefix {
			log.SetPrefix(f.prefix)
		}
		log.Println(str)
	}
}
開發者ID:victor-simida,項目名稱:gateway,代碼行數:10,代碼來源:writer.go

示例10: NewWebServer

func NewWebServer(webCfg *WebConfig, sessionService services.SessionService) framework.WebServer {

	sessionManager := NewSessionManager(webCfg, sessionService)
	_srv := _web.NewServer()
	_srv.Logger = log.New(ioutil.Discard, log.Prefix(), log.Flags())
	server := &webServer{config: webCfg, sessionManager: sessionManager, _srv: _srv}

	return server
}
開發者ID:mfelicio,項目名稱:go-einvite-traditional,代碼行數:9,代碼來源:server.go

示例11: Logf

// Logf logs a message to one or more loggers and uses a format string.
func (cxt *ExecutionContext) Logf(prefix string, format string, v ...interface{}) {
	if _, ok := cxt.skiplist[prefix]; ok {
		return
	}
	tmpPrefix := log.Prefix()
	log.SetPrefix(prefix)
	log.Printf(format, v...)
	log.SetPrefix(tmpPrefix)
}
開發者ID:ngpestelos,項目名稱:deis,代碼行數:10,代碼來源:context.go

示例12: logMsg

func logMsg(format, msg string, a ...interface{}) {
	defer log.SetFlags(log.Flags())
	defer log.SetPrefix(log.Prefix())
	log.SetFlags(0)
	log.SetPrefix("")

	msg = fmt.Sprintf(format+"\n", msg)
	log.Printf(msg, a...)
}
開發者ID:sknop,項目名稱:direnv,代碼行數:9,代碼來源:log.go

示例13: exportCommand

func exportCommand(env Env, args []string) (err error) {
	defer log.SetPrefix(log.Prefix())
	log.SetPrefix(log.Prefix() + "export:")
	log_debug("start")
	context := ExportContext{env: env}

	var target string

	if len(args) > 1 {
		target = args[1]
	}

	shell := DetectShell(target)
	if shell == nil {
		return fmt.Errorf("Unknown target shell '%s'", target)
	}

	log_debug("load config")
	if err = context.loadConfig(); err != nil {
		return
	}

	log_debug("loading RCs")
	if context.getRCs(); !context.hasRC() {
		return nil
	}

	log_debug("updating RC")
	if err = context.updateRC(); err != nil {
		log_debug("err: %v", err)
		context.resetEnv()
	}

	if context.newEnv == nil {
		log_debug("newEnv nil, exiting")
		return nil
	}

	diffString := context.diffString(shell)
	log_debug("env diff %s", diffString)
	fmt.Print(diffString)

	return
}
開發者ID:direnv,項目名稱:direnv,代碼行數:44,代碼來源:cmd_export.go

示例14: Printf

// Printf calls Printf only if the level is equal or lower than the set level.
// If the level is FatalLevel, it will call Fatalf regardless...
func Printf(l Level, format string, v ...interface{}) {
	if l == FatalLevel {
		stdLog.Fatalf(format, v...)
		return
	}

	if l <= level {
		defer stdLog.SetPrefix(stdLog.Prefix())
		stdLog.SetPrefix(levelPrefix[l])
		stdLog.Printf(format, v...)
	}
}
開發者ID:herrsebi,項目名稱:acd,代碼行數:14,代碼來源:extension.go

示例15: Print

// Print calls Print only if the level is equal or lower than the set level.
// If the level is FatalLevel, it will call Fatal regardless...
func Print(l Level, v ...interface{}) {
	if l == FatalLevel {
		stdLog.Fatal(v...)
		return
	}

	if l <= level {
		defer stdLog.SetPrefix(stdLog.Prefix())
		stdLog.SetPrefix(levelPrefix[l])
		stdLog.Print(v...)
	}
}
開發者ID:herrsebi,項目名稱:acd,代碼行數:14,代碼來源:extension.go


注:本文中的log.Prefix函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。