diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-09-15 17:50:43 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-09-15 17:50:43 -0400 |
| commit | 8b512adbbcf62f49b3e92410e643c86f2e70908a (patch) | |
| tree | b3f5e08c6589bc7c00e2a089fbe5304cb60d742a /examples/log.tm | |
| parent | 3d1a102a8d8425b8f4a08b78c77ee4b38f6de55b (diff) | |
Move each example to its own folder
Diffstat (limited to 'examples/log.tm')
| -rw-r--r-- | examples/log.tm | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/examples/log.tm b/examples/log.tm deleted file mode 100644 index 42df072c..00000000 --- a/examples/log.tm +++ /dev/null @@ -1,50 +0,0 @@ -use <time.h> -use <stdio.h> - -timestamp_format := CString("%F %T") - -logfiles := {:Path} - -func _timestamp()->Text: - c_str := inline C:CString { - char *str = GC_MALLOC_ATOMIC(20); - time_t t; time(&t); - struct tm *tm_info = localtime(&t); - strftime(str, 20, "%F %T", tm_info); - str - } - return c_str:as_text() - -func info(text:Text, newline=yes): - say("$\[2]⚫ $text$\[]", newline) - for file in logfiles: - file:append("$(_timestamp()) [info] $text$\n") - -func debug(text:Text, newline=yes): - say("$\[32]🟢 $text$\[]", newline) - for file in logfiles: - file:append("$(_timestamp()) [debug] $text$\n") - -func warn(text:Text, newline=yes): - say("$\[33;1]🟡 $text$\[]", newline) - for file in logfiles: - file:append("$(_timestamp()) [warn] $text$\n") - -func error(text:Text, newline=yes): - say("$\[31;1]🔴 $text$\[]", newline) - for file in logfiles: - file:append("$(_timestamp()) [error] $text$\n") - -func add_logfile(file:Path): - logfiles:add(file) - -func remove_logfile(file:Path): - logfiles:remove(file) - -func main(): - add_logfile((./log.txt)) - >> info("Hello") - >> debug("Hello") - >> warn("Hello") - >> error("Hello") - |
