コード例 #1
0
ファイル: lc-admin.go プロジェクト: atmosx/log-courier
func (a *Admin) renderSnapYAML(indent string, snap *core.Snapshot) {
	if snap.NumEntries() != 0 {
		for i, j := 0, snap.NumEntries(); i < j; i = i + 1 {
			k, v := snap.Entry(i)
			switch t := v.(type) {
			case string:
				fmt.Printf(indent+"%s: %s\n", k, t)
			case int, int8, int16, int32, int64, uint8, uint16, uint32, uint64:
				fmt.Printf(indent+"%s: %d\n", k, t)
			case float32, float64:
				fmt.Printf(indent+"%s: %.2f\n", k, t)
			case time.Time:
				fmt.Printf(indent+"%s: %s\n", k, t.Format("_2 Jan 2006 15.04.05"))
			case time.Duration:
				fmt.Printf(indent+"%s: %s\n", k, (t - (t % time.Second)).String())
			default:
				fmt.Printf(indent+"%s: %v\n", k, t)
			}
		}
	}
	if snap.NumSubs() != 0 {
		for i, j := 0, snap.NumSubs(); i < j; i = i + 1 {
			sub_snap := snap.Sub(i)
			fmt.Printf(indent+"%s:\n", sub_snap.Description())
			a.renderSnapYAML(indent+"  ", sub_snap)
		}
	}
}
コード例 #2
0
ファイル: lc-admin.go プロジェクト: atmosx/log-courier
func (a *Admin) renderSnapJSON(indent string, snap *core.Snapshot) {
	if snap.NumEntries() != 0 {
		for i, j := 0, snap.NumEntries(); i < j; i = i + 1 {
			k, v := snap.Entry(i)
			switch t := v.(type) {
			case string:
				fmt.Printf(indent+"%q: %q", k, t)
			case int8, int16, int32, int64, uint8, uint16, uint32, uint64:
				fmt.Printf(indent+"%q: %d", k, t)
			case float32, float64:
				fmt.Printf(indent+"%q: %.2f", k, t)
			case time.Time:
				fmt.Printf(indent+"%q: %q", k, t.Format("_2 Jan 2006 15.04.05"))
			case time.Duration:
				fmt.Printf(indent+"%q: %q", k, (t - (t % time.Second)).String())
			default:
				fmt.Printf(indent+"%q: %q", k, fmt.Sprintf("%v", t))
			}
			if i+1 < j || snap.NumSubs() != 0 {
				fmt.Printf(",\n")
			} else {
				fmt.Printf("\n")
			}
		}
	}
	if snap.NumSubs() != 0 {
		for i, j := 0, snap.NumSubs(); i < j; i = i + 1 {
			sub_snap := snap.Sub(i)
			fmt.Printf(indent+"%q: {\n", sub_snap.Description())
			a.renderSnapJSON(indent+"\t", sub_snap)
			if i+1 < j {
				fmt.Printf(indent + "},\n")
			} else {
				fmt.Printf(indent + "}\n")
			}
		}
	}
}