Commit Graph

40 Commits

Author SHA1 Message Date
mlugg
0fe3fd01dd
std: update std.builtin.Type fields to follow naming conventions
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-28 08:39:59 +01:00
mlugg
6808ce27bd
compiler,lib,test,langref: migrate @setCold to @branchHint 2024-08-27 00:44:35 +01:00
Andrew Kelley
f97c2f28fd update the codebase for the new std.Progress API 2024-05-27 20:56:48 -07:00
Prokop Randacek
6fb23542fe Buffer the logging function
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-09 14:02:57 -08:00
Veikka Tuominen
220d3264c9 std: make options a struct instance instead of a namespace 2024-02-01 15:22:36 +02:00
Eric Joldasov
50339f595a all: zig fmt and rename "@XToY" to "@YFromX"
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-19 12:34:42 -07:00
Carl Åstholm
8d6336420b std.log.defaultLog: remove freestanding compile error 2023-05-03 11:19:37 +03:00
Veikka Tuominen
f83834993e std: collect all options under one namespace 2023-01-05 02:31:29 -07:00
Lee Cannon
93bdd04e88 std.log: add functionality to check if a specific log level and scope are enabled 2023-01-03 13:02:32 +02:00
Andrew Kelley
d3d24874c9 std: remove deprecated API for the upcoming release
See #3811
2022-09-16 14:46:53 -04:00
Hashi364
973b440561 Using comptime level.asText() in log example
Some recent change makes slice concatenation runtime (merge #12368), so the example needs to be explicitly made comptime.
2022-08-31 16:01:35 +03:00
r00ster91
13d58258a8 std.log: deduplicate switch 2022-07-09 15:19:03 +03:00
r00ster91
6f17be063d
std.log: give friendly error to freestanding users 2022-07-07 21:40:31 +03:00
Andrew Kelley
902df103c6 std lib API deprecations for the upcoming 0.9.0 release
See #3811
2021-11-30 00:13:07 -07:00
Andrew Kelley
008b0ec5e5 std.Thread.Mutex: change API to lock() and unlock()
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-11-09 18:31:03 -07:00
Isaac Freund
f7b090d707 std.log: simplify to 4 distinct log levels
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-24 15:04:29 -04:00
Andrew Kelley
6115cf2240 migrate from std.Target.current to @import("builtin").target
closes #9388
closes #9321
2021-10-04 23:48:55 -07:00
Andrew Kelley
d29871977f remove redundant license headers from zig standard library
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-08-24 12:25:09 -07:00
Jonathan Marler
cadf32d745 Expose mechanism to convert log level to text 2021-06-24 04:30:05 -06:00
Jonathan Marler
642f5df0ab Expose default std.log implementation
This allows root.log implementations to capture log messages, process them, and forward them to the default implementation if desired.
2021-06-24 04:11:28 -06:00
Luna
d1f99eabb7 add compile error if root.log is not a function 2021-06-22 16:38:18 +03:00
Lee Cannon
50822530d3
Provide method to set logging level per scope (#8584) 2021-06-09 12:23:45 +03:00
Andrew Kelley
5f35dc0c0d zig fmt the std lib 2021-02-24 21:29:23 -07:00
Frank Denis
6c2e0c2046 Year++ 2020-12-31 15:45:24 -08:00
Andrew Kelley
b6556c944b fix another round of regressions in this branch
* 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-26 21:03:38 -07:00
Andrew Kelley
495d18a205 std.log: better default for printing logs
* 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-25 00:02:52 -07:00
Andrew Kelley
209a3da4f7 provide default implementation of std.log on freestanding
closes #6252
2020-09-04 13:00:10 -07:00
Andrew Kelley
4a69b11e74 add license header to all std lib files
add SPDX license identifier
copyright ownership is zig contributors
2020-08-20 16:07:04 -04:00
heidezomp
2439f67061 std.log: update documentation and example for scoped logging 2020-08-13 17:12:16 +02:00
heidezomp
a8e0f667c6 std.log: (breaking) remove scope parameter from logging functions
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-13 16:50:38 +02:00
heidezomp
bf2ed0f571 std.log: don't state in docs that messages are logged to stderr
Since the logger implementation can be overridden, the messages might
not be logged to stderr at all.
2020-08-12 15:54:21 +02:00
heidezomp
25607079f0 std.log: add documentation for scoped logging
* 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-12 15:37:56 +02:00
heidezomp
7db2c11537 std.log: add scoped logging struct
* 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-08-12 14:03:02 +02:00
heidezomp
32a6759a7a Fix std.log example to make the log handler print the newline
Follow up from #5910
2020-07-22 22:08:08 +00:00
joachimschmidt557
c6bd8e8c53 Make the default log handler print a newline
Closes #5907
2020-07-22 17:02:27 +00:00
purringChaos
094223d634 Fix log.zig example. 2020-07-21 18:53:30 +03:00
Vexu
be1507a7af
update compile error tests and some doc comments 2020-07-12 00:54:07 +03:00
Vexu
e85fe13e44
run zig fmt on std lib and self hosted 2020-07-11 20:41:19 +03:00
Haze Booth
237c5429b0 Don't attempt to use io from thin air 2020-06-19 02:06:27 -04:00
Isaac Freund
0bd067d19a
Introduce std.log
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
2020-06-17 02:14:52 +02:00