50 Commits

Author SHA1 Message Date
Alfonso Sánchez-Beato
56f64edaf7 many: add options to the logger to be able to enable internally debug traces 2024-05-10 19:20:03 +02:00
Miguel Pires
29c9752d66 many: s/ioutil.WriteFile/os.WriteFile (#13217)
Replace ioutil.WriteFile with os.WriteFile since the former has been
deprecated since go1.16 and simply calls the latter.

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2023-09-26 11:38:46 +01:00
Valentin David
d9e4ab8c5e osutil/kcmdline: simplify names 2023-07-31 16:40:56 +02:00
Valentin David
c9bbf25300 osutil: extract kcmdline to its own package 2023-07-31 16:40:56 +02:00
Alfonso Sánchez-Beato
9926506020 logger: add BootSetup logger
BootSetup is expected to be called from program running from
initramfs, and it looks at the kernel command line to check if
something should be printed or not.
2023-03-29 08:18:51 +01:00
Miguel Pires
ee783cc46c client: test SNAPD_CLIENT_DEBUG_HTTP env var
Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2023-01-04 18:40:08 +01:00
Miguel Pires
0728dfef27 logger: allow logging HTTP traffic enabling all logs
When using SNAPD_DEBUG_HTTP, it was also necessary to set SNAPD_DEBUG
for the HTTP traffic to be logged. So it was impossible to log the HTTP
traffic without logging everything. This commit changes that so that
setting the former logs the HTTP traffic and setting SNAPD_DEBUG
enables the debug logs in the rest of snapd.

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2022-12-13 21:30:23 +01:00
Maciej Borzecki
57c31581c2 logger: add a helper to log timestamps during snap startup
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2022-05-23 14:01:23 +02:00
Sreeja Manghat
9bf5d2485a many: unit test fix when SNAPD_DEBUG=1 is set
Minor changes ensuring unset SNAPD_DEBG to avoid test failures when run with SNAPD_DEBUG=1.
Added support in test.yaml for unit tests with SNAPD_DEBUG=1 to be re-run to avoid regressions.
2022-01-25 20:26:56 +05:30
Ian Johnson
2e2b3aaf7f osutil: add KernelCommandLineKeyValue; boot: refactor ModeAnd...FromKernelCommandLine (#9659)
* boot/cmdline.go: add TODO about using strutil.KernelCommandLineSplit

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>

* strutil/cmdline.go: add GetKernelCommandLineKeyValue

This complements KernelCommandLineSplit, but goes further, checking for a
specific key-value pair in the kernel command line parameters, and returning the
value if found. This will be useful across the codebase for places where we want
to check one specific kernel command line parameter key-value pair.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>

* logger/logger.go: use GetKernelCommandLineKeyValue directly

This is a bit more straight forward to read IMHO and potentially reduces some
looping over the parameters as we break as soon as we find snapd.debug in the
positive case where it is set.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>

* strutil,osutil: move kernel commandline helpers to osutil

* boot: tweak TODO now that we use osutil.KernelCommandLineSplit

* many: refactor ModeAnd...FromKernelCommandLine and KernelCommandLineKeyValue

Refactor GetKernelCommandLineKeyValue to KernelCommandLineKeyValue which
returns a map of the specified keys that were found on the kernel command line
that have values. It also no longer takes the command line string as an
argument and instead parses the command line itself.

The above necessitates moving the mocking function for where to find
/proc/cmdline to osutil as well and adjusting many tests for this.

Finally, with all of this in place we can refactor
boot.ModeAndRecoverySystemFromKernelCommandLine to use the osutil helpers
and not duplicate parsing logic in the boot package. This does result in
a slight change in behavior where now duplicated kernel command line
parameters are not a fatal condition, but instead the last definition is
used.

Also adjust some tests to mock an empty proc/cmdline to avoid using the
host's version when running tests.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>

* osutil, many: rename to KernelCommandLineKeyValues

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>

* boot: disallow non empty system label without a mode

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>

* osutil: tweak handling of cmdline keys

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>

* osutil: mv cmdline to kcmdline

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>

* osutil: comment tweak

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>

* logger: further tweaks

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>

Co-authored-by: Michael Vogt <mvo@ubuntu.com>
Co-authored-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2020-11-19 15:35:31 +01:00
Michael Vogt
9c3d817e42 logger: use strutil.KernelCommandLineSplit in debugEnabledOnKernelCmdline
This is a followup from PR#9486 which adds a precise kernel commandline
parsing.
2020-10-12 17:30:31 +02:00
Claudio Matsuoka
99f6790591 logger: fix snapd.debug=1 parsing
We were previously splitting the kernel cmdline fields using strictly
a space character as separator. If snapd.debug=1 is at the end of
the cmdline it also gets a trailing newline and the parameter was
ignored.

Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
2020-10-09 16:30:02 -03:00
Michael Vogt
a0786608b3 logger: make "type Log" use pointer recievers
This works around the unit test failure in go 1.9 which is the
result of: https://github.com/golang/go/issues/16723

See also https://github.com/golang/go/issues/16723 for details.
Once go1.9 is no longer supported we can drop this commit.
2020-08-25 08:37:18 +02:00
Michael Vogt
5392cf7aa9 logger: add TODO (thanks to Samuele) 2020-08-24 17:54:25 +02:00
Michael Vogt
10d02d3a81 logger: add support for setting snapd.debug=1 on kernel cmdline
While debugging a failure during UC20 seeding I noticed it is
hard to get debug data from snapd. I booted the system with:
```
dangerous systemd.debug-shell=1
```
but the
```
journalctl -u snapd
```
output did not contain that much information because debug
was not enabled. So this commit allows to enable debug via
the kernel commandline to allow easier seeding debugging.
2020-08-14 13:38:01 +02:00
James Henstridge
16c3680b78 logger, usersession: add WithLoggerLock helper suggested by @pedronis 2019-09-03 10:16:43 +08:00
John R. Lenton
93a00aea1e logger: try to not have double dates
Before this change, logger was inconditionally adding a timestamp to
our logs. Then systemd picks them up and adds a timestamp. This
results in silly logs like

    Jul 19 16:40:30 fleet snapd[8498]: 2018/07/19 16:40:30.298179 retry.go:52: DEBUG: <blah blah blah>

With this change we take advantage of the fact that systemd services
run with a very limited environment, and check for TERM being set: if
not set, we disable logging the timestamp ourselves. That way you can
still run snapd by hand to debug things and get timestamps, but let
systemd do it itself otherwise.
2018-07-19 16:59:43 +01:00
Michael Vogt
ee9452fe75 many: add logger.MockLogger() and use it in the tests (#3911)
We have two noisy tests in the unittest runs right now. Messages
get logged to stdout which really should not be visible. With the use
of the new logger.MockLogger() those are now no longer visible.

I also tweaked the existing pattern of:

    var logbuf bytes.Buffer
    l, err := logger.New(&logbuf, logger.DefaultFlags)
    c.Assert(err, IsNil)
    logger.SetLogger(l)

to just use:

    logbuf, restore := logger.MockLogger()
    defer restore()
2017-09-13 19:14:28 +02:00
John R. Lenton
8243b0c6b0 logger (& many more, to accommodate): drop explicit syslog.
logger.ConsoleLog printed to standard output and to syslog, an idea
which has proven to be at least partly misguided: snapd's logs would
typically be duplicated as systemd logs the output already. snap only
rarely logged anything relevant to syslog. Aditionally, syslog was
always written to (even for DEBUG), which has been deemed a misfeature.

This drops logger.ConsoleLog and introudces logger.Log (constructor
goes from logger.NewConsoleLog to logger.New); the new type has no
connection with syslog.
2017-05-22 19:06:00 +01:00
John R. Lenton
a606cf68b5 review feedback 2016-11-23 21:51:02 +00:00
John R. Lenton
5241ccb8bb many: unify boolean env var handling 2016-11-23 21:51:02 +00:00
John R. Lenton
6d4cd7a2e2 s/can('t| not)/cannot/ 2016-09-10 15:50:03 +01:00
Gustavo Niemeyer
2dbc8a4c35 Code moved to github.com/snapcore/snapd. 2016-05-24 09:26:23 -03:00
Michael Vogt
b091db00cb allow console logging via SNAPD_DEBUG 2016-04-14 16:06:04 +02:00
Michael Vogt
a0f49a5512 fix tests 2016-04-14 15:47:58 +02:00