当前位置: 首页>>代码示例>>Golang>>正文


Golang logger.Println函数代码示例

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


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

示例1: selectRows

// select the rows into table
func selectRows(dbh *sql.DB) Rows {
	var t Rows

	logger.Println("events_stages_summary_global_by_event_name.selectRows()")
	sql := "SELECT EVENT_NAME, COUNT_STAR, SUM_TIMER_WAIT FROM events_stages_summary_global_by_event_name WHERE SUM_TIMER_WAIT > 0"

	rows, err := dbh.Query(sql)
	if err != nil {
		log.Fatal(err)
	}
	defer rows.Close()

	for rows.Next() {
		var r Row
		if err := rows.Scan(
			&r.eventName,
			&r.countStar,
			&r.sumTimerWait); err != nil {
			log.Fatal(err)
		}
		t = append(t, r)
	}
	if err := rows.Err(); err != nil {
		log.Fatal(err)
	}
	logger.Println("recovered", len(t), "row(s):")
	logger.Println(t)

	return t
}
开发者ID:denji,项目名称:ps-top,代码行数:31,代码来源:private.go

示例2: SetByName

// SetByName sets the view based on its name.
// - If we provide an empty name then use the default.
// - If we don't provide a valid name then give an error
func (v *View) SetByName(name string) {
	logger.Println("View.SetByName(" + name + ")")
	if name == "" {
		logger.Println("View.SetByName(): name is empty so setting to:", ViewLatency.String())
		v.Set(ViewLatency)
		return
	}

	for i := range names {
		if name == names[i] {
			v.code = Code(i)
			logger.Println("View.SetByName(", name, ")")
			return
		}
	}

	// suggest what should be used
	allViews := ""
	for i := range names {
		allViews = allViews + " " + names[i]
	}

	// no need for now to strip off leading space from allViews.
	log.Fatal("Asked for a view name, '", name, "' which doesn't exist. Try one of:", allViews)
}
开发者ID:ChengShuY,项目名称:ps-top,代码行数:28,代码来源:view.go

示例3: ValidateViews

// ValidateViews check which views are readable. If none are we give a fatal error
func ValidateViews(dbh *sql.DB) error {
	var count int
	var status string
	logger.Println("Validating access to views...")

	for v := range names {
		ta := tables[v]
		if ta.CheckSelectable(dbh) {
			status = "is"
			count++
		} else {
			status = "IS NOT"
		}
		tables[v] = ta
		logger.Println(v.String() + ": " + ta.Name() + " " + status + " SELECTable")
	}

	if count == 0 {
		return errors.New("None of the required tables are SELECTable. Giving up")
	}
	logger.Println(count, "of", len(names), "view(s) are SELECTable, continuing")

	setPrevAndNextViews()

	return nil
}
开发者ID:denji,项目名称:ps-top,代码行数:27,代码来源:view.go

示例4: Connect

// Connect makes a connection to the database using the previously defined settings
func (c *Connector) Connect() {
	var err error

	switch {
	case c.connectMethod == ConnectByComponents:
		logger.Println("ConnectByComponents() Connecting...")

		newDsn := mysql_defaults_file.BuildDSN(c.components, db)
		c.dbh, err = sql.Open(sqlDriver, newDsn)
	case c.connectMethod == ConnectByDefaultsFile:
		logger.Println("ConnectByDefaults_file() Connecting...")

		c.dbh, err = mysql_defaults_file.OpenUsingDefaultsFile(sqlDriver, c.defaultsFile, db)
	case c.connectMethod == ConnectByEnvironment:
		/***************************************************************************
		 **                                                                         *
		 *    WARNING          This functionality may be removed.        WARNING    *
		 *                                                                          *
		 *  While I've implemented this it may not be good/safe to actually use it. *
		 *  See: http://dev.mysql.com/doc/refman/5.6/en/password-security-user.html *
		 *  Store your password in the MYSQL_PWD environment variable. See Section  *
		 *  2.12, “Environment Variables”.                                          *
		 ****************************************************************************/
		logger.Println("ConnectByEnvironment() Connecting...")
		c.dbh, err = mysql_defaults_file.OpenUsingEnvironment(sqlDriver)
	default:
		log.Fatal("Connector.Connect() c.connectMethod not ConnectByDefaultsFile/ConnectByComponents/ConnectByEnvironment")
	}

	// we catch Open...() errors here
	if err != nil {
		log.Fatal(err)
	}
	c.postConnectAction()
}
开发者ID:ChengShuY,项目名称:ps-top,代码行数:36,代码来源:connector.go

示例5: mergeByName

// Convert the imported rows to a merged one with merged data.
// - Combine all entries with the same "name" by adding their values.
func (rows Rows) mergeByName(globalVariables *global.Variables) Rows {
	start := time.Now()
	rowsByName := make(map[string]Row)

	var newName string
	for i := range rows {
		var newRow Row

		if rows[i].sumTimerWait > 0 {
			newName = rows[i].simplifyName(globalVariables)

			// check if we have an entry in the map
			if _, found := rowsByName[newName]; found {
				newRow = rowsByName[newName]
			} else {
				newRow = Row{name: newName} // empty row with new name
			}
			newRow = add(newRow, rows[i])
			rowsByName[newName] = newRow // update the map with the new summed value
		}
	}

	// add the map contents back into the table
	var mergedRows Rows
	for _, row := range rowsByName {
		mergedRows = append(mergedRows, row)
	}
	if !mergedRows.Valid() {
		logger.Println("WARNING: mergeByName(): mergedRows is invalid")
	}

	logger.Println("mergeByName() took:", time.Duration(time.Since(start)).String(), "and returned", len(rowsByName), "rows")
	return mergedRows
}
开发者ID:ChengShuY,项目名称:ps-top,代码行数:36,代码来源:rows.go

示例6: ValidateViews

// ValidateViews check which views are readable. If none are we give a fatal error
func ValidateViews(dbh *sql.DB) error {
	var count int
	var status string
	logger.Println("Validating access to views...")

	// determine which of the defined views is valid because the underlying table access works
	for v := range names {
		ta := tables[v]
		e := ta.CheckSelectError(dbh)
		suffix := ""
		if e == nil {
			status = "is"
			count++
		} else {
			status = "IS NOT"
			suffix = " " + e.Error()
		}
		tables[v] = ta
		logger.Println(v.String() + ": " + ta.Name() + " " + status + " SELECTable" + suffix)
	}

	if count == 0 {
		return errors.New("None of the required tables are SELECTable. Giving up")
	}
	logger.Println(count, "of", len(names), "view(s) are SELECTable, continuing")

	setPrevAndNextViews()

	return nil
}
开发者ID:ChengShuY,项目名称:ps-top,代码行数:31,代码来源:view.go

示例7: EnableMutexMonitoring

// EnableMutexMonitoring changes settings to monitor wait/synch/mutex/%
func (si *SetupInstruments) EnableMutexMonitoring() {
	logger.Println("EnableMutexMonitoring")
	sqlMatch := "wait/synch/mutex/%"
	sqlSelect := "SELECT NAME, ENABLED, TIMED FROM setup_instruments WHERE NAME LIKE '" + sqlMatch + "' AND 'YES' NOT IN (ENABLED,TIMED)"
	collecting := "Collecting setup_instruments wait/synch/mutex configuration settings"
	updating := "Updating setup_instruments configuration for: wait/synch/mutex"

	si.Configure(sqlSelect, collecting, updating)
	logger.Println("EnableMutexMonitoring finishes")
}
开发者ID:ChengShuY,项目名称:ps-top,代码行数:11,代码来源:setup_instruments.go

示例8: collectAll

// CollectAll collects all the stats together in one go
func (app *App) collectAll() {
	logger.Println("app.collectAll() start")
	app.fsbi.Collect(app.dbh)
	app.tlwsbt.Collect(app.dbh)
	app.tiwsbt.Collect(app.dbh)
	app.users.Collect(app.dbh)
	app.essgben.Collect(app.dbh)
	app.ewsgben.Collect(app.dbh)
	app.memory.Collect(app.dbh)
	logger.Println("app.collectAll() finished")
}
开发者ID:ChengShuY,项目名称:ps-top,代码行数:12,代码来源:app.go

示例9: loadRegexps

// Load the ~/.pstoprc regexp expressions in section [munge]
func loadRegexps() {
	if loadedRegexps {
		return
	}
	loadedRegexps = true

	logger.Println("rc.loadRegexps()")

	haveRegexps = false
	filename := convertFilename(pstoprc)

	// Is the file is there?
	f, err := os.Open(filename)
	if err != nil {
		logger.Println("- unable to open " + filename + ", nothing to munge")
		return // can't open file. This is not fatal. We just can't do anything useful.
	}
	// If we get here the file is readable, so close it again.
	err = f.Close()
	if err != nil {
		// Do nothing. What can we do? Do we care?
	}

	// Load and process the ini file.
	i, err := go_ini.LoadFile(filename)
	if err != nil {
		log.Fatal("Could not load ~/.pstoprc", filename, ":", err)
	}

	// Note: This is wrong if I want to have an _ordered_ list of regexps
	// as go-ini provides me a hash so I lose the ordering. This may not
	// be desirable but as a first step accept this is broken.
	section := i.Section("munge")

	regexps = make(mungeRegexps, 0, len(section))

	// now look for regexps and load them in...
	for k, v := range section {
		var m mungeRegexp
		var err error

		m.pattern, m.replace = k, v
		m.re, err = regexp.Compile(m.pattern)
		if err == nil {
			m.valid = true
		}
		regexps = append(regexps, m)
	}

	if len(regexps) > 0 {
		haveRegexps = true
	}
	logger.Println("- found", len(regexps), "regexps to use to munge output")
}
开发者ID:ChengShuY,项目名称:ps-top,代码行数:55,代码来源:rc.go

示例10: Collect

// Collect collects data from the db, updating initial
// values if needed, and then subtracting initial values if we want
// relative values, after which it stores totals.
func (t *Object) Collect(dbh *sql.DB) {
	logger.Println("Object.Collect() - starting collection of data")
	start := time.Now()

	t.current = selectRows(dbh)
	logger.Println("t.current collected", len(t.current), "row(s) from SELECT")

	t.processlist2byUser()

	logger.Println("Object.Collect() END, took:", time.Duration(time.Since(start)).String())
}
开发者ID:ChengShuY,项目名称:ps-top,代码行数:14,代码来源:public.go

示例11: subtract

// subtract the countable values in one row from another
func (row *Row) subtract(other Row) {
	// check for issues here (we have a bug) and log it
	// - this situation should not happen so there's a logic bug somewhere else
	if row.sumTimerWait >= other.sumTimerWait {
		row.sumTimerWait -= other.sumTimerWait
		row.countStar -= other.countStar
	} else {
		logger.Println("WARNING: Row.subtract() - subtraction problem! (not subtracting)")
		logger.Println("row=", row)
		logger.Println("other=", other)
	}
}
开发者ID:ChengShuY,项目名称:ps-top,代码行数:13,代码来源:private.go

示例12: NewApp

// NewApp sets up the application given various parameters.
func NewApp(conn *connector.Connector, interval int, count int, stdout bool, defaultView string, disp display.Display) *App {
	logger.Println("app.NewApp()")
	app := new(App)

	app.ctx = new(context.Context)
	app.count = count
	app.dbh = conn.Handle()
	app.finished = false
	app.stdout = stdout
	app.display = disp
	app.display.SetContext(app.ctx)
	app.SetHelp(false)

	if err := view.ValidateViews(app.dbh); err != nil {
		log.Fatal(err)
	}

	logger.Println("app.Setup() Setting the default view to:", defaultView)
	app.view.SetByName(defaultView) // if empty will use the default

	app.setupInstruments = setup_instruments.NewSetupInstruments(app.dbh)
	app.setupInstruments.EnableMonitoring()

	app.wi.SetWaitInterval(time.Second * time.Duration(interval))

	variables, _ := lib.SelectAllGlobalVariablesByVariableName(app.dbh)
	// setup to their initial types/values
	app.fsbi = fsbi.NewFileSummaryByInstance(variables)
	app.tlwsbt = new(tlwsbt.Object)
	app.ewsgben = new(ewsgben.Object)
	app.essgben = new(essgben.Object)

	app.ctx.SetWantRelativeStats(true) // we show info from the point we start collecting data
	app.fsbi.SetWantRelativeStats(app.ctx.WantRelativeStats())
	app.tlwsbt.SetWantRelativeStats(app.ctx.WantRelativeStats())
	app.tiwsbt.SetWantRelativeStats(app.ctx.WantRelativeStats())
	app.users.SetWantRelativeStats(app.ctx.WantRelativeStats()) // ignored
	app.essgben.SetWantRelativeStats(app.ctx.WantRelativeStats())
	app.ewsgben.SetWantRelativeStats(app.ctx.WantRelativeStats()) // ignored

	app.fixLatencySetting() // adjust to see ops/latency

	app.resetDBStatistics()

	// get short name (to save space)
	hostname, _ := lib.SelectGlobalVariableByVariableName(app.dbh, "HOSTNAME")
	app.ctx.SetHostname(hostname)
	// get the MySQL version
	mysqlVersion, _ := lib.SelectGlobalVariableByVariableName(app.dbh, "VERSION")
	app.ctx.SetMySQLVersion(mysqlVersion)

	return app
}
开发者ID:denji,项目名称:ps-top,代码行数:54,代码来源:app.go

示例13: errorInExpectedList

// return true if the error is not in the expected list
func errorInExpectedList(actualError string, expectedErrors []string) bool {
	logger.Println("checking if", actualError, "is in", expectedErrors)
	e := actualError[0:11]
	expectedError := false
	for i := range expectedErrors {
		if e == expectedErrors[i] {
			logger.Println("found an expected error", expectedErrors[i])
			expectedError = true
			break
		}
	}
	logger.Println("returning", expectedError)
	return expectedError
}
开发者ID:ChengShuY,项目名称:ps-top,代码行数:15,代码来源:setup_instruments.go

示例14: sqlErrorHandler

// catch a SELECT error - specifically this one.
// Error 1146: Table 'performance_schema.memory_summary_global_by_event_name' doesn't exist
func sqlErrorHandler(err error) bool {
	var ignore bool

	logger.Println("- SELECT gave an error:", err.Error())
	if err.Error()[0:11] != "Error 1146:" {
		fmt.Println(fmt.Sprintf("XXX'%s'XXX", err.Error()[0:11]))
		log.Fatal("Unexpected error", fmt.Sprintf("XXX'%s'XXX", err.Error()[0:11]))
		// log.Fatal("Unexpected error:", err.Error())
	} else {
		logger.Println("- expected error, so ignoring")
		ignore = true
	}

	return ignore
}
开发者ID:ChengShuY,项目名称:ps-top,代码行数:17,代码来源:private.go

示例15: NewConnector

// new connector returns a connected Connector given the different parameters
func NewConnector(flags Flags) *Connector {
	var defaultsFile string
	connector := new(Connector)

	if *flags.UseEnvironment {
		connector.ConnectByEnvironment()
	} else {
		if *flags.Host != "" || *flags.Socket != "" {
			logger.Println("--host= or --socket= defined")
			var components = make(map[string]string)
			if *flags.Host != "" && *flags.Socket != "" {
				fmt.Println(lib.MyName() + ": Do not specify --host and --socket together")
				os.Exit(1)
			}
			if *flags.Host != "" {
				components["host"] = *flags.Host
			}
			if *flags.Port != 0 {
				if *flags.Socket == "" {
					components["port"] = fmt.Sprintf("%d", *flags.Port)
				} else {
					fmt.Println(lib.MyName() + ": Do not specify --socket and --port together")
					os.Exit(1)
				}
			}
			if *flags.Socket != "" {
				components["socket"] = *flags.Socket
			}
			if *flags.User != "" {
				components["user"] = *flags.User
			}
			if *flags.Password != "" {
				components["password"] = *flags.Password
			}
			connector.ConnectByComponents(components)
		} else {
			if flags.DefaultsFile != nil && *flags.DefaultsFile != "" {
				logger.Println("--defaults-file defined")
				defaultsFile = *flags.DefaultsFile
			} else {
				logger.Println("connecting by implicit defaults file")
			}
			connector.ConnectByDefaultsFile(defaultsFile)
		}
	}

	return connector
}
开发者ID:ChengShuY,项目名称:ps-top,代码行数:49,代码来源:flags.go


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