aboutsummaryrefslogtreecommitdiff
path: root/lib/std/log.zig
AgeCommit message (Collapse)Author
2025-10-30std.log: colorize output in default implementationMatthew Lugg
Also remove the example implementation from the file doc comment; it's better to just link to `defaultLog` as an example, since this avoids writing the example implementation twice and prevents the example from bitrotting.
2025-10-30std.debug.lockStderrWriter: also return ttyconfMatthew Lugg
`std.Io.tty.Config.detect` may be an expensive check (e.g. involving syscalls), and doing it every time we need to print isn't really necessary; under normal usage, we can compute the value once and cache it for the whole program's execution. Since anyone outputting to stderr may reasonably want this information (in fact they are very likely to), it makes sense to cache it and return it from `lockStderrWriter`. Call sites who do not need it will experience no significant overhead, and can just ignore the TTY config with a `const w, _` destructure.
2025-09-18Remove usages of deprecatedWriterandrewkraevskii
2025-07-10std.log.defaultLog: provide a small bufferAndrew Kelley
2025-07-10Merge pull request #24387 from ziglang/std.log.default_levelAndrew Kelley
std.log: adjust default level for ReleaseSmall to include info + bonus cleanup
2025-07-09std.log: adjust default level for ReleaseSmall to include infoAndrew Kelley
it was kind of wild to not do this before. sorry!
2025-07-07std.fmt: breaking API changesAndrew Kelley
added adapter to AnyWriter and GenericWriter to help bridge the gap between old and new API make std.testing.expectFmt work at compile-time std.fmt no longer has a dependency on std.unicode. Formatted printing was never properly unicode-aware. Now it no longer pretends to be. Breakage/deprecations: * std.fs.File.reader -> std.fs.File.deprecatedReader * std.fs.File.writer -> std.fs.File.deprecatedWriter * std.io.GenericReader -> std.io.Reader * std.io.GenericWriter -> std.io.Writer * std.io.AnyReader -> std.io.Reader * std.io.AnyWriter -> std.io.Writer * std.fmt.format -> std.fmt.deprecatedFormat * std.fmt.fmtSliceEscapeLower -> std.ascii.hexEscape * std.fmt.fmtSliceEscapeUpper -> std.ascii.hexEscape * std.fmt.fmtSliceHexLower -> {x} * std.fmt.fmtSliceHexUpper -> {X} * std.fmt.fmtIntSizeDec -> {B} * std.fmt.fmtIntSizeBin -> {Bi} * std.fmt.fmtDuration -> {D} * std.fmt.fmtDurationSigned -> {D} * {} -> {f} when there is a format method * format method signature - anytype -> *std.io.Writer - inferred error set -> error{WriteFailed} - options -> (deleted) * std.fmt.Formatted - now takes context type explicitly - no fmt string
2025-07-07std.io: move getStdIn, getStdOut, getStdErr functions to fs.FileAndrew Kelley
preparing to rearrange std.io namespace into an interface how to upgrade: std.io.getStdIn() -> std.fs.File.stdin() std.io.getStdOut() -> std.fs.File.stdout() std.io.getStdErr() -> std.fs.File.stderr()
2025-05-24std.log: fix exampleFelix Rabe
2024-08-28std: update `std.builtin.Type` fields to follow naming conventionsmlugg
The compiler actually doesn't need any functional changes for this: Sema does reification based on the tag indices of `std.builtin.Type` already! So, no zig1.wasm update is necessary. This change is necessary to disallow name clashes between fields and decls on a type, which is a prerequisite of #9938.
2024-08-27compiler,lib,test,langref: migrate `@setCold` to `@branchHint`mlugg
2024-05-27update the codebase for the new std.Progress APIAndrew Kelley
2024-02-09Buffer the logging functionProkop Randacek
The default logging function used to have no buffer. So a single log statement could result in many individual write syscalls each writing only a couple of bytes. After this change the logging function now has a 4kb buffer. Only log statements longer than 4kb now do multiple write syscalls. 4kb is the default bufferedWriter size and was choosen arbitrarily. The downside of this is that the log function now allocates 4kb more stack space but I think that is an acceptable trade-off.
2024-02-01std: make options a struct instance instead of a namespaceVeikka Tuominen
2023-06-19all: zig fmt and rename "@XToY" to "@YFromX"Eric Joldasov
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-05-03std.log.defaultLog: remove freestanding compile errorCarl Åstholm
2023-01-05std: collect all options under one namespaceVeikka Tuominen
2023-01-03std.log: add functionality to check if a specific log level and scope are ↵Lee Cannon
enabled
2022-09-16std: remove deprecated API for the upcoming releaseAndrew Kelley
See #3811
2022-08-31Using `comptime level.asText()` in log exampleHashi364
Some recent change makes slice concatenation runtime (merge #12368), so the example needs to be explicitly made comptime.
2022-07-09`std.log`: deduplicate `switch`r00ster91
2022-07-07std.log: give friendly error to freestanding usersr00ster91
2021-11-30std lib API deprecations for the upcoming 0.9.0 releaseAndrew Kelley
See #3811
2021-11-09std.Thread.Mutex: change API to lock() and unlock()Andrew Kelley
This is a breaking change. Before, usage looked like this: ```zig const held = mutex.acquire(); defer held.release(); ``` Now it looks like this: ```zig mutex.lock(); defer mutex.unlock(); ``` The `Held` type was an idea to make mutexes slightly safer by making it more difficult to forget to release an aquired lock. However, this ultimately caused more problems than it solved, when any data structures needed to store a held mutex. Simplify everything by reducing the API down to the primitives: lock() and unlock(). Closes #8051 Closes #8246 Closes #10105
2021-10-24std.log: simplify to 4 distinct log levelsIsaac Freund
Over the last year of using std.log in practice, it has become clear to me that having the current 8 distinct log levels does more harm than good. It is too subjective which level a given message should have which makes filtering based on log level weaker as not all messages will have been assigned the log level one might expect. Instead, more granular filtering should be achieved by leveraging the logging scope feature. Filtering based on a combination of scope and log level should be sufficiently powerful for all use-cases. Note that the self hosted compiler has already limited itself to 4 distinct log levels for many months and implemented granular filtering based on both log scope and level. This has worked very well in practice while working on the self hosted compiler.
2021-10-04migrate from `std.Target.current` to `@import("builtin").target`Andrew Kelley
closes #9388 closes #9321
2021-08-24remove redundant license headers from zig standard libraryAndrew Kelley
We already have a LICENSE file that covers the Zig Standard Library. We no longer need to remind everyone that the license is MIT in every single file. Previously this was introduced to clarify the situation for a fork of Zig that made Zig's LICENSE file harder to find, and replaced it with their own license that required annual payments to their company. However that fork now appears to be dead. So there is no need to reinforce the copyright notice in every single file.
2021-06-24Expose mechanism to convert log level to textJonathan Marler
2021-06-24Expose default std.log implementationJonathan Marler
This allows root.log implementations to capture log messages, process them, and forward them to the default implementation if desired.
2021-06-22add compile error if root.log is not a functionLuna
2021-06-09Provide method to set logging level per scope (#8584)Lee Cannon
2021-02-24zig fmt the std libAndrew Kelley
2020-12-31Year++Frank Denis
2020-09-26fix another round of regressions in this branchAndrew Kelley
* std.log: still print error messages in ReleaseSmall builds. - when start code gets an error code from main, it uses std.log.err to report the error. this resulted in a test failure because ReleaseSmall wasn't printing `error: TheErrorCode` when an error was returned from main. But that seems like it should keep working. So I changed the std.log defaults. I plan to follow this up with a proposal to change the names of and reduce the quantity of the log levels. * warning emitted when using -femit-h when using stage1 backend; fatal log message when using -femit-h with self-hosted backend (because the feature is not yet available) * fix double `test-cli` build steps in zig's build.zig * update docgen to use new CLI * translate-c uses `-x c` and generates a temporary basename with a `.h` extension. Otherwise clang reports an error. * --show-builtin implies -fno-emit-bin * restore the compile error for using an extern "c" function without putting -lc on the build line. we have to know about the libc dependency up front. * Fix ReleaseFast and ReleaseSmall getting swapped when passing the value to the stage1 backend. * correct the zig0 CLI usage text. * update test harness code to the new CLI.
2020-09-25std.log: better default for printing logsAndrew Kelley
* prefix with the message level * if the scope is not default, also prefix with the scope This makes the stack trace test pass, with no changes to the test case, because errors returned from main() now print `error: Foo` just like they do in master branch.
2020-09-04provide default implementation of std.log on freestandingAndrew Kelley
closes #6252
2020-08-20add license header to all std lib filesAndrew Kelley
add SPDX license identifier copyright ownership is zig contributors
2020-08-13std.log: update documentation and example for scoped loggingheidezomp
2020-08-13std.log: (breaking) remove scope parameter from logging functionsheidezomp
The logging functions in std.log don't take a scope parameter anymore, but use the .default scope. To provide your own scope, use the logging functions in std.log.scoped(.some_other_scope). As per nmichaels' suggestion: https://github.com/ziglang/zig/pull/6039#issuecomment-673148971
2020-08-12std.log: don't state in docs that messages are logged to stderrheidezomp
Since the logger implementation can be overridden, the messages might not be logged to stderr at all.
2020-08-12std.log: add documentation for scoped loggingheidezomp
* Add short documentation to std.log.scoped and std.log.default * Update the module documentation and example to explain the difference between using explicit scopes, using a scoped logging namespace, and using the default namespace
2020-08-12std.log: add scoped logging structheidezomp
* Add a std.log.scoped function that returns a scoped logging struct * Add a std.log.default struct that logs using the .default scope Implementation of daurnimator's proposal: https://github.com/ziglang/zig/issues/5943#issuecomment-669043489 Note that I named the function "scoped" instead of "scope" so as not to clash with the scope parameter that is used everywhere; this seemed a better solution to me than renaming the scope parameter to "s" or "log_scope" or the like.
2020-07-22Fix std.log example to make the log handler print the newlineheidezomp
Follow up from #5910
2020-07-22Make the default log handler print a newlinejoachimschmidt557
Closes #5907
2020-07-21Fix log.zig example.purringChaos
2020-07-12update compile error tests and some doc commentsVexu
2020-07-11run zig fmt on std lib and self hostedVexu
2020-06-19Don't attempt to use io from thin airHaze Booth
2020-06-17Introduce std.logIsaac Freund
std.log provides 8 log levels and corresponding logging functions. It allows the user to override the logging "backend" by defining root.log and to override the default log level by defining root.log_level. Logging functions accept a scope parameter which allows the implementer of the logging "backend" to filter logging by library as well as level. Using the standardized syslog [1] log levels ensures that std.log will be flexible enough to work for as many use-cases as possible. If we were to stick with only 3/4 log levels, std.log would be insufficient for large and/or complex projects such as a kernel or display server. [1]: https://tools.ietf.org/html/rfc5424#section-6.2.1