hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 3dd574837fff80fe080d3d55016261f8f72cd689
parent 93e46ffcb8d471bf1eaa7b53b163f8220932e5b7
Author: Armin Preiml <apreiml@strohwolke.at>
Date:   Sat, 27 Aug 2022 19:38:49 +0200

log: add silent logger for turning off logs

Signed-off-by: Armin Preiml <apreiml@strohwolke.at>

Diffstat:
Alog/silent.ha | 13+++++++++++++
Mscripts/gen-stdlib | 4++--
Mstdlib.mk | 12++++++++----
3 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/log/silent.ha b/log/silent.ha @@ -0,0 +1,13 @@ +use fmt; + +// A logger that does not print any messages. +export let silent: *logger = &_silent; + +let _silent: logger = logger { + println = &silent_println, + printfln = &silent_printfln, +}; + +fn silent_println(l: *logger, fields: fmt::formattable...) void = return; +fn silent_printfln(l: *logger, fmt: str, fields: fmt::field...) void = return; + diff --git a/scripts/gen-stdlib b/scripts/gen-stdlib @@ -919,9 +919,9 @@ linux_vdso() { } log() { - gen_srcs -plinux log logger.ha global.ha funcs.ha + gen_srcs -plinux log logger.ha global.ha funcs.ha silent.ha gen_ssa -plinux log datetime fmt io os - gen_srcs -pfreebsd log logger.ha global.ha funcs.ha + gen_srcs -pfreebsd log logger.ha global.ha funcs.ha silent.ha gen_ssa -pfreebsd log datetime fmt io os } diff --git a/stdlib.mk b/stdlib.mk @@ -1517,7 +1517,8 @@ $(HARECACHE)/linux/vdso/linux_vdso-linux.ssa: $(stdlib_linux_vdso_linux_srcs) $( stdlib_log_linux_srcs = \ $(STDLIB)/log/logger.ha \ $(STDLIB)/log/global.ha \ - $(STDLIB)/log/funcs.ha + $(STDLIB)/log/funcs.ha \ + $(STDLIB)/log/silent.ha $(HARECACHE)/log/log-linux.ssa: $(stdlib_log_linux_srcs) $(stdlib_rt) $(stdlib_datetime_$(PLATFORM)) $(stdlib_fmt_$(PLATFORM)) $(stdlib_io_$(PLATFORM)) $(stdlib_os_$(PLATFORM)) @printf 'HAREC \t$@\n' @@ -1529,7 +1530,8 @@ $(HARECACHE)/log/log-linux.ssa: $(stdlib_log_linux_srcs) $(stdlib_rt) $(stdlib_d stdlib_log_freebsd_srcs = \ $(STDLIB)/log/logger.ha \ $(STDLIB)/log/global.ha \ - $(STDLIB)/log/funcs.ha + $(STDLIB)/log/funcs.ha \ + $(STDLIB)/log/silent.ha $(HARECACHE)/log/log-freebsd.ssa: $(stdlib_log_freebsd_srcs) $(stdlib_rt) $(stdlib_datetime_$(PLATFORM)) $(stdlib_fmt_$(PLATFORM)) $(stdlib_io_$(PLATFORM)) $(stdlib_os_$(PLATFORM)) @printf 'HAREC \t$@\n' @@ -3732,7 +3734,8 @@ $(TESTCACHE)/linux/vdso/linux_vdso-linux.ssa: $(testlib_linux_vdso_linux_srcs) $ testlib_log_linux_srcs = \ $(STDLIB)/log/logger.ha \ $(STDLIB)/log/global.ha \ - $(STDLIB)/log/funcs.ha + $(STDLIB)/log/funcs.ha \ + $(STDLIB)/log/silent.ha $(TESTCACHE)/log/log-linux.ssa: $(testlib_log_linux_srcs) $(testlib_rt) $(testlib_datetime_$(PLATFORM)) $(testlib_fmt_$(PLATFORM)) $(testlib_io_$(PLATFORM)) $(testlib_os_$(PLATFORM)) @printf 'HAREC \t$@\n' @@ -3744,7 +3747,8 @@ $(TESTCACHE)/log/log-linux.ssa: $(testlib_log_linux_srcs) $(testlib_rt) $(testli testlib_log_freebsd_srcs = \ $(STDLIB)/log/logger.ha \ $(STDLIB)/log/global.ha \ - $(STDLIB)/log/funcs.ha + $(STDLIB)/log/funcs.ha \ + $(STDLIB)/log/silent.ha $(TESTCACHE)/log/log-freebsd.ssa: $(testlib_log_freebsd_srcs) $(testlib_rt) $(testlib_datetime_$(PLATFORM)) $(testlib_fmt_$(PLATFORM)) $(testlib_io_$(PLATFORM)) $(testlib_os_$(PLATFORM)) @printf 'HAREC \t$@\n'