3 people like it.
Like the snippet!
Logging
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
|
module Logging
open System
/// Log levels.
let Error = 0
let Warning = 1
let Information = 2
let Debug = 3
let LevelToString level =
match level with
| 0 -> "Error"
| 1 -> "Warning"
| 2 -> "Information"
| 3 -> "Debug"
| _ -> "Unknown"
/// The current log level.
let mutable current_log_level = Debug
/// The inteface loggers need to implement.
type ILogger = abstract Log : int -> Printf.StringFormat<'a,unit> -> 'a
/// Writes to console.
let ConsoleLogger = {
new ILogger with
member __.Log level format =
Printf.kprintf (printfn "[%s][%A] %s" (LevelToString level) System.DateTime.Now) format
}
/// Defines which logger to use.
let mutable DefaultLogger = ConsoleLogger
/// Logs a message with the specified logger.
let logUsing (logger: ILogger) = logger.Log
/// Logs a message using the default logger.
let log level message = logUsing DefaultLogger level message
|
module Logging
namespace System
val Error : int
Full name: Logging.Error
Log levels.
val Warning : int
Full name: Logging.Warning
val Information : int
Full name: Logging.Information
val Debug : int
Full name: Logging.Debug
val LevelToString : level:int -> string
Full name: Logging.LevelToString
val level : int
val mutable current_log_level : int
Full name: Logging.current_log_level
The current log level.
type ILogger =
interface
abstract member Log : int -> StringFormat<'a,unit> -> 'a
end
Full name: Logging.ILogger
The inteface loggers need to implement.
abstract member ILogger.Log : int -> Printf.StringFormat<'a,unit> -> 'a
Full name: Logging.ILogger.Log
Multiple items
val int : value:'T -> int (requires member op_Explicit)
Full name: Microsoft.FSharp.Core.Operators.int
--------------------
type int = int32
Full name: Microsoft.FSharp.Core.int
--------------------
type int<'Measure> = int
Full name: Microsoft.FSharp.Core.int<_>
module Printf
from Microsoft.FSharp.Core
type StringFormat<'T,'Result> = Format<'T,unit,string,'Result>
Full name: Microsoft.FSharp.Core.PrintfModule.StringFormat<_,_>
type unit = Unit
Full name: Microsoft.FSharp.Core.unit
val ConsoleLogger : ILogger
Full name: Logging.ConsoleLogger
Writes to console.
val format : Printf.StringFormat<'a,unit>
val kprintf : continutation:(string -> 'Result) -> format:Printf.StringFormat<'T,'Result> -> 'T
Full name: Microsoft.FSharp.Core.Printf.kprintf
val printfn : format:Printf.TextWriterFormat<'T> -> 'T
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
Multiple items
type DateTime =
struct
new : ticks:int64 -> DateTime + 10 overloads
member Add : value:TimeSpan -> DateTime
member AddDays : value:float -> DateTime
member AddHours : value:float -> DateTime
member AddMilliseconds : value:float -> DateTime
member AddMinutes : value:float -> DateTime
member AddMonths : months:int -> DateTime
member AddSeconds : value:float -> DateTime
member AddTicks : value:int64 -> DateTime
member AddYears : value:int -> DateTime
...
end
Full name: System.DateTime
--------------------
DateTime()
(+0 other overloads)
DateTime(ticks: int64) : unit
(+0 other overloads)
DateTime(ticks: int64, kind: DateTimeKind) : unit
(+0 other overloads)
DateTime(year: int, month: int, day: int) : unit
(+0 other overloads)
DateTime(year: int, month: int, day: int, calendar: Globalization.Calendar) : unit
(+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int) : unit
(+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, kind: DateTimeKind) : unit
(+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, calendar: Globalization.Calendar) : unit
(+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, millisecond: int) : unit
(+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, millisecond: int, kind: DateTimeKind) : unit
(+0 other overloads)
property DateTime.Now: DateTime
val mutable DefaultLogger : ILogger
Full name: Logging.DefaultLogger
Defines which logger to use.
val logUsing : logger:ILogger -> (int -> Printf.StringFormat<'a,unit> -> 'a)
Full name: Logging.logUsing
Logs a message with the specified logger.
val logger : ILogger
abstract member ILogger.Log : int -> Printf.StringFormat<'a,unit> -> 'a
val log : level:int -> message:Printf.StringFormat<'a,unit> -> 'a
Full name: Logging.log
Logs a message using the default logger.
val message : Printf.StringFormat<'a,unit>
More information