本文整理匯總了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)
}
}
}
示例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)
}
}
}
}
示例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
}
示例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"
}