| Age | Commit message (Collapse) | Author |
|
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/
|
|
Go 1.22 now support for-range on numeric value.
|
|
|
|
Since Go 1.20, the standard bytes package have the Copy function.
Since Go 1.22, the standard slices package have the Concat function.
|
|
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.
|
|
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
|
|
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.
|
|
Previously, the example use package name mlog which cause import
cycle.
To fix this, we rename the package to mlog_test.
|
|
|
|
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)
|
|
Instead of using different channel to handle flush, send command
with specific string "__flush__".
|
|
Since Outf and Errf must end with new line move checking and
adding new line to writeTo, before its being processed.
|
|
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.
|
|
Replace assignment from using ":=" to use variable declaration with type,
rename the example file without prefix.
|
|
|
|
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.
|
|
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.
|
|
Since the default mlog instance is a global variable, using non-pointer
give advantages on minimize GC pressure.
|
|
This changes make the MultiLogger struct to consume memory from 104
to 88 bytes (-16 bytes).
|
|
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.
|
|
The Panicf method is equal to Errf followed by panic. This signature
follow the log.Panicf convention.
|
|
The PrintStack function or method will writes to error writers the stack
trace returned by debug.Stack.
|
|
In commit 25b6e78dd we add new line to error message, so this comment
does not applicable anymore.
|
|
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.
|
|
This is to fix the error message not displayed directly when calling
Errf without new line.
|
|
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.
|