本文整理汇总了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()),
}
}
示例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)
}
示例3: Prefix
// Prefix -> log.Prefix
func (this *Logger) Prefix() string {
if this == nil {
return log.Prefix()
}
this.Calls++
return this.Logger.Prefix()
}
示例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] ")
}
示例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
}
示例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")
}
}
示例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
}
}
示例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)
}
示例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)
}
}
示例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
}
示例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)
}
示例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...)
}
示例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
}
示例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...)
}
}
示例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...)
}
}