Remove unneeded semicolons from the core library

This commit is contained in:
gingerBill
2021-08-31 22:21:13 +01:00
parent b176af2742
commit 251da264ed
187 changed files with 27227 additions and 27227 deletions
+58 -58
View File
@@ -1,9 +1,9 @@
package log
import "core:fmt";
import "core:strings";
import "core:os";
import "core:time";
import "core:fmt"
import "core:strings"
import "core:os"
import "core:time"
Level_Headers := [?]string{
0..<10 = "[DEBUG] --- ",
@@ -11,7 +11,7 @@ Level_Headers := [?]string{
20..<30 = "[WARN ] --- ",
30..<40 = "[ERROR] --- ",
40..<50 = "[FATAL] --- ",
};
}
Default_Console_Logger_Opts :: Options{
.Level,
@@ -19,14 +19,14 @@ Default_Console_Logger_Opts :: Options{
.Short_File_Path,
.Line,
.Procedure,
} | Full_Timestamp_Opts;
} | Full_Timestamp_Opts
Default_File_Logger_Opts :: Options{
.Level,
.Short_File_Path,
.Line,
.Procedure,
} | Full_Timestamp_Opts;
} | Full_Timestamp_Opts
File_Console_Logger_Data :: struct {
@@ -35,128 +35,128 @@ File_Console_Logger_Data :: struct {
}
create_file_logger :: proc(h: os.Handle, lowest := Level.Debug, opt := Default_File_Logger_Opts, ident := "") -> Logger {
data := new(File_Console_Logger_Data);
data.file_handle = h;
data.ident = ident;
return Logger{file_console_logger_proc, data, lowest, opt};
data := new(File_Console_Logger_Data)
data.file_handle = h
data.ident = ident
return Logger{file_console_logger_proc, data, lowest, opt}
}
destroy_file_logger :: proc(log: ^Logger) {
data := cast(^File_Console_Logger_Data)log.data;
data := cast(^File_Console_Logger_Data)log.data
if data.file_handle != os.INVALID_HANDLE {
os.close(data.file_handle);
os.close(data.file_handle)
}
free(data);
free(data)
}
create_console_logger :: proc(lowest := Level.Debug, opt := Default_Console_Logger_Opts, ident := "") -> Logger {
data := new(File_Console_Logger_Data);
data.file_handle = os.INVALID_HANDLE;
data.ident = ident;
return Logger{file_console_logger_proc, data, lowest, opt};
data := new(File_Console_Logger_Data)
data.file_handle = os.INVALID_HANDLE
data.ident = ident
return Logger{file_console_logger_proc, data, lowest, opt}
}
destroy_console_logger :: proc(log: ^Logger) {
free(log.data);
free(log.data)
}
file_console_logger_proc :: proc(logger_data: rawptr, level: Level, text: string, options: Options, location := #caller_location) {
data := cast(^File_Console_Logger_Data)logger_data;
h: os.Handle = os.stdout if level <= Level.Error else os.stderr;
data := cast(^File_Console_Logger_Data)logger_data
h: os.Handle = os.stdout if level <= Level.Error else os.stderr
if data.file_handle != os.INVALID_HANDLE {
h = data.file_handle;
h = data.file_handle
}
backing: [1024]byte; //NOTE(Hoej): 1024 might be too much for a header backing, unless somebody has really long paths.
buf := strings.builder_from_slice(backing[:]);
backing: [1024]byte //NOTE(Hoej): 1024 might be too much for a header backing, unless somebody has really long paths.
buf := strings.builder_from_slice(backing[:])
do_level_header(options, level, &buf);
do_level_header(options, level, &buf)
when time.IS_SUPPORTED {
if Full_Timestamp_Opts & options != nil {
fmt.sbprint(&buf, "[");
t := time.now();
y, m, d := time.date(t);
h, min, s := time.clock(t);
fmt.sbprint(&buf, "[")
t := time.now()
y, m, d := time.date(t)
h, min, s := time.clock(t)
if .Date in options { fmt.sbprintf(&buf, "%d-%02d-%02d ", y, m, d); }
if .Time in options { fmt.sbprintf(&buf, "%02d:%02d:%02d", h, min, s); }
fmt.sbprint(&buf, "] ");
fmt.sbprint(&buf, "] ")
}
}
do_location_header(options, &buf, location);
do_location_header(options, &buf, location)
if .Thread_Id in options {
// NOTE(Oskar): not using context.thread_id here since that could be
// incorrect when replacing context for a thread.
fmt.sbprintf(&buf, "[{}] ", os.current_thread_id());
fmt.sbprintf(&buf, "[{}] ", os.current_thread_id())
}
if data.ident != "" {
fmt.sbprintf(&buf, "[%s] ", data.ident);
fmt.sbprintf(&buf, "[%s] ", data.ident)
}
//TODO(Hoej): When we have better atomics and such, make this thread-safe
fmt.fprintf(h, "%s %s\n", strings.to_string(buf), text);
fmt.fprintf(h, "%s %s\n", strings.to_string(buf), text)
}
do_level_header :: proc(opts: Options, level: Level, str: ^strings.Builder) {
RESET :: "\x1b[0m";
RED :: "\x1b[31m";
YELLOW :: "\x1b[33m";
DARK_GREY :: "\x1b[90m";
RESET :: "\x1b[0m"
RED :: "\x1b[31m"
YELLOW :: "\x1b[33m"
DARK_GREY :: "\x1b[90m"
col := RESET;
col := RESET
switch level {
case .Debug: col = DARK_GREY;
case .Info: col = RESET;
case .Warning: col = YELLOW;
case .Error, .Fatal: col = RED;
case .Debug: col = DARK_GREY
case .Info: col = RESET
case .Warning: col = YELLOW
case .Error, .Fatal: col = RED
}
if .Level in opts {
if .Terminal_Color in opts {
fmt.sbprint(str, col);
fmt.sbprint(str, col)
}
fmt.sbprint(str, Level_Headers[level]);
fmt.sbprint(str, Level_Headers[level])
if .Terminal_Color in opts {
fmt.sbprint(str, RESET);
fmt.sbprint(str, RESET)
}
}
}
do_location_header :: proc(opts: Options, buf: ^strings.Builder, location := #caller_location) {
if Location_Header_Opts & opts == nil {
return;
return
}
fmt.sbprint(buf, "[");
fmt.sbprint(buf, "[")
file := location.file_path;
file := location.file_path
if .Short_File_Path in opts {
last := 0;
last := 0
for r, i in location.file_path {
if r == '/' {
last = i+1;
last = i+1
}
}
file = location.file_path[last:];
file = location.file_path[last:]
}
if Location_File_Opts & opts != nil {
fmt.sbprint(buf, file);
fmt.sbprint(buf, file)
}
if .Line in opts {
if Location_File_Opts & opts != nil {
fmt.sbprint(buf, ":");
fmt.sbprint(buf, ":")
}
fmt.sbprint(buf, location.line);
fmt.sbprint(buf, location.line)
}
if .Procedure in opts {
if (Location_File_Opts | {.Line}) & opts != nil {
fmt.sbprint(buf, ":");
fmt.sbprint(buf, ":")
}
fmt.sbprintf(buf, "%s()", location.procedure);
fmt.sbprintf(buf, "%s()", location.procedure)
}
fmt.sbprint(buf, "] ");
fmt.sbprint(buf, "] ")
}
+33 -33
View File
@@ -6,7 +6,7 @@ import "core:fmt"
// NOTE(bill, 2019-12-31): These are defined in `package runtime` as they are used in the `context`. This is to prevent an import definition cycle.
Level :: runtime.Logger_Level;
Level :: runtime.Logger_Level
/*
Logger_Level :: enum {
Debug = 0,
@@ -17,7 +17,7 @@ Logger_Level :: enum {
}
*/
Option :: runtime.Logger_Option;
Option :: runtime.Logger_Option
/*
Option :: enum {
Level,
@@ -31,7 +31,7 @@ Option :: enum {
}
*/
Options :: runtime.Logger_Options;
Options :: runtime.Logger_Options
/*
Options :: bit_set[Option];
*/
@@ -39,25 +39,25 @@ Options :: bit_set[Option];
Full_Timestamp_Opts :: Options{
.Date,
.Time,
};
}
Location_Header_Opts :: Options{
.Short_File_Path,
.Long_File_Path,
.Line,
.Procedure,
};
}
Location_File_Opts :: Options{
.Short_File_Path,
.Long_File_Path,
};
}
Logger_Proc :: runtime.Logger_Proc;
Logger_Proc :: runtime.Logger_Proc
/*
Logger_Proc :: #type proc(data: rawptr, level: Level, text: string, options: Options, location := #caller_location);
*/
Logger :: runtime.Logger;
Logger :: runtime.Logger
/*
Logger :: struct {
procedure: Logger_Proc,
@@ -72,74 +72,74 @@ nil_logger_proc :: proc(data: rawptr, level: Level, text: string, options: Optio
}
nil_logger :: proc() -> Logger {
return Logger{nil_logger_proc, nil, Level.Debug, nil};
return Logger{nil_logger_proc, nil, Level.Debug, nil}
}
// TODO(bill): Should these be redesigned so that they are do not rely upon `package fmt`?
debugf :: proc(fmt_str: string, args: ..any, location := #caller_location) {
logf(level=.Debug, fmt_str=fmt_str, args=args, location=location);
logf(level=.Debug, fmt_str=fmt_str, args=args, location=location)
}
infof :: proc(fmt_str: string, args: ..any, location := #caller_location) {
logf(level=.Info, fmt_str=fmt_str, args=args, location=location);
logf(level=.Info, fmt_str=fmt_str, args=args, location=location)
}
warnf :: proc(fmt_str: string, args: ..any, location := #caller_location) {
logf(level=.Warning, fmt_str=fmt_str, args=args, location=location);
logf(level=.Warning, fmt_str=fmt_str, args=args, location=location)
}
errorf :: proc(fmt_str: string, args: ..any, location := #caller_location) {
logf(level=.Error, fmt_str=fmt_str, args=args, location=location);
logf(level=.Error, fmt_str=fmt_str, args=args, location=location)
}
fatalf :: proc(fmt_str: string, args: ..any, location := #caller_location) {
logf(level=.Fatal, fmt_str=fmt_str, args=args, location=location);
logf(level=.Fatal, fmt_str=fmt_str, args=args, location=location)
}
debug :: proc(args: ..any, sep := " ", location := #caller_location) {
log(level=.Debug, args=args, sep=sep, location=location);
log(level=.Debug, args=args, sep=sep, location=location)
}
info :: proc(args: ..any, sep := " ", location := #caller_location) {
log(level=.Info, args=args, sep=sep, location=location);
log(level=.Info, args=args, sep=sep, location=location)
}
warn :: proc(args: ..any, sep := " ", location := #caller_location) {
log(level=.Warning, args=args, sep=sep, location=location);
log(level=.Warning, args=args, sep=sep, location=location)
}
error :: proc(args: ..any, sep := " ", location := #caller_location) {
log(level=.Error, args=args, sep=sep, location=location);
log(level=.Error, args=args, sep=sep, location=location)
}
fatal :: proc(args: ..any, sep := " ", location := #caller_location) {
log(level=.Fatal, args=args, sep=sep, location=location);
log(level=.Fatal, args=args, sep=sep, location=location)
}
panic :: proc(args: ..any, location := #caller_location) -> ! {
log(level=.Fatal, args=args, location=location);
runtime.panic("log.panic", location);
log(level=.Fatal, args=args, location=location)
runtime.panic("log.panic", location)
}
panicf :: proc(fmt_str: string, args: ..any, location := #caller_location) -> ! {
logf(level=.Fatal, fmt_str=fmt_str, args=args, location=location);
runtime.panic("log.panicf", location);
logf(level=.Fatal, fmt_str=fmt_str, args=args, location=location)
runtime.panic("log.panicf", location)
}
log :: proc(level: Level, args: ..any, sep := " ", location := #caller_location) {
logger := context.logger;
logger := context.logger
if logger.procedure == nil {
return;
return
}
if level < logger.lowest_level {
return;
return
}
str := fmt.tprint(args=args, sep=sep); //NOTE(Hoej): While tprint isn't thread-safe, no logging is.
logger.procedure(logger.data, level, str, logger.options, location);
str := fmt.tprint(args=args, sep=sep) //NOTE(Hoej): While tprint isn't thread-safe, no logging is.
logger.procedure(logger.data, level, str, logger.options, location)
}
logf :: proc(level: Level, fmt_str: string, args: ..any, location := #caller_location) {
logger := context.logger;
logger := context.logger
if logger.procedure == nil {
return;
return
}
if level < logger.lowest_level {
return;
return
}
str := fmt.tprintf(fmt_str, ..args);
logger.procedure(logger.data, level, str, logger.options, location);
str := fmt.tprintf(fmt_str, ..args)
logger.procedure(logger.data, level, str, logger.options, location)
}
+9 -9
View File
@@ -6,24 +6,24 @@ Multi_Logger_Data :: struct {
}
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, Level.Debug, nil};
data := new(Multi_Logger_Data)
data.loggers = make([]Logger, len(logs))
copy(data.loggers, logs)
return Logger{multi_logger_proc, data, Level.Debug, nil}
}
destroy_multi_logger :: proc(log : ^Logger) {
free(log.data);
log^ = nil_logger();
free(log.data)
log^ = nil_logger()
}
multi_logger_proc :: proc(logger_data: rawptr, level: Level, text: string,
options: Options, location := #caller_location) {
data := cast(^Multi_Logger_Data)logger_data;
data := cast(^Multi_Logger_Data)logger_data
for log in data.loggers {
if level < log.lowest_level {
return;
return
}
log.procedure(log.data, level, text, log.options, location);
log.procedure(log.data, level, text, log.options, location)
}
}