hypercli: github.com/hyperhq/hypercli/pkg/jsonlog Index | Files

package jsonlog

import "github.com/hyperhq/hypercli/pkg/jsonlog"

Package jsonlog provides helper functions to parse and print time (time.Time) as JSON.


Package Files

jsonlog.go jsonlog_marshalling.go jsonlogbytes.go time_marshalling.go


const (
    // RFC3339NanoFixed is our own version of RFC339Nano because we want one
    // that pads the nano seconds part with zeros to ensure
    // the timestamps are aligned in the logs.
    RFC3339NanoFixed = "2006-01-02T15:04:05.000000000Z07:00"
    // JSONFormat is the format used by FastMarshalJSON
    JSONFormat = `"` + time.RFC3339Nano + `"`

func FastTimeMarshalJSON Uses

func FastTimeMarshalJSON(t time.Time) (string, error)

FastTimeMarshalJSON avoids one of the extra allocations that time.MarshalJSON is making.

type JSONLog Uses

type JSONLog struct {
    // Log is the log message
    Log string `json:"log,omitempty"`
    // Stream is the log source
    Stream string `json:"stream,omitempty"`
    // Created is the created timestamp of log
    Created time.Time `json:"time"`

JSONLog represents a log message, typically a single entry from a given log stream. JSONLogs can be easily serialized to and from JSON and support custom formatting.

func (*JSONLog) Format Uses

func (jl *JSONLog) Format(format string) (string, error)

Format returns the log formatted according to format If format is nil, returns the log message If format is json, returns the log marshaled in json format By default, returns the log with the log time formatted according to format.

func (*JSONLog) MarshalJSON Uses

func (mj *JSONLog) MarshalJSON() ([]byte, error)

MarshalJSON marshals the JSONLog.

func (*JSONLog) MarshalJSONBuf Uses

func (mj *JSONLog) MarshalJSONBuf(buf *bytes.Buffer) error

MarshalJSONBuf marshals the JSONLog and stores the result to a bytes.Buffer.

func (*JSONLog) Reset Uses

func (jl *JSONLog) Reset()

Reset resets the log to nil.

type JSONLogs Uses

type JSONLogs struct {
    Log     []byte `json:"log,omitempty"`
    Stream  string `json:"stream,omitempty"`
    Created string `json:"time"`

    // json-encoded bytes
    RawAttrs json.RawMessage `json:"attrs,omitempty"`

JSONLogs is based on JSONLog. It allows marshalling JSONLog from Log as []byte and an already marshalled Created timestamp.

func (*JSONLogs) MarshalJSONBuf Uses

func (mj *JSONLogs) MarshalJSONBuf(buf *bytes.Buffer) error

MarshalJSONBuf is based on the same method from JSONLog It has been modified to take into account the necessary changes.

Package jsonlog imports 6 packages (graph) and is imported by 12 packages. Updated 2017-12-13. Refresh now. Tools for package owners.