abstractfactory/pyblish — pull request #103 by mottosso (2014-09-27 10:52:19+00:00)
Title: Logging 2.0

Hi all,

I've gone ahead and implemented thorough logging for the `pyblish.main.publish_all()`, which now also goes by the name of `pyblish.main.publish()` to align better with the CLI.

At the moment, whenever you publish, the following information is displayed.

1. Currently running version of Pyblish
2. Where, if one is used, user configuration is located
3. Currently available plug-in paths
4. Currently available plug-ins, along with which families each support
5. Currently running plug-in
6. Any log messages from within each plug-in, visually indented for clarity
7. File name, function/method name and line number of where any error occured
7. Summary of
1. How many instances were processed
2. How long processing took
3. If there were any non-critical errors, such as if an extractor fails.
8. Finally, and most importantly, a *reliable* *Finished Successfully*/*Failed*/*Success with errors* message at the very end.

### Example

More examples [here](https://github.com/abstractfactory/pyblish/wiki/logging)

```python
--------------------------------------------------------------------------------
pyblish version 1.0.6
--------------------------------------------------------------------------------

User Configuration @ None

Available plugin paths:
- C:\pythonpath\pyblish_maya\plugins
- C:\pythonpath\pyblish_napoleon\plugins
- C:\pythonpath\pyblish\plugins

Available plugins:
- ExtractAlembic demo.alembic
- ExtractModelAsMa demo.model
- ExtractModelAsMb demo.model
- ExtractModelAsObj demo.model
- NapoleonConformAsset napoleon.model, napoleon.rig.animation
- NapoleonExtractAnimationAsCurves napoleon.animation.curves
- NapoleonExtractAnimationAsPointcache napoleon.animation.pointcache
- NapoleonExtractAsMb napoleon.model, napoleon.rig.animation
- NapoleonSelectViaObjectSet
- SelectCurrentDate
- SelectCurrentFile
- SelectCurrentUser
- SelectCurrentWorkingDirectory
- SelectObjectSet
- SelectTransform
- SelectWorkspace
- ValidateMutedChannels demo.animation
- ValidateNamingConvention demo.model

--------------------------------------------------------------------------------
Processing

SelectWorkspace...
SelectCurrentFile...
SelectCurrentWorkingDirectory...
SelectObjectSet...
# INFO Adding instance: Napoleon
SelectTransform...
SelectCurrentDate...
SelectCurrentUser...
NapoleonSelectViaObjectSet...
# INFO Found: Napoleon
ValidateNamingConvention...
ValidateMutedChannels...
ExtractModelAsObj...
NapoleonExtractAnimationAsPointcache...
NapoleonExtractAsMb...
# DEBUG Processing instance: Napoleon
# INFO Extracting Napoleon locally..
# INFO Moving Napoleon relative working file..
# INFO No existing directory found, creating..
# INFO Clearing local cache..
# INFO Extraction successful.
ExtractModelAsMa...
ExtractAlembic...
ExtractModelAsMb...
NapoleonExtractAnimationAsCurves...
NapoleonConformAsset...
# DEBUG Processing instance: Napoleon
# INFO Conforming commit directory: C:\pyblish-napoleon\examples\napoleon\assets\Napoleon\model\private\marcus\maya\published\20140925_120822\napoleon.model\Napoleon
# INFO Parent asset: C:\pyblish-napoleon\examples\napoleon\assets\Napoleon\model
# INFO Conforming to: C:\pyblish-napoleon\examples\napoleon\assets\Napoleon\model\public\v009
# INFO Moving from C:\pyblish-napoleon\examples\napoleon\assets\Napoleon\model\private\marcus\maya\published\20140925_120822\napoleon.model\Napoleon to C:\pyblish-napoleon\examples\napoleon\assets\Napoleon\model\public\v009

--------------------------------------------------------------------------------
Time taken: 0.19s
Summary:
- "Napoleon" processed by: "NapoleonExtractAsMb", "NapoleonConformAsset"
Committed to: C:\pyblish-napoleon\examples\napoleon\assets\Napoleon\model\private\marcus\maya\published\20140925_120822\napoleon.model\Napoleon
Conformed to: C:\pyblish-napoleon\examples\napoleon\assets\Napoleon\model\public\v009

# pyblish.main : Processed 1 instances successfully #
```

### Reference for GUIs

Have a look at [`pyblish.main.publish()`][code] for reference when implementing these visualisations in GUIs. It illustrates how to get all of this information and how to pass paths and such to the discovery mechanism, how to use plug-ins independently and how to use and inspect errors occurring during processing. These are things what will most likely have to be done in a GUI as well.

In short, `pyblish.main.publish()` implements logging, whereas `pyblish.main._publish()` implements the execution of plug-ins; i.e. `publish()` is the interface whereas `_publish()` is its implementation.

[code]: https://github.com/mottosso/pyblish/blob/84ddc52759d9602198398ce89a6fe4d8722999e9/pyblish/main.py#L111