Commit Graph

184 Commits

Author SHA1 Message Date
Philip Withnall
f7825f98e7 gmessages: Drop one of the documentation sections
It was short, unhelpful, and easy to confuse with the longer and more
informative documentation sections.

https://bugzilla.gnome.org/show_bug.cgi?id=769785
2016-08-12 11:54:45 +02:00
Philip Withnall
371078b6a3 gmessages: Expand documentation on log domains and G_MESSAGES_DEBUG
Give some example log domains, and recommend that G_MESSAGES_DEBUG is
used universally as the way to enable debug output (rather than having a
separate environment variable per library).

https://bugzilla.gnome.org/show_bug.cgi?id=682794
2016-08-07 08:10:31 +01:00
Philip Withnall
0e132b8ac5 gmessages: Document g_test_expect_message() doesn’t like structured logs
It’s effectively deprecated if G_LOG_USE_STRUCTURED is defined, or if
the structured logging API is used directly. See the documentation for
rationale.

https://bugzilla.gnome.org/show_bug.cgi?id=769486
2016-08-07 08:07:42 +01:00
Philip Withnall
4e66036b82 Revert "Make g_test_expect_message work for structured logs"
This reverts commit df02e8f47c.

We are going to make g_test_expect_message() only work for the old
logging API.

https://bugzilla.gnome.org/show_bug.cgi?id=769486
2016-08-07 08:07:42 +01:00
Philip Withnall
5c3205f2fb gmessages: Don’t require is_journald() call before writer_journald()
g_log_writer_is_journald() works out whether the process’ stderr or
stdout are redirected to journald. While the default writer function
uses this in conjunction with g_log_writer_journald(), that does not
always have to be the case — other writer functions might want to always
write to the journal, and never write to stderr (for example).

Consequently, automatically open the journal socket in
writer_journald(), rather than is_journald().

https://bugzilla.gnome.org/show_bug.cgi?id=769507
2016-08-04 14:33:34 +01:00
Matthias Clasen
df02e8f47c Make g_test_expect_message work for structured logs
This is used in GTK+ tests, and GTK+ has switched to
G_LOG_USE_STRUCTURED, so we need this to keep working.
2016-08-02 23:16:04 -04:00
Chun-wei Fan
6d6b97aa59 gmessages.c: Fix build on non-Linux
journald is a part of systemd which is Linux-only at this time, so only
compile the journald items on Linux only, and just return FALSE for
g_log_writer_is_journald() and G_LOG_WRITER_UNHANDLED for
g_log_writer_journald() on non-Linux.

https://bugzilla.gnome.org/show_bug.cgi?id=744456
2016-07-27 10:45:00 +08:00
Matthias Clasen
496c52ec79 Avoid htole64 altogether
GLib ships its own api for this, lets use it.
2016-07-25 12:31:52 -04:00
Matthias Clasen
ad285d9bd2 Handle EINTR when sending logs to the journal
Ray pointed out that we might well get interrupted here,
and should not loose logs due to that.
2016-07-25 10:25:40 -04:00
Matthias Clasen
34cb9c7de1 Explicitly include endian.h
htole64 is defined here.

https://bugzilla.gnome.org/show_bug.cgi?id=769139
2016-07-25 10:15:08 -04:00
Matthias Clasen
a2d5d1f119 Use SOCK_CLOEXEC if available
Ray pointed out that we can avoid the race here.
2016-07-25 09:47:26 -04:00
Matthias Clasen
6a07885a98 Drop libsystemd dependency
Talk to the journal ourselves using sendmsg() instead of linking
against libsystemd for sd_journal_sendv(). At the same time, we
can also avoid excessive copying.

The motivation for dropping the dependency is that we can
then use structured logging e.g. in a flatpak sandbox where
libsystemd may not be present in the runtime.

The code here is inspired by similar code in libvirt.
2016-07-22 23:04:51 -04:00
Matthias Clasen
e7ee56dd1d Make g_log_set_writer_func work more than once
It is fine to document that you shall only call this once,
but for tests, it is important that we can call it multiple
times.
2016-07-22 15:12:42 -04:00
Ray Strode
f414cddc1f gmessages: support NULL log domain
It's possible that a project may not define the G_LOG_DOMAIN but
still use g_log functions.  In such cases, we now crash.

This commit fixes that.

https://bugzilla.gnome.org/show_bug.cgi?id=769087
2016-07-22 11:33:14 -04:00
Matthias Clasen
f38845c116 Expand g_log_structured docs a bit
Mention two possible pitfalls that were pointed out by Ray Strode.
2016-07-21 14:52:46 -04:00
Víctor Manuel Jáquez Leal
d311177948 gmessage: Suppress string format literal warning
https://bugzilla.gnome.org/show_bug.cgi?id=769029
2016-07-21 07:12:46 -04:00
Matthias Clasen
849599671c Update structured logging docs a bit
Remove references to removed macros, add some more links
to standard journal fields.
2016-07-20 20:42:09 -04:00
Matthias Clasen
f5a8dfb6af Improve journal detection
We can use getpeername() and check if we have a socket that
is in /run/systemd/journal/.
2016-07-20 20:42:09 -04:00
Matthias Clasen
bdcf9e8b4e Redo structured logging API
It turns out that the current approach of parsing g_log_structured
varargs is unworkable, because vprintf is not guaranteed to advance
the passed-in va_list. So, we have to reshuffle the argument list
a bit; I've come up with this approach:

g_log_structured (domain, level,
                  key-value pairs...
                  "MESSAGE", format,
                  printf arguments);

This requires a "MESSAGE" key to always be present, and it requires
the "MESSAGE"-format pair to be last, but it avoids an extra NULL
as marker after the key-value pairs. And it can be parsed with a
single pass over the va_list, without any va_copy.

Since we have G_LOG_USE_STRUCTURED, the separate ...structured()
convenience macros are pretty pointless, and I have dropped them
for now.
2016-07-20 20:42:09 -04:00
Matthias Clasen
fec01b630a Use g_log_structured_array in g_logv
We already formatted the message; there is no need to
go through the printf machinery a second time.
2016-07-20 20:42:09 -04:00
Chun-wei Fan
c08b1a6ae5 glib/gmessages.c: Use G_VA_COPY() instead of va_copy()
Some compilers may not support va_copy(), so use the G_VA_COPY macro so
that things can be supported properly on all supported compilers.
2016-07-18 14:25:52 +08:00
Philip Withnall
12acd90d8a gmessages: Document namespacing recommendation for structured log fields
We recommend that all custom log fields are namespaced to avoid
collisions.

https://bugzilla.gnome.org/show_bug.cgi?id=744456
2016-07-17 17:10:41 +01:00
Matthias Clasen
75084c990f gmessages: Suppress journald code locations
This only leads to the location of our sd_journal_sendv call
being embedded into every log message coming from the old
API.
2016-07-17 01:47:32 -04:00
Philip Withnall
fce7cfaf40 gmessages: Rebase g_log() on g_log_structured()
Replace the underlying write_string() call which is the ultimate result
of calling g_log() with a call to g_log_structured(). This means that
all g_log() calls will pass through the structured log handling code
path, as long as they are not already modified or dropped by the g_log()
code (fatal masks, aborts, etc.).

In the case that the default structured log writer is in use, this will
result in the same format of log output to stdout or stderr, as
previously happened. If a non-default writer is in use, it handles the
message as it sees fit.

https://bugzilla.gnome.org/show_bug.cgi?id=744456
2016-07-16 23:52:18 -04:00
Philip Withnall
37ef301684 gmessages: Add colour output support to structured log messages
If outputting to a terminal which supports coloured output (rather than,
for example, redirecting to a file). This is only enabled for structured
log messages, where colour output support can be tested. It is not
enabled for non-structured log messages.

https://bugzilla.gnome.org/show_bug.cgi?id=744456
2016-07-16 23:52:18 -04:00
Philip Withnall
052eaf24f7 gmessages: Add a structured logging API
In parallel with g_log(), add a new structured logging API, based around
g_log_structured() and various helper functions which are exposed
publicly to allow programs to build their own logging policies easily,
without having to rewrite a lot of gmessages.c because it’s all
internal.

See the expanded documentation at the top of gmessages.c for some
rationale. See the g_log_structured() documentation for some example
code.

https://bugzilla.gnome.org/show_bug.cgi?id=744456
2016-07-16 23:52:18 -04:00
Philip Withnall
ae9e72ef61 gmessages: Simplify _g_log_abort() in gmessages.c a little
https://bugzilla.gnome.org/show_bug.cgi?id=744456
2016-06-29 17:18:55 +01:00
Руслан Ижбулатов
e47904a26f Use g_abort() instead of abort() where possible
https://bugzilla.gnome.org/show_bug.cgi?id=665446
2016-04-27 13:17:28 +00:00
Philip Withnall
d8a7d5f168 gmessages: Clarify documentation for G_LOG_LEVEL_CRITICAL
Clarify that it’s a critical //warning//, not a critical something-else.
2016-03-15 12:30:01 +00:00
Philip Withnall
25a7c817d3 glib: Add missing (nullable) and (optional) annotations
Add various (nullable) and (optional) annotations which were missing
from a variety of functions. Also port a couple of existing (allow-none)
annotations in the same files to use (nullable) and (optional) as
appropriate instead.

Secondly, add various (not nullable) annotations as needed by the new
default in gobject-introspection of marking gpointers as (nullable). See
https://bugzilla.gnome.org/show_bug.cgi?id=729660.

This includes adding some stub documentation comments for the
assertion macro error functions, which weren’t previously documented.
The new comments are purely to allow for annotations, and hence are
marked as (skip) to prevent the symbols appearing in the GIR file.

https://bugzilla.gnome.org/show_bug.cgi?id=719966
2015-11-07 10:48:32 +01:00
Ignacio Casal Quinteiro
fb9df27776 Change message system to use fputs instead of write
By default g_log_default_handler always assumes that stdout
and stderr are file descriptors 1 and 2. On Win32 this isn't
always the case as the win32 API functions AttachConsole and
freopen can be used to dynamically attach GUI applications to
a console and the file descriptors of stderr and stdout will
become different than 1 and 2.

Fix it by using fputs with the FILE directly instead of
using the file descriptors.

https://bugzilla.gnome.org/show_bug.cgi?id=692085
2015-10-08 17:32:29 +02:00
Philip Withnall
5a642651c7 gmessages: Mention g_return_if_fail() in g_warning() and g_error() docs
It seems to be common for people to use g_warning() or g_error() as pre-
and post-condition error reporting functions, which is not really what
they’re intended for. Similarly, it is generally a sign of bad API
design to use g_warning() to report errors — use GError instead.

Try and suggest this to the user in the hope that nice code results.

https://bugzilla.gnome.org/show_bug.cgi?id=741779
2015-08-19 12:56:38 +01:00
Rico Tzschichholz
1f0a11c59a g_log_set_handler_full: Bump "Since" version accordingly 2015-06-11 07:52:40 +02:00
Matthias Clasen
2471d9cf86 Add g_log_set_handler_full
This is a bindable version of g_log_set_handler that takes
a destroy notify for the user_data.

https://bugzilla.gnome.org/show_bug.cgi?id=740516
2015-06-10 22:03:19 -04:00
Philip Withnall
6ac2e8c79a gmessages: Tweak docs for G_LOG_DOMAIN to use AM_CPPFLAGS
Instead of INCLUDES, which is deprecated in automake. Using AM_CPPFLAGS
also gives the hint that the -D argument should be a CPPFLAGS variable,
rather than CFLAGS.
2015-05-13 15:22:57 +01:00
Dan Winship
be0b921115 Fix up failure-to-see-expected-message logging
When GLib had been told to expect message X, but then actually saw
message Y, it would log the "did not see expected message" error with
message Y's log level and domain, which makes no sense. Change it to
log with domain "GLib" and G_LOG_LEVEL_CRITICAL instead.

Also, include the expected domain in the error message, so that if
that's the reason why the expectation didn't match, you can tell that
from the error message.

Update glib/tests/testing.c for these changes; for all other test
programs in GLib and elsewhere, this change should not break any
existing tests, it should only improve the output on failure.

https://bugzilla.gnome.org/show_bug.cgi?id=727974
2014-07-09 10:48:34 -04:00
Patrick Welche
ab9f63fadd gmessages: make g_assert_warning compiler friendly
https://bugzilla.gnome.org/show_bug.cgi?id=720708
2014-06-28 13:17:16 -04:00
Ryan Lortie
dce88768dc all: remove use of 'register' keyword
We should have done this a decade ago...

https://bugzilla.gnome.org/show_bug.cgi?id=730293
2014-06-28 13:07:52 -04:00
Matthias Clasen
ab18d71e6f Minor documentation additions and corrections
Going for 100%.
2014-05-31 10:54:02 -04:00
Matthias Clasen
bc6ee788b4 docs: let go of *
Since we are no longer using sgml mode, using /* */ to
escape block comments inside examples does not work anymore.
Switch to using line comments with //
2014-02-14 21:33:36 -05:00
Matthias Clasen
e7fd3de86d Eradicate links and xrefs
These are all replaced by markdown ref links.
2014-02-08 12:26:56 -05:00
Matthias Clasen
cb588d4532 Convert external links to markdown syntax 2014-02-05 21:23:28 -05:00
Matthias Clasen
111803030d Don't use <envar> in docs
Switch to simpler markdown, `foo`.
2014-02-05 19:32:41 -05:00
Matthias Clasen
acdd7015fb Avoid a gtk-doc warning 2014-02-01 20:49:21 -05:00
Matthias Clasen
adf892e96a Annotate all examples with their language
The C ones, at least.
2014-02-01 15:11:49 -05:00
Matthias Clasen
77c4ff80dc docs: Stop using the function tag 2014-02-01 12:19:04 -05:00
Matthias Clasen
f7a6046998 gmessages: Convert docs to markdown
In particular, convert lists to markdown syntax.
2014-02-01 10:22:44 -05:00
Matthias Clasen
17f51583a8 Docs: Convert examples to |[ ]| 2014-01-31 21:56:33 -05:00
Matthias Clasen
4d12e0d66f Docs: Don't use the emphasis tag
Most of the time, the text read just as well without the extra
boldness.
2014-01-31 20:34:33 -05:00
Daniel Mustieles
078dbda148 Updated FSF's address 2014-01-31 14:31:55 +01:00