|
@@ -11,30 +11,30 @@ Level :: enum {
|
|
}
|
|
}
|
|
|
|
|
|
Option :: enum {
|
|
Option :: enum {
|
|
- Level,
|
|
|
|
- Date,
|
|
|
|
- Time,
|
|
|
|
- Short_File_Path,
|
|
|
|
- Long_File_Path,
|
|
|
|
- Line,
|
|
|
|
- Procedure,
|
|
|
|
- Terminal_Color
|
|
|
|
|
|
+ Level,
|
|
|
|
+ Date,
|
|
|
|
+ Time,
|
|
|
|
+ Short_File_Path,
|
|
|
|
+ Long_File_Path,
|
|
|
|
+ Line,
|
|
|
|
+ Procedure,
|
|
|
|
+ Terminal_Color
|
|
}
|
|
}
|
|
|
|
|
|
Options :: bit_set[Option];
|
|
Options :: bit_set[Option];
|
|
Full_Timestamp_Opts :: Options{
|
|
Full_Timestamp_Opts :: Options{
|
|
- Option.Date,
|
|
|
|
- Option.Time
|
|
|
|
|
|
+ .Date,
|
|
|
|
+ .Time
|
|
};
|
|
};
|
|
Location_Header_Opts :: Options{
|
|
Location_Header_Opts :: Options{
|
|
- Option.Short_File_Path,
|
|
|
|
- Option.Long_File_Path,
|
|
|
|
- Option.Line,
|
|
|
|
- Option.Procedure,
|
|
|
|
|
|
+ .Short_File_Path,
|
|
|
|
+ .Long_File_Path,
|
|
|
|
+ .Line,
|
|
|
|
+ .Procedure,
|
|
};
|
|
};
|
|
Location_File_Opts :: Options{
|
|
Location_File_Opts :: Options{
|
|
- Option.Short_File_Path,
|
|
|
|
- Option.Long_File_Path
|
|
|
|
|
|
+ .Short_File_Path,
|
|
|
|
+ .Long_File_Path
|
|
};
|
|
};
|
|
|
|
|
|
Logger_Proc :: #type proc(data: rawptr, level: Level, text: string, options: Options, location := #caller_location);
|
|
Logger_Proc :: #type proc(data: rawptr, level: Level, text: string, options: Options, location := #caller_location);
|
|
@@ -42,30 +42,34 @@ Logger_Proc :: #type proc(data: rawptr, level: Level, text: string, options: Opt
|
|
Logger :: struct {
|
|
Logger :: struct {
|
|
procedure: Logger_Proc,
|
|
procedure: Logger_Proc,
|
|
data: rawptr,
|
|
data: rawptr,
|
|
- options: Options,
|
|
|
|
|
|
+ options: Options,
|
|
}
|
|
}
|
|
|
|
|
|
Multi_Logger_Data :: struct {
|
|
Multi_Logger_Data :: struct {
|
|
- loggers : []Logger,
|
|
|
|
|
|
+ loggers : []Logger,
|
|
}
|
|
}
|
|
|
|
|
|
create_multi_logger :: proc(logs: ..Logger) -> Logger {
|
|
create_multi_logger :: proc(logs: ..Logger) -> Logger {
|
|
- data := new(Multi_Logger_Data);
|
|
|
|
- data.loggers = make([]Logger, len(logs));
|
|
|
|
- copy(data.loggers, logs);
|
|
|
|
- return Logger{multi_logger_proc, data, nil};
|
|
|
|
|
|
+ data := new(Multi_Logger_Data);
|
|
|
|
+ data.loggers = make([]Logger, len(logs));
|
|
|
|
+ copy(data.loggers, logs);
|
|
|
|
+ return Logger{multi_logger_proc, data, nil};
|
|
}
|
|
}
|
|
|
|
|
|
-destroy_multi_logger ::proc(log : ^Logger) {
|
|
|
|
- free(log.data);
|
|
|
|
- log^ = nil_logger();
|
|
|
|
|
|
+destroy_multi_logger :: proc(log : ^Logger) {
|
|
|
|
+ free(log.data);
|
|
|
|
+ log^ = nil_logger();
|
|
}
|
|
}
|
|
|
|
|
|
multi_logger_proc :: proc(logger_data: rawptr, level: Level, text: string,
|
|
multi_logger_proc :: proc(logger_data: rawptr, level: Level, text: string,
|
|
options: Options, location := #caller_location) {
|
|
options: Options, location := #caller_location) {
|
|
- data := cast(^Multi_Logger_Data)logger_data;
|
|
|
|
- if data.loggers == nil || len(data.loggers) == 0 do return;
|
|
|
|
- for log in data.loggers do log.procedure(log.data, level, text, log.options, location);
|
|
|
|
|
|
+ data := cast(^Multi_Logger_Data)logger_data;
|
|
|
|
+ if data.loggers == nil || len(data.loggers) == 0 {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ for log in data.loggers {
|
|
|
|
+ log.procedure(log.data, level, text, log.options, location);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
nil_logger_proc :: proc(data: rawptr, level: Level, text: string, options: Options, location := #caller_location) {
|
|
nil_logger_proc :: proc(data: rawptr, level: Level, text: string, options: Options, location := #caller_location) {
|
|
@@ -76,6 +80,7 @@ nil_logger :: proc() -> Logger {
|
|
return Logger{nil_logger_proc, nil, nil};
|
|
return Logger{nil_logger_proc, nil, nil};
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// TODO(bill): Should these be redesigned so that they are do not rely upon `package fmt`?
|
|
debug :: proc(fmt_str : string, args : ..any, location := #caller_location) do logf(level=Level.Debug, fmt_str=fmt_str, args=args, location=location);
|
|
debug :: proc(fmt_str : string, args : ..any, location := #caller_location) do logf(level=Level.Debug, fmt_str=fmt_str, args=args, location=location);
|
|
info :: proc(fmt_str : string, args : ..any, location := #caller_location) do logf(level=Level.Info, fmt_str=fmt_str, args=args, location=location);
|
|
info :: proc(fmt_str : string, args : ..any, location := #caller_location) do logf(level=Level.Info, fmt_str=fmt_str, args=args, location=location);
|
|
warn :: proc(fmt_str : string, args : ..any, location := #caller_location) do logf(level=Level.Warning, fmt_str=fmt_str, args=args, location=location);
|
|
warn :: proc(fmt_str : string, args : ..any, location := #caller_location) do logf(level=Level.Warning, fmt_str=fmt_str, args=args, location=location);
|
|
@@ -83,7 +88,7 @@ error :: proc(fmt_str : string, args : ..any, location := #caller_location) do l
|
|
fatal :: proc(fmt_str : string, args : ..any, location := #caller_location) do logf(level=Level.Fatal, fmt_str=fmt_str, args=args, location=location);
|
|
fatal :: proc(fmt_str : string, args : ..any, location := #caller_location) do logf(level=Level.Fatal, fmt_str=fmt_str, args=args, location=location);
|
|
|
|
|
|
logf :: proc(level : Level, fmt_str : string, args : ..any, location := #caller_location) {
|
|
logf :: proc(level : Level, fmt_str : string, args : ..any, location := #caller_location) {
|
|
- logger := context.logger;
|
|
|
|
- str := len(args) > 0 ? fmt.tprintf(fmt_str, ..args) : fmt.tprint(fmt_str); //NOTE(Hoej): While tprint isn't thread-safe, no logging is.
|
|
|
|
- logger.procedure(logger.data, level, str, logger.options, location);
|
|
|
|
|
|
+ logger := context.logger;
|
|
|
|
+ str := len(args) > 0 ? fmt.tprintf(fmt_str, ..args) : fmt.tprint(fmt_str); //NOTE(Hoej): While tprint isn't thread-safe, no logging is.
|
|
|
|
+ logger.procedure(logger.data, level, str, logger.options, location);
|
|
}
|
|
}
|