aboutsummaryrefslogtreecommitdiff
path: root/lib/mlog
AgeCommit message (Collapse)Author
2026-01-15all: convert license and copyright to use SPDX identifiersShulhan
With help of spdxconv tool [1], we able to bulk update all files license and copyright format to comply with SPDX formats. [1] https://kilabit.info/project/spdxconv/
2025-01-23all: use for-range with numericShulhan
Go 1.22 now support for-range on numeric value.
2025-01-23all: replace "interface{}" with "any"Shulhan
2025-01-22lib/bytes: replace Copy and Concat with standard libraryShulhan
Since Go 1.20, the standard bytes package have the Copy function. Since Go 1.22, the standard slices package have the Concat function.
2024-03-05all: comply with linter recommendations #2Shulhan
HTTP request now implicitly create request with context. Any false positive related to not closing HTTP response body has been annotated with "nolint:bodyclose". In the example code, use consistent "// Output:" comment format, by prefixing with single space. Any comment on code now also prefixing with single space. An error returned without variables now use [errors.New] instead of [fmt.Errorf]. Any error returned using [fmt.Errorf] now wrapped using "%w" instead of "%s". Also, replace error checking using [errors.Is] or [errors.As], instead of using equal/not-equal operator. Any statement like "x = x OP y" now replaced with "x OP= y". Also, swap statement is simplified using "x, y = y, x". Any switch statement with single case now replaced with if-condition. Any call to defer on function or program that call [os.Exit], now replaced by calling the deferred function directly. Any if-else condition now replaced with switch statement, if possible.
2024-03-02all: move the repository to "git.sr.ht/~shulhan/pakakeh.go"Shulhan
There are several reasons that why we move from github.com. First, related to the name of package. We accidentally name the package with "share" a common word in English that does not reflect the content of repository. By moving to other repository, we can rename it to better and unique name, in this "pakakeh.go". Pakakeh is Minang word for tools, and ".go" suffix indicate that the repository related to Go programming language. Second, supporting open source. The new repository is hosted under sourcehut.org, the founder is known to support open source, and all their services are licensed under AGPL, unlike GitHub that are closed sources. Third, regarding GitHub CoPilot. The GitHub Terms of Service [1], allow any public content that are hosted there granted them to parse the content. On one side, GitHub helps and flourish the open source, but on another side have an issues regarding scraping the copyleft license [2]. [1]: https://docs.github.com/en/site-policy/github-terms/github-terms-of-service#4-license-grant-to-us [2]: https://githubcopilotinvestigation.com
2023-12-13all: fix linter warnings reported by reviveShulhan
There are some reports that I disagree with revive, in example, code should not declare the type after variables. In my opinion, on some cases, declaring the type make the code more readable and explicit. Since I did not want to add new configuration file, we changes it and follow revive for now.
2023-09-11lib/mlog: update the example for MultiLogger using different package nameShulhan
Previously, the example use package name mlog which cause import cycle. To fix this, we rename the package to mlog_test.
2022-08-03lib/mlog: simplify for-select channel consumers with for-rangeShulhan
2022-06-27lib/mlog: minimize allocation when generating logShulhan
Instead of using two bytes.Buffer pool, use one; and add space after time and prefix by writing to buffer directly instead of allocating new arguments to Fprintf. Benchmark result, name old time/op new time/op delta MultiLogger-8 3.97µs ± 3% 3.68µs ± 2% -7.43% (p=0.008 n=5+5) name old alloc/op new alloc/op delta MultiLogger-8 510B ± 1% 300B ± 1% -41.13% (p=0.008 n=5+5) name old allocs/op new allocs/op delta MultiLogger-8 10.4 ± 6% 3.4 ±18% -67.31% (p=0.008 n=5+5)
2022-06-27lib/mlog: simplify flushing by using single channelShulhan
Instead of using different channel to handle flush, send command with specific string "__flush__".
2022-06-27lib/mlog: minimize checking for new lineShulhan
Since Outf and Errf must end with new line move checking and adding new line to writeTo, before its being processed.
2022-06-27lib/mlog: add method Close to MultiLoggerShulhan
The Close method flush and close all log forwarders. Any write to a closed MultiLogger will be ignored. This changes require adding sync.Mutex to mark if the instance has been closed or not; which affect createMultiLogger and defaultMLog to return a pointer to prevent copy on Mutex.
2022-06-26lib/mlog: clean up the codeShulhan
Replace assignment from using ":=" to use variable declaration with type, rename the example file without prefix.
2022-05-09all: reformat all codes using gofmt 1.19 (the Go tip)Shulhan
2022-03-27lib/http: use package mlog for loggingShulhan
In case the consumer of lib/http package use mlog for logging, the log will be written to their predefined writers. In case they did not use mlog, the log will written to stdout and stderr.
2022-02-17lib/mlog: make the Outf method always add new line at the endShulhan
One of common mistakes when using logging library is to put the new line "\n" at then of format string, which cause delayed output written to Stdout (the OS wait for "\n" as signal for printing). This changes check new line to every call of Outf method and add it if its not exist. If the caller need to call Outf multiple times before ending it with new line, they should handle it manually by storing into temporary buffer first and call Outf at the end.
2022-02-17lib/mlog: change default mlog instance to non-pointerShulhan
Since the default mlog instance is a global variable, using non-pointer give advantages on minimize GC pressure.
2022-02-17lib/mlog: realign the struct MultiLoggerShulhan
This changes make the MultiLogger struct to consume memory from 104 to 88 bytes (-16 bytes).
2021-08-25lib/mlog: implement io.Writer and add function ErrorWriterShulhan
The ErrorWriter will return the internal default MultiLogger. A call to Write() on returned io.Writer will forward it to all registered error writers. A Write method on MultiLogger write the b to all error writers. It will always return the length of b without an error.
2021-08-06lib/mlog: add function and method PanicfShulhan
The Panicf method is equal to Errf followed by panic. This signature follow the log.Panicf convention.
2021-05-04mlog: add function and method PrintStackShulhan
The PrintStack function or method will writes to error writers the stack trace returned by debug.Stack.
2021-05-04mlog: remove comment about adding new lineShulhan
In commit 25b6e78dd we add new line to error message, so this comment does not applicable anymore.
2021-03-03mlog: change default time layout in the prefixShulhan
Previously, we use RFC3339 for time layout. This format use 'T' for separator between date and time. This commit changes the time layout to "YYYY-MM-DD HH:mm:ss MST" for readability.
2021-02-23mlog: append new line character on Errf if its not end with itShulhan
This is to fix the error message not displayed directly when calling Errf without new line.
2021-02-12mlog: implement MultiLoggerShulhan
MultiLogger represent a single log writer that write to multiple outputs. MultiLogger can have zero or more writers for standard output (normal log) and zero or more writers for standard error. The MultiLogger is buffered to minimize waiting time when writing to multiple writers that have different latencies. For example, if we have one writer to os.Stdout, one writer to file, and one writer to network; the writer to network may take more time to finish than to os.Stdout and file, which may slowing down the program if we want to wait for all writes to finish. For this reason, do not forget to call Flush when your program exit. The default MultiLogger use time.RFC3339 as the default time layout, empty prefix, os.Stdout for the output writer, and os.Stderr for the error writer. Format of written log, [time] [prefix] <message> The time and prefix only printed if its not empty, and the single space is added for convenience. Unlike standard log package, this package does not add new line to the end of message if its not exist.