Merge lp://qastaging/~elopio/snapcraft/fix1476452-python_log into lp://qastaging/~snappy-dev/snapcraft/core

Proposed by Leo Arias
Status: Merged
Approved by: Michael Terry
Approved revision: 112
Merged at revision: 110
Proposed branch: lp://qastaging/~elopio/snapcraft/fix1476452-python_log
Merge into: lp://qastaging/~snappy-dev/snapcraft/core
Prerequisite: lp://qastaging/~elopio/snapcraft/test_tmp_cwd
Diff against target: 669 lines (+176/-69)
14 files modified
integration-tests/units/jobs.pxu (+4/-4)
snapcraft/__init__.py (+14/-5)
snapcraft/cmds.py (+9/-5)
snapcraft/common.py (+0/-5)
snapcraft/main.py (+8/-0)
snapcraft/plugin.py (+8/-4)
snapcraft/plugins/ant_project.py (+7/-2)
snapcraft/plugins/copy.py (+5/-1)
snapcraft/plugins/ubuntu.py (+10/-4)
snapcraft/tests/test_cmds.py (+45/-8)
snapcraft/tests/test_copy_plugin.py (+15/-8)
snapcraft/tests/test_plugin.py (+17/-4)
snapcraft/tests/test_yaml.py (+23/-14)
snapcraft/yaml.py (+11/-5)
To merge this branch: bzr merge lp://qastaging/~elopio/snapcraft/fix1476452-python_log
Reviewer Review Type Date Requested Status
Michael Terry (community) Approve
Michael Vogt (community) Approve
Review via email: mp+265354@code.qastaging.launchpad.net

Commit message

Use the python logger.

Description of the change

The python logger is nice. I've just done the basic config to keep the previous behaviour, but there are many options. At some point we should add an extra handler to send the logs to a file.

By using this logger, now it becomes testable too. I've added some tests, but to add the rest I need to learn a little more about snapcraft.

To post a comment you must log in.
Revision history for this message
Michael Vogt (mvo) wrote :

Thanks for this branch. I like it and code-wise it looks great, just two comments inline (which are the same) where a small comment might be helpful. I +1 on this branch but I will leave the top-approve to Mike.

review: Approve
Revision history for this message
Michael Terry (mterry) wrote :

A) This has conflicts now

B) Does this keep the bold text output? I thought that was rather valuable for separating the non-bold output of plugin subprocesses from the bold output of snapcraft itself (bracketing plugin output when going through the stages).

I'd prefer to keep that if possible.

review: Needs Information
Revision history for this message
Leo Arias (elopio) wrote :

> A) This has conflicts now

and it requires sergio to add fixtures to the machine :(

> B) Does this keep the bold text output? I thought that was rather valuable
> for separating the non-bold output of plugin subprocesses from the bold output
> of snapcraft itself (bracketing plugin output when going through the stages).
>
> I'd prefer to keep that if possible.

No, it doesn't. I can do it with with separate handlers and filters, I think. Let me try.

Revision history for this message
Leo Arias (elopio) wrote :

> Thanks for this branch. I like it and code-wise it looks great, just two
> comments inline (which are the same) where a small comment might be helpful. I
> +1 on this branch but I will leave the top-approve to Mike.

Thanks for the review. I added comments on all the checks for the return code.

Revision history for this message
Leo Arias (elopio) wrote :

> A) This has conflicts now

Merged and all tests passing.

> B) Does this keep the bold text output? I thought that was rather valuable
> for separating the non-bold output of plugin subprocesses from the bold output
> of snapcraft itself (bracketing plugin output when going through the stages).
>
> I'd prefer to keep that if possible.

Now the logger format has the bold wrapper. Please check if that's what you wanted.

110. By Leo Arias

Merged with trunk.

Revision history for this message
Michael Terry (mterry) wrote :

From IRC:

<mterry> elopio, looking at your branch -- now some things are bold that weren't before
<mterry> elopio, look at the diff in LP and you can see some things were just print() lines before
 elopio, specifically when we ran a subcommand, it would not be bold
 elopio, and a couple tiny other places
 elopio, what's the cleanest way to distinguish there? Use another logger command than info?

Revision history for this message
Leo Arias (elopio) wrote :

> From IRC:
>
>
> <mterry> elopio, looking at your branch -- now some things are bold that
> weren't before
> <mterry> elopio, look at the diff in LP and you can see some things were just
> print() lines before
> elopio, specifically when we ran a subcommand, it would not be bold
> elopio, and a couple tiny other places
> elopio, what's the cleanest way to distinguish there? Use another logger
> command than info?l

No, I think the correct way is to define a different logger, like:
subcommand_logger = logging.getLogger(__name__ + '.subcommand')

And then we add a handler to that subcommand_logger that has a formatter without the bold wrapper.
However, if you see at the statements that use print:

66 - print(' '.join(cmd))

141 - snapcraft.common.log("Wrote the following as snapcraft.yaml.")
142 - print()
143 - print(yaml)

170 - print("Installing required packages on the host system: " + ", ".join(newPackages))

I fail to see a pattern in there that we can generalize in a logger. So maybe instead, each call to the logger should decide if it should be wrapped in bold or not. And IMO, instead of using \bold it would be clearer to use the name of the package. Like:

snapcraft log message-1
plugin.ubuntu: ubuntu log message-1
...
plugin.ubuntu: ubuntu log message-n
snapcraft log message-last

In the end, I think we should define a logging policy so we can be consistent on how to use it, and then define the logger hierarchy so it's easy to use. For now, I'll revert those lines to use print so this branch will introduce the loggers while keeping the exact same behaviour as before. And lets start the discussion.

111. By Leo Arias

Revert to prints for now to keep the exact same behaviour as before. Pending discussion of a hierarcy of loggers for different sources.

112. By Leo Arias

Updated the cmd test.

Revision history for this message
Michael Terry (mterry) wrote :

Looks good. We can go over the bold/not-bold stuff separately. I'm sure there's a nicer way to distinguish those.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches

to all changes: