本文整理汇总了Golang中github.com/docker/docker/pkg/jsonlog.JSONLog类的典型用法代码示例。如果您正苦于以下问题:Golang JSONLog类的具体用法?Golang JSONLog怎么用?Golang JSONLog使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JSONLog类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: decodeLogLine
func decodeLogLine(dec *json.Decoder, l *jsonlog.JSONLog) (*logger.Message, error) {
l.Reset()
if err := dec.Decode(l); err != nil {
return nil, err
}
msg := &logger.Message{
Source: l.Stream,
Timestamp: l.Created,
Line: []byte(l.Log),
}
return msg, nil
}
开发者ID:ChanderG,项目名称:docker,代码行数:12,代码来源:jsonfilelog.go
示例2: Write
// Write writes bytes to all writers. Failed writers will be evicted during
// this call.
func (w *BroadcastWriter) Write(p []byte) (n int, err error) {
created := time.Now().UTC()
w.Lock()
if writers, ok := w.streams[""]; ok {
for sw := range writers {
if n, err := sw.Write(p); err != nil || n != len(p) {
// On error, evict the writer
delete(writers, sw)
}
}
}
if w.jsLogBuf == nil {
w.jsLogBuf = new(bytes.Buffer)
w.jsLogBuf.Grow(1024)
}
w.buf.Write(p)
for {
line, err := w.buf.ReadString('\n')
if err != nil {
w.buf.WriteString(line)
break
}
for stream, writers := range w.streams {
if stream == "" {
continue
}
jsonLog := jsonlog.JSONLog{Log: line, Stream: stream, Created: created}
err = jsonLog.MarshalJSONBuf(w.jsLogBuf)
if err != nil {
log.Errorf("Error making JSON log line: %s", err)
continue
}
w.jsLogBuf.WriteByte('\n')
b := w.jsLogBuf.Bytes()
for sw := range writers {
if _, err := sw.Write(b); err != nil {
delete(writers, sw)
}
}
}
w.jsLogBuf.Reset()
}
w.jsLogBuf.Reset()
w.Unlock()
return len(p), nil
}
开发者ID:balagopalraj,项目名称:clearlinux,代码行数:48,代码来源:broadcastwriter.go
注:本文中的github.com/docker/docker/pkg/jsonlog.JSONLog类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论