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


Golang StringVector.Resize方法代码示例

本文整理汇总了Golang中container/vector.StringVector.Resize方法的典型用法代码示例。如果您正苦于以下问题:Golang StringVector.Resize方法的具体用法?Golang StringVector.Resize怎么用?Golang StringVector.Resize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在container/vector.StringVector的用法示例。


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

示例1: intLogc

// Send a closure log message internally
func (log *Logger) intLogc(level int, closure func() string) {
	// Create a vector long enough to not require resizing
	var logto vector.StringVector
	logto.Resize(0, len(log.filterLevels))

	// Determine if any logging will be done
	for filt := range log.filterLevels {
		if level >= log.filterLevels[filt] {
			logto.Push(filt)
		}
	}

	// Only log if a filter requires it
	if len(logto) > 0 {
		// Determine caller func
		pc, _, lineno, ok := runtime.Caller(2)
		src := ""
		if ok {
			src = fmt.Sprintf("%s:%d", runtime.FuncForPC(pc).Name(), lineno)
		}

		// Make the log record from the closure's return
		rec := newLogRecord(level, src, closure())

		// Dispatch the logs
		for _, filt := range logto {
			log.filterLogWriters[filt].LogWrite(rec)
		}
	}
}
开发者ID:Kissaki,项目名称:log4go,代码行数:31,代码来源:log4go.go

示例2: Log

// Send a log message manually
func (log *Logger) Log(level int, source, message string) {
	// Create a vector long enough to not require resizing
	var logto vector.StringVector
	logto.Resize(0, len(log.filterLevels))

	// Determine if any logging will be done
	for filt := range log.filterLevels {
		if level >= log.filterLevels[filt] {
			logto.Push(filt)
		}
	}

	// Only log if a filter requires it
	if len(logto) > 0 {
		// Make the log record
		rec := newLogRecord(level, source, message)

		// Dispatch the logs
		for _, filt := range logto {
			lw := log.filterLogWriters[filt]
			if lw.Good() {
				lw.LogWrite(rec)
			}
		}
	}
}
开发者ID:Kissaki,项目名称:log4go,代码行数:27,代码来源:log4go.go

示例3: removeEmptyStrings

func removeEmptyStrings(arr []string) []string {
	sv := new(vector.StringVector)
	sv.Resize(0, len(arr))
	for _, s := range arr {
		if s != "" {
			sv.Push(s)
		}
	}
	return *sv
}
开发者ID:pombredanne,项目名称:dsocial.go,代码行数:10,代码来源:util.go

示例4: FormatLogRecord

// Known format codes:
// %T - Time (15:04:05 MST)
// %t - Time (15:04)
// %D - Date (2006/01/02)
// %d - Date (01/02/06)
// %L - Level (FNST, FINE, DEBG, TRAC, WARN, EROR, CRIT)
// %S - Source
// %M - Message
// Ignores unknown formats
// Recommended: "[%D %T] [%L] (%S) %M"
func FormatLogRecord(format string, rec *LogRecord) string {
	var ovec vector.StringVector

	// Split the string into pieces by % signs
	pieces := strings.Split(format, "%", -1)
	ovec.Resize(0, 2*len(pieces)+2) // allocate enough pieces for each piece and its previous plus an extra for the first and last piece for good measure

	// Iterate over the pieces, replacing known formats
	for i, piece := range pieces {
		if i > 0 && len(piece) > 0 {
			switch piece[0] {
			case 'T':
				ovec.Push(rec.Created.Format("15:04:05 MST"))
			case 't':
				ovec.Push(rec.Created.Format("15:04"))
			case 'D':
				ovec.Push(rec.Created.Format("2006/01/02"))
			case 'd':
				ovec.Push(rec.Created.Format("01/02/06"))
			case 'L':
				ovec.Push(levelStrings[rec.Level])
			case 'S':
				ovec.Push(rec.Source)
			case 'M':
				ovec.Push(rec.Message)
			}
			if len(piece) > 1 {
				ovec.Push(piece[1:])
			}
		} else if len(piece) > 0 {
			ovec.Push(piece)
		}
	}

	return strings.Join(ovec, "") + "\n"
}
开发者ID:QBui,项目名称:log4go,代码行数:46,代码来源:pattlog.go


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