Last active
June 15, 2016 02:43
-
-
Save TheAngryByrd/fefd9369fc5a218df2999f23f6328a42 to your computer and use it in GitHub Desktop.
Logary Console Colors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Helpers = | |
| let (|StartsWith|_|) s (v : string) = | |
| if v.StartsWith s then Some () | |
| else None | |
| open Helpers | |
| type ConsoleColorWriter(consoleTextWriter : IO.TextWriter, colorMap) = | |
| inherit IO.TextWriter() | |
| override this.Encoding = System.Text.Encoding.Default | |
| override this.WriteLine(value : string) = | |
| Console.ForegroundColor <- | |
| match value with | |
| | StartsWith "F" -> LogLevel.Fatal | |
| | StartsWith "E" -> LogLevel.Error | |
| | StartsWith "W" -> LogLevel.Warn | |
| | StartsWith "I" -> LogLevel.Info | |
| | StartsWith "D" -> LogLevel.Debug | |
| | StartsWith "V" -> LogLevel.Verbose | |
| | _ -> LogLevel.Verbose | |
| |> colorMap | |
| consoleTextWriter.WriteLine(value) | |
| Console.ResetColor() | |
| let colormap level = | |
| match level with | |
| | LogLevel.Fatal -> ConsoleColor.DarkRed | |
| | LogLevel.Error -> ConsoleColor.Red | |
| | LogLevel.Warn -> ConsoleColor.Yellow | |
| | _ -> ConsoleColor.White | |
| let consoleConfig = Console.empty | |
| let consoleConf = | |
| TextWriter.create | |
| { formatter = consoleConfig.formatter | |
| output = new ConsoleColorWriter( System.Console.Out, colormap) | |
| error = new ConsoleColorWriter( System.Console.Error, colormap) | |
| flush = false | |
| isErrorAt = Error } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment