コード例 #1
0
ファイル: php.go プロジェクト: lovek323/bclog
func (e *PhpStackTraceLogEvent) PrintLine(index int) {
	fmt.Printf("[%d]  ", index)
	fmt.Print(e.SyslogTime.Format("2006-01-02 15:04:05") + "  ")
	ct.ChangeColor(ct.Yellow, false, ct.None, false)
	fmt.Print("php-stack-trace  ")
	ct.ChangeColor(ct.Cyan, false, ct.None, false)
	fmt.Printf("%d-%s-%d  ", e.Number, e.File, e.Line)
	ct.ResetColor()
	fmt.Printf("%s\n", e.Method)
}
コード例 #2
0
ファイル: bigcommerce-app.go プロジェクト: lovek323/bclog
func (e *BigcommerceAppLogEvent) PrintLine(index int) {
	fmt.Printf("[%d]  ", index)
	fmt.Printf("%s  ", e.SyslogTime.Format("2006-01-02 15:04:05"))
	ct.ChangeColor(ct.Yellow, false, ct.None, false)
	fmt.Print("bigcommerce-app  ")
	ct.ChangeColor(ct.Cyan, false, ct.None, false)
	fmt.Printf("%s-%d  ", e.LogLevel, e.StoreContext.StoreId)
	ct.ResetColor()
	fmt.Printf("%s\n", e.Content)
}
コード例 #3
0
ファイル: process.go プロジェクト: lovek323/bclog
func (e *ProcessLogEvent) PrintLine(index int) {
	fmt.Printf("[%d]  ", index)
	fmt.Print(e.SyslogTime.Format("2006-01-02 15:04:05") + "  ")
	ct.ChangeColor(ct.Yellow, false, ct.None, false)
	fmt.Print("process  ")
	ct.ChangeColor(ct.Cyan, false, ct.None, false)
	fmt.Printf("%s-%d  ", e.Name, e.ProcessId)
	ct.ResetColor()
	fmt.Printf("%s\n", e.Content)
}
コード例 #4
0
ファイル: generic.go プロジェクト: lovek323/bclog
func (e *GenericLogEvent) PrintLine(index int) {
	fmt.Printf("[%d]  ", index)
	fmt.Print(e.SyslogTime.Format("2006-01-02 15:04:05") + "  ")
	ct.ChangeColor(ct.Yellow, false, ct.None, false)
	fmt.Print("generic  ")
	ct.ChangeColor(ct.Cyan, false, ct.None, false)
	fmt.Printf("%s  ", e.Name)
	ct.ResetColor()
	fmt.Printf("%s\n", e.Content)
}
コード例 #5
0
ファイル: console.go プロジェクト: wgq91here/chandra
func WriteOutLevel(l string) {
	switch l {
	case OUT_LEVEL_WARNING:
		ct.ChangeColor(ct.Yellow, true, ct.None, false)
	case OUT_LEVEL_ERROR:
		ct.ChangeColor(ct.Red, true, ct.None, false)
	case OUT_LEVEL_INFO:
		ct.ChangeColor(ct.Cyan, true, ct.None, false)
	default:
		ct.ResetColor()
	}
}
コード例 #6
0
ファイル: outlet.go プロジェクト: commonnet/forego
// Write out a single coloured line
func (of *OutletFactory) WriteLine(left, right string, leftC, rightC ct.Color, isError bool) {
	of.Lock()
	defer of.Unlock()

	ct.ChangeColor(leftC, true, ct.None, false)
	formatter := fmt.Sprintf("%%-%ds | ", of.Padding)
	fmt.Printf(formatter, left)

	if isError {
		ct.ChangeColor(ct.Red, true, ct.None, true)
	} else {
		ct.ResetColor()
	}
	fmt.Println(right)
	if isError {
		ct.ResetColor()
	}
}
コード例 #7
0
ファイル: nginx.go プロジェクト: lovek323/bclog
func (e *NginxAccessLogEvent) PrintLine(index int) {
	background := ct.None
	bold := false

	if e.Request.StatusCode >= 500 {
		background = ct.Red
		bold = false
	} else {
		background = ct.None
		bold = true
	}

	fmt.Printf("[%d]  ", index)
	fmt.Print(e.Time.Format("2006-01-02 15:04:05") + "  ")
	ct.ChangeColor(ct.Yellow, bold, background, false)
	fmt.Print("nginx-access  ")
	ct.ChangeColor(ct.Cyan, bold, background, false)
	fmt.Printf("%s-%d  ", e.Request.Method, e.Request.StatusCode)
	fmt.Printf("%s\n", e.Request.Uri)
	ct.ResetColor()
}
コード例 #8
0
ファイル: nginx.go プロジェクト: lovek323/bclog
func (e *NginxErrorLogEvent) PrintLine(index int) {
	fmt.Printf("[%d]  ", index)

	if e.LogLevel == "error" {
		fmt.Print(e.SyslogTime.Format("2006-01-02 15:04:05") + "  ")
		ct.ChangeColor(ct.Yellow, false, ct.Red, false)
		fmt.Print("nginx-error  ")
		ct.ChangeColor(ct.Cyan, false, ct.Red, false)
		fmt.Printf("%s  ", e.LogLevel)
		ct.ChangeColor(ct.None, false, ct.Red, false)
		fmt.Printf("%s %s\n", e.Request.Uri, e.Content)
		ct.ResetColor()
	} else {
		fmt.Print(e.SyslogTime.Format("2006-01-02 15:04:05") + "  ")
		ct.ChangeColor(ct.Yellow, false, ct.None, false)
		fmt.Print("nginx-error  ")
		ct.ChangeColor(ct.Cyan, false, ct.None, false)
		fmt.Printf("%s  ", e.LogLevel)
		ct.ResetColor()
		fmt.Printf("%s %s\n", e.Request.Uri, e.Content)
	}
}
コード例 #9
0
ファイル: php.go プロジェクト: lovek323/bclog
func (e *PhpLogEvent) PrintLine(index int) {
	background := ct.None

	switch e.LogLevel {
	case "Notice":
	case "Warning":
		background = ct.None
		break
	case "Fatal error":
		background = ct.Red
		break
	case "Catchable fatal error":
		background = ct.Red
		break
	case "Parse error":
		background = ct.Red
		break
	case "SQL Error":
		background = ct.Red
		break
	case "Strict standards":
		background = ct.None
		break
	default:
		log.Fatalf(e.LogLevel)
	}

	fmt.Printf("[%d]  ", index)
	fmt.Print(e.SyslogTime.Format("2006-01-02 15:04:05") + "  ")
	ct.ChangeColor(ct.Yellow, false, background, false)
	fmt.Print("php  ")
	ct.ChangeColor(ct.Cyan, false, background, false)
	fmt.Printf("%s-%s-%d  ", e.LogLevel, e.File, e.Line)
	ct.ChangeColor(ct.None, false, background, false)
	fmt.Printf("%s\n", e.Content)
	ct.ResetColor()
}
コード例 #10
0
ファイル: formatter.go プロジェクト: ElricleNecro/TOD
// A simple function to print message with colors.
func ColoredPrint(thecolor color.Color, bold bool, values ...interface{}) {

	// change the color of the terminal
	color.ChangeColor(
		thecolor,
		bold,
		None,
		false,
	)

	// print
	fmt.Print(values...)

	// reset the color
	color.ResetColor()
}
コード例 #11
0
ファイル: ShowImage_test.go プロジェクト: pa001024/reflex
func TestGetConsoleColor(t *testing.T) {
	for b := uint32(0); b < 6; b++ {
		for g := uint32(0); g < 6; g++ {
			for r := uint32(0); r < 6; r++ {
				m, l, h, j, k := GetConsoleColor(r*0x33/4, g*0x33/4, b*0x33/4)
				ct.ChangeColor(l, h, j, k)
				c := clist64[m : m+1]
				c = c + c + c + c
				if k {
					fmt.Printf("%s%x", c, (j-1)<<1)
				} else {
					fmt.Printf("%s%x", c, (j - 1))
				}
				ct.ResetColor()
				fmt.Printf("#%02x%02x%02x ", r*0x33, g*0x33, b*0x33)
			}
			fmt.Print("\n")
		}
	}
}
コード例 #12
0
ファイル: ShowImage.go プロジェクト: pa001024/reflex
// 将图片渲染到文字(有颜色版)
func ShowColor(iw io.Writer, img image.Image, console Console) {
	// Lanczos3缩放图片到控制台屏幕大小
	w := console.ScreenW - 1 // 标宽 换行符竟然也算一个?
	s := img.Bounds().Size()
	// 标高 = 结果高 * 宽高比 = (原高 / 原宽 * 标宽) * 宽高比
	h := uint(float64(s.Y) / float64(s.X) * float64(w) * console.Ratio())
	m := resize.Resize(w, h, img, resize.Bicubic)
	for y := 0; y < int(h); y++ {
		for x := (0); x < int(w); x++ {
			r, g, b, a := m.At(x, y).RGBA()
			r, g, b, a = r>>10, g>>10, b>>10, a>>10 // 转换到6位色 0~63
			r, g, b = r*a/63, g*a/63, b*a/63        // Alpha混合
			m, fg, fgl, bg, bgl := GetConsoleColor(r, g, b)
			ct.ChangeColor(fg, fgl, bg, bgl)
			// cindex := (r + g + b) / 3
			io.WriteString(iw, clist64[m:m+1])
		}
		io.WriteString(iw, "\n")
	}
	ct.ResetColor()
}
コード例 #13
0
ファイル: golog.go プロジェクト: robsix/golog
func print(timeFormat string, le *logEntry) {
	var level string
	switch le.level {
	case Info:
		level = "INFO    "
		ct.Foreground(ct.Cyan, false)
	case Warning:
		level = "WARNING "
		ct.Foreground(ct.Yellow, false)
	case Error:
		level = "ERROR   "
		ct.Foreground(ct.Red, false)
	case Critical:
		level = "CRITICAL"
		ct.ChangeColor(ct.Black, false, ct.Red, false)
	case Fatal:
		level = "FATAL   "
		ct.ResetColor()
	}
	fmt.Println(le.time.Format(timeFormat), level, le.message)
	ct.ResetColor()
}
コード例 #14
0
ファイル: text.go プロジェクト: RomainVabre/origin
func (t *textLogger) Write(entry Entry) {
	if t.ttyOutput {
		ct.ChangeColor(entry.Level.Color, entry.Level.Bright, ct.None, false)
	}
	text := strings.TrimSpace(entry.Message)
	if entry.Level.Level >= WarnLevel.Level {
		text = fmt.Sprintf("[%s from %s]\n", entry.ID, entry.Origin) + text
	}
	if strings.Contains(text, "\n") { // separate multiline comments with newlines
		if !t.lastNewline {
			fmt.Fprintln(t.out) // separate from previous one-line log msg
		}
		text = text + "\n"
		t.lastNewline = true
	} else {
		t.lastNewline = false
	}
	fmt.Fprintln(t.out, entry.Level.Prefix+strings.Replace(text, "\n", "\n       ", -1))
	if t.ttyOutput {
		ct.ResetColor()
	}
}
コード例 #15
0
ファイル: php.go プロジェクト: lovek323/bclog
func (e *PhpLogEvent) PrintFull() {
	fmt.Printf("\n---------- PHP LOG EVENT ----------\n")

	writer := new(tabwriter.Writer)
	writer.Init(os.Stdout, 0, 8, 2, ' ', 0)

	fmt.Fprintf(
		writer,
		"SyslogTime:\t%s\n",
		e.SyslogTime.Format("2006-01-02 15:04:05"),
	)

	fmt.Fprintf(writer, "LogLevel:\t%s\n", e.LogLevel)
	fmt.Fprintf(writer, "Content:\t%s\n", e.Content)
	fmt.Fprintf(writer, "File:\t%s\n", e.File)
	fmt.Fprintf(writer, "Line:\t%d\n", e.Line)

	writer.Flush()

	ct.ChangeColor(ct.White, true, ct.None, false)
	fmt.Print("\nStack trace\n")
	ct.ResetColor()

	for _, phpStackTraceLogEvent := range e.StackTraceEvents {
		fmt.Fprintf(
			writer,
			"%d.\t%s\t%s\t%d\n",
			phpStackTraceLogEvent.Number,
			phpStackTraceLogEvent.Method,
			phpStackTraceLogEvent.File,
			phpStackTraceLogEvent.Line,
		)
	}

	writer.Flush()

	fmt.Printf("\n---------- PHP LOG EVENT ----------\n")
}
コード例 #16
0
ファイル: main.go プロジェクト: lovek323/bclog
func summary(args []string) {
	var duration time.Duration
	var err error

	if len(args) > 0 {
		if args[0] == "last-prompt" {
			duration = time.Now().Sub(lastPrompt)
		} else {
			duration, err = time.ParseDuration(args[0])

			if err != nil {
				fmt.Println(
					"Invalid syntax: first argument to summary must be a valid " +
						"duration or empty",
				)
				fmt.Println("summary [duration]\n")
			}
		}
	} else {
		duration, _ = time.ParseDuration("24h")
	}

	ct.ChangeColor(ct.Yellow, true, ct.None, false)
	fmt.Printf("\nSUMMARY (LAST %s)\n", duration)
	ct.ResetColor()

	writer := new(tabwriter.Writer)
	writer.Init(os.Stdout, 0, 8, 2, ' ', 0)

	for summary, events := range statistics {
		lastDuration := history[len(history)-1].GetSyslogTime().Sub(
			events[len(events)-1].GetSyslogTime(),
		)

		count := 0

		for _, event := range events {
			if event == nil {
				continue
			}
			if history[len(history)-1].GetSyslogTime().Sub(event.GetSyslogTime()) <= duration {
				count++
			}
		}

		if count == 0 {
			continue
		}

		fmt.Fprintf(
			writer,
			"%s\t%d event(s)\tLast %s ago\n",
			summary,
			count,
			lastDuration,
		)
	}

	writer.Flush()

	fmt.Print("\n")
}
コード例 #17
0
ファイル: tail.go プロジェクト: nizsheanez/ria
func Tail() cli.Command {
	command := cli.Command{
		Name:  "tail",
		Usage: "show last logs",
		Flags: []cli.Flag{
			cli.StringFlag{
				Name:  "s",
				Value: "web01.mylan",
				Usage: "server",
			},
			cli.StringFlag{
				Name:  "v",
				Value: "country",
				Usage: "my",
			},
			cli.IntFlag{
				Name:  "n",
				Value: 100,
				Usage: "number of lines",
			},
			cli.BoolFlag{
				Name:  "f",
				Usage: "watch results",
			},
		},
		Action: func(c *cli.Context) {

			config := &ssh.ClientConfig{
				User: "******",
				Auth: []ssh.AuthMethod{ssh_utils.MakeKeyring()},
			}

			type Host struct {
				name   string
				stdout chan string
			}
			var hosts []*Host

			for _, hostName := range strings.Split(c.String("s"), ",") {
				hosts = append(hosts, &Host{
					name:   hostName,
					stdout: make(chan string, 100),
				})
			}
			stderr := make(chan error)

			for _, host := range hosts {
				var flags string
				if c.Bool("f") {
					flags += " -f"
				} else {
					flags += " -" + c.String("n")
				}
				cmd := "tail " + flags + " /shop/logs/live/nginx/alice.access.log-20140821"
				go ssh_utils.ExecuteCmd(cmd, host.name, config, host.stdout, stderr)

			}

			go func() {
				cases := make([]reflect.SelectCase, len(hosts))
				for i, host := range hosts {
					cases[i] = reflect.SelectCase{Dir: reflect.SelectRecv, Chan: reflect.ValueOf(host.stdout)}
				}
				for {
					if chosen, value, ok := reflect.Select(cases); ok {
						host := hosts[chosen]
						res := value.String()

						color.ChangeColor(color.Blue, true, color.None, false)
						fmt.Print(host.name + ": ")
						color.ResetColor()
						fmt.Print(res)
					}
				}
			}()

			err := <-stderr
			println(fmt.Sprintf("%q", err))
		},
	}
	return command
}
コード例 #18
0
ファイル: util.go プロジェクト: tmaiaroto/discfg
// Changes the color for error messages. Good for one line heading. Any lengthy response should probably not be colored with a red background.
func errorLabel(message string) {
	ct.ChangeColor(ct.White, true, ct.Red, false)
	fmt.Print(message)
	ct.ResetColor()
	fmt.Println("")
}
コード例 #19
0
ファイル: color.go プロジェクト: cfstras/pcm
func Color(color ct.Color, msg ...interface{}) {
	ct.ChangeColor(color, false, ct.None, false)
	fmt.Print(msg...)
	ct.ResetColor()
}
コード例 #20
0
ファイル: main.go プロジェクト: hoffoo/github-monitor
func (gj *GithubJSON) summarize() (skipped bool) {

	switch gj.GetType() {
	case "Project":
		if summary == false {
			gcolor.ChangeColor(gcolor.Green, true, gcolor.None, false)
			fmt.Println(gj.Full_Name)
			gcolor.ResetColor()
			if len(gj.Description) > 0 {
				fmt.Println(gj.Description)
			}
			if gj.Open_Issues > 0 {
				fmt.Printf("https://github.com/%s/issues : %d issues\n", gj.Full_Name, gj.Open_Issues)
			}

			fmt.Printf("forked: %d   watched: %d\n", gj.Forks_Count, gj.Watchers_Count)
			gcolor.ChangeColor(gcolor.Blue, true, gcolor.None, false)
			fmt.Printf("%s\n\n", gj.Html_Url)
			gcolor.ResetColor()
		} else {
			if gj.Open_Issues > 0 {
				format("%s %d - %d open", gj.Full_Name, gj.Watchers_Count, gj.Open_Issues)
			} else {
				format("%s %d", gj.Full_Name, gj.Watchers_Count)
			}
		}
	case "WatchEvent":
		skipped = format("%s star %s", gj.Actor.Login, gj.Repo.Name)
	case "FollowEvent":
		skipped = format("%s follow %s", gj.Actor.Login, gj.Payload.Target.Login)
	case "IssuesEvent":
		switch gj.Payload.Action {
		case "created":
			skipped = format("%s comment issue %d %s", gj.Actor.Login, gj.Payload.Issue.Number, gj.Repo.Name)
		case "opened":
			skipped = format("%s made issue %d %s", gj.Actor.Login, gj.Payload.Issue.Number, gj.Repo.Name)
		case "closed":
			skipped = format("%s close issue %d %s", gj.Actor.Login, gj.Payload.Issue.Number, gj.Repo.Name)
		case "reopened":
			skipped = format("%s reopened issue %d %s", gj.Actor.Login, gj.Payload.Issue.Number, gj.Repo.Name)
		default:
			skipped = format("-> %s %s %s", gj.Type, gj.Actor.Login, gj.Repo.Name)
		}
	case "IssueCommentEvent":
		skipped = format("%s comment issue %d %s", gj.Actor.Login, gj.Payload.Issue.Number, gj.Repo.Name)
	case "PushEvent":
		skipped = format("%s push to %s", gj.Actor.Login, gj.Repo.Name)
	case "ForkEvent":
		skipped = format("%s fork %s", gj.Actor.Login, gj.Repo.Name)
	case "CreateEvent":
		switch gj.Payload.Ref_Type {
		case "tag":
			skipped = format("%s tag %s %s", gj.Actor.Login, gj.Payload.Ref, gj.Repo.Name)
		case "repository":
			skipped = format("%s create %s", gj.Actor.Login, gj.Repo.Name)
		case "branch":
			skipped = format("%s branch %s", gj.Actor.Login, gj.Repo.Name)
		default:
			skipped = format("-> %s %s %s", gj.Type, gj.Actor.Login, gj.Repo.Name)
		}
	case "PullRequestReviewCommentEvent":
		skipped = format("%s pr comment on %s", gj.Actor.Login, gj.Repo.Name)
	case "PullRequestEvent":
		switch gj.Payload.Action {
		case "closed":
			skipped = format("%s close pr %d %s", gj.Actor.Login, gj.Payload.Number, gj.Repo.Name)
		case "opened":
			skipped = format("%s create pr %d %s", gj.Actor.Login, gj.Payload.Number, gj.Repo.Name)
		case "reopened":
			skipped = format("%s reopened pr %d %s", gj.Actor.Login, gj.Payload.Number, gj.Repo.Name)
		default:
			skipped = format("-> %s %s %s", gj.Type, gj.Actor.Login, gj.Repo.Name)
		}
	case "DeleteEvent":
		switch gj.Payload.Ref_Type {
		case "branch":
			skipped = format("%s del branch %s %s", gj.Actor.Login, gj.Payload.Ref, gj.Repo.Name)
		default:
			skipped = format("-> %s %s %s", gj.Type, gj.Actor.Login, gj.Repo.Name)
		}
	case "ReleaseEvent":
		switch gj.Payload.Action {
		case "published":
			skipped = format("%s published %s %s", gj.Actor.Login, gj.Payload.Release.Tag_Name, gj.Repo.Name)
		default:
			skipped = format("-> %s %s %s", gj.Type, gj.Actor.Login, gj.Repo.Name)
		}
	case "CommitCommentEvent":
		skipped = format("%s commit comment %s", gj.Actor.Login, gj.Repo.Name)
	case "GollumEvent":
		switch gj.Payload.Pages.Action {
		case "edited":
			skipped = format("%s wiki edit %s", gj.Actor.Login, gj.Repo.Name)
		}
	default:
		for _, event := range skipEvents {
			if event == gj.Type {
				return true // we skipped this event
			}
		}
		skipped = format("-> %s %s %s", gj.Type, gj.Actor.Login, gj.Repo.Name)
	}

	return skipped
}