# `sc_crawler.logger`

> Logging and progress bar helpers.

# `sc_crawler.logger`

**Classes:**

- [**ScRichHandler**](#scrichhandler) – Extend RichHandler with function name logged in the right column.
- [**ProgressPanel**](#progresspanel) – Progress bars of the vendors and their inventory steps, with the metadata of the run.
- [**VendorProgressTracker**](#vendorprogresstracker) – Tracking the progress of the vendor's inventory updates.
- [**VoidProgressTracker**](#voidprogresstracker) – Progress tracker reference not doing antyhing.

**Functions:**

- [**log_start_end**](#log_start_end) – Log the start and end of the decorated function.

## func <code class="doc-name">log_start_end</code> [logger.py:31–62](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/logger.py#L31-L62)

```python
log_start_end(func)
```

Log the start and end of the decorated function.

## class <code class="doc-name">ScRichHandler</code> [logger.py:66–91](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/logger.py#L66-L91)

Bases: [`RichHandler`](https://rich.readthedocs.io/en/stable/reference/logging.html#rich.logging.RichHandler)

Extend RichHandler with function name logged in the right column.

## class <code class="doc-name">ProgressPanel</code> [logger.py:94–142](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/logger.py#L94-L142)

Progress bars of the vendors and their inventory steps, with the metadata of the run.

## class <code class="doc-name">VendorProgressTracker</code> [logger.py:149–303](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/logger.py#L149-L303)

Tracking the progress of the vendor's inventory updates.

**Functions:**

- [**start_vendor**](#vendorprogresstrackerstart_vendor) – Starts a progress bar for the Vendor's steps.
- [**advance_vendor**](#vendorprogresstrackeradvance_vendor) – Increment the number of finished steps.
- [**update_vendor**](#vendorprogresstrackerupdate_vendor) – Update the vendor's progress bar.
- [**start_task**](#vendorprogresstrackerstart_task) – Starts a progress bar in the list of current jobs.
- [**last_task**](#vendorprogresstrackerlast_task) – Returh the last registered TaskID.
- [**advance_task**](#vendorprogresstrackeradvance_task) – Increment the number of finished steps.
- [**update_task**](#vendorprogresstrackerupdate_task) – Update the task's progress bar.
- [**hide_task**](#vendorprogresstrackerhide_task) – Hide a task from the list of progress bars.
- [**fail_vendor**](#vendorprogresstrackerfail_vendor) – Clean up the progress bars of a vendor failed mid-way.

**Attributes:**

- [**vendor**](#vendorprogresstrackervendor) ([`Vendor`](https://docs.sparecores.com/crawler/reference/tables.md#vendor)) – A [sc_crawler.tables.Vendor](https://docs.sparecores.com/crawler/reference/tables.md#vendor) instance for which tracking progress.
- [**progress_panel**](#vendorprogresstrackerprogress_panel) ([`ProgressPanel`](#progresspanel)) – A `rich` panel including progress bars.
- [**vendors**](#vendorprogresstrackervendors) ([`Progress`](https://rich.readthedocs.io/en/stable/reference/progress.html#rich.progress.Progress)) – [rich.progress.Progress](https://rich.readthedocs.io/en/stable/reference/progress.html#rich.progress.Progress) for tracking the inventory steps of the vendor.
- [**tasks**](#vendorprogresstrackertasks) ([`Progress`](https://rich.readthedocs.io/en/stable/reference/progress.html#rich.progress.Progress)) – [rich.progress.Progress](https://rich.readthedocs.io/en/stable/reference/progress.html#rich.progress.Progress) for tracking the lower-level tasks within each step.
- [**metadata**](#vendorprogresstrackermetadata) ([`Text`](https://rich.readthedocs.io/en/stable/reference/text.html#rich.text.Text)) – [rich.text.Text](https://rich.readthedocs.io/en/stable/reference/text.html#rich.text.Text) metadata, e.g. data sources and records to be udpated.
- [**task_ids**](#vendorprogresstrackertask_ids) ([`List`](https://docs.python.org/3/library/typing.html#typing.List)`[TaskID]`) – List of active task ids for the current `vendor`.
- [**vendor_task_id**](#vendorprogresstrackervendor_task_id) ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)`[TaskID]`) – The `TaskID` of the vendor's progress bar, set by `start_vendor`.

### attr <code class="doc-parent">VendorProgressTracker.</code><code class="doc-name">vendor</code> [logger.py:172](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/logger.py#L172)

```python
vendor: Vendor = vendor
```

A [sc_crawler.tables.Vendor](https://docs.sparecores.com/crawler/reference/tables.md#vendor) instance for which tracking progress.

### attr <code class="doc-parent">VendorProgressTracker.</code><code class="doc-name">progress_panel</code> [logger.py:173](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/logger.py#L173)

```python
progress_panel: ProgressPanel = progress_panel
```

A `rich` panel including progress bars.
Should not be used directly, see the `vendors`, `tasks` and `metadata` attributes.

### attr <code class="doc-parent">VendorProgressTracker.</code><code class="doc-name">vendors</code> [logger.py:174](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/logger.py#L174)

```python
vendors: Progress = progress_panel.vendors
```

[rich.progress.Progress](https://rich.readthedocs.io/en/stable/reference/progress.html#rich.progress.Progress) for tracking the inventory steps of the vendor.

### attr <code class="doc-parent">VendorProgressTracker.</code><code class="doc-name">tasks</code> [logger.py:175](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/logger.py#L175)

```python
tasks: Progress = progress_panel.tasks
```

[rich.progress.Progress](https://rich.readthedocs.io/en/stable/reference/progress.html#rich.progress.Progress) for tracking the lower-level tasks within each step.

### attr <code class="doc-parent">VendorProgressTracker.</code><code class="doc-name">metadata</code> [logger.py:176](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/logger.py#L176)

```python
metadata: Text = progress_panel.metadata
```

[rich.text.Text](https://rich.readthedocs.io/en/stable/reference/text.html#rich.text.Text) metadata, e.g. data sources and records to be udpated.

### attr <code class="doc-parent">VendorProgressTracker.</code><code class="doc-name">task_ids</code> [logger.py:179](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/logger.py#L179)

```python
task_ids: List[TaskID] = []
```

List of active task ids for the current `vendor`.

### attr <code class="doc-parent">VendorProgressTracker.</code><code class="doc-name">vendor_task_id</code> [logger.py:180](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/logger.py#L180)

```python
vendor_task_id: Optional[TaskID] = None
```

The `TaskID` of the vendor's progress bar, set by `start_vendor`.

### meth <code class="doc-parent">VendorProgressTracker.</code><code class="doc-name">start_vendor</code> [logger.py:182–194](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/logger.py#L182-L194)

```python
start_vendor(total)
```

Starts a progress bar for the Vendor's steps.

**Parameters:**

- **total** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Overall number of steps to show in the progress bar.

**Returns:**

- **TaskId** (`TaskID`) – The progress bar's identifier to be referenced in future updates.

### meth <code class="doc-parent">VendorProgressTracker.</code><code class="doc-name">advance_vendor</code> [logger.py:201–207](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/logger.py#L201-L207)

```python
advance_vendor(advance=1)
```

Increment the number of finished steps.

**Parameters:**

- **advance** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Number of steps to advance.

### meth <code class="doc-parent">VendorProgressTracker.</code><code class="doc-name">update_vendor</code> [logger.py:209–215](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/logger.py#L209-L215)

```python
update_vendor(**kwargs)
```

Update the vendor's progress bar.

Useful fields:
- `step`: Name of the currently running step to be shown on the progress bar.

### meth <code class="doc-parent">VendorProgressTracker.</code><code class="doc-name">start_task</code> [logger.py:217–234](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/logger.py#L217-L234)

```python
start_task(name, total)
```

Starts a progress bar in the list of current jobs.

Besides returning the `TaskID`, it will also register in `self.tasks.task_ids`
as the last task, which will be the default value for future `advance_task`,
`hide_task` etc calls. The latter will remove the `TaskID` from the `task_ids`.

**Parameters:**

- **name** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Name to show in front of the progress bar. Will be prefixed by Vendor's name.
- **total** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Overall number of steps to show in the progress bar.

**Returns:**

- **TaskId** (`TaskID`) – The progress bar's identifier to be referenced in future updates.

### meth <code class="doc-parent">VendorProgressTracker.</code><code class="doc-name">last_task</code> [logger.py:236–238](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/logger.py#L236-L238)

```python
last_task()
```

Returh the last registered TaskID.

### meth <code class="doc-parent">VendorProgressTracker.</code><code class="doc-name">advance_task</code> [logger.py:240–251](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/logger.py#L240-L251)

```python
advance_task(task_id=None, advance=1)
```

Increment the number of finished steps.

**Parameters:**

- **task_id** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)`[TaskID]`) – The progress bar's identifier returned by `start_task`.
Defaults to the most recently created task.
- **advance** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Number of steps to advance.

### meth <code class="doc-parent">VendorProgressTracker.</code><code class="doc-name">update_task</code> [logger.py:253–267](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/logger.py#L253-L267)

```python
update_task(task_id=None, **kwargs)
```

Update the task's progress bar.

**Parameters:**

- **task_id** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)`[TaskID]`) – The progress bar's identifier returned by `start_task`.
Defaults to the most recently created task.

**Other Parameters:**

- **step** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Name of the currently running step to be shown on the progress bar.

See [`rich.progress.Progress.update`](https://rich.readthedocs.io/en/stable/reference/progress.html#rich.progress.Progress.update) for further keyword arguments.

### meth <code class="doc-parent">VendorProgressTracker.</code><code class="doc-name">hide_task</code> [logger.py:269–282](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/logger.py#L269-L282)

```python
hide_task(task_id=None)
```

Hide a task from the list of progress bars.

**Parameters:**

- **task_id** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)`[TaskID]`) – The progress bar's identifier returned by `start_task`.
Defaults to the most recently created task.

### meth <code class="doc-parent">VendorProgressTracker.</code><code class="doc-name">fail_vendor</code> [logger.py:284–303](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/logger.py#L284-L303)

```python
fail_vendor(step='✘')
```

Clean up the progress bars of a vendor failed mid-way.

Removes the progress bars of the vendor's interrupted steps from the
display (e.g. when an exception interrupted an inventory step before its
`hide_task` call), and stops the vendor's progress bar so its elapsed time
no longer increases while the next vendors are being processed. These are
display entries only, the interrupted work is not running anymore.

**Parameters:**

- **step** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Text to show as the current step on the vendor's progress bar.

## class <code class="doc-name">VoidProgressTracker</code> [logger.py:306–337](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/logger.py#L306-L337)

Bases: [`VendorProgressTracker`](#vendorprogresstracker)

Progress tracker reference not doing antyhing.

**Functions:**

- [**start_vendor**](#voidprogresstrackerstart_vendor) – Starts a progress bar for the Vendor's steps.
- [**advance_vendor**](#voidprogresstrackeradvance_vendor) – Increment the number of finished steps.
- [**update_vendor**](#voidprogresstrackerupdate_vendor) – Update the vendor's progress bar.
- [**start_task**](#voidprogresstrackerstart_task) – Starts a progress bar in the list of current jobs.
- [**last_task**](#voidprogresstrackerlast_task) – Returh the last registered TaskID.
- [**advance_task**](#voidprogresstrackeradvance_task) – Increment the number of finished steps.
- [**update_task**](#voidprogresstrackerupdate_task) – Update the task's progress bar.
- [**hide_task**](#voidprogresstrackerhide_task) – Hide a task from the list of progress bars.
- [**fail_vendor**](#voidprogresstrackerfail_vendor) – Clean up the progress bars of a vendor failed mid-way.

### meth <code class="doc-parent">VoidProgressTracker.</code><code class="doc-name">start_vendor</code> [logger.py:312–313](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/logger.py#L312-L313)

```python
start_vendor(*args, **kwargs)
```

Starts a progress bar for the Vendor's steps.

**Parameters:**

- **total** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Overall number of steps to show in the progress bar.

**Returns:**

- **TaskId** (`TaskID`) – The progress bar's identifier to be referenced in future updates.

### meth <code class="doc-parent">VoidProgressTracker.</code><code class="doc-name">advance_vendor</code> [logger.py:315–316](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/logger.py#L315-L316)

```python
advance_vendor(*args, **kwargs)
```

Increment the number of finished steps.

**Parameters:**

- **advance** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Number of steps to advance.

### meth <code class="doc-parent">VoidProgressTracker.</code><code class="doc-name">update_vendor</code> [logger.py:318–319](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/logger.py#L318-L319)

```python
update_vendor(*args, **kwargs)
```

Update the vendor's progress bar.

Useful fields:
- `step`: Name of the currently running step to be shown on the progress bar.

### meth <code class="doc-parent">VoidProgressTracker.</code><code class="doc-name">start_task</code> [logger.py:321–322](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/logger.py#L321-L322)

```python
start_task(*args, **kwargs)
```

Starts a progress bar in the list of current jobs.

Besides returning the `TaskID`, it will also register in `self.tasks.task_ids`
as the last task, which will be the default value for future `advance_task`,
`hide_task` etc calls. The latter will remove the `TaskID` from the `task_ids`.

**Parameters:**

- **name** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Name to show in front of the progress bar. Will be prefixed by Vendor's name.
- **total** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Overall number of steps to show in the progress bar.

**Returns:**

- **TaskId** (`TaskID`) – The progress bar's identifier to be referenced in future updates.

### meth <code class="doc-parent">VoidProgressTracker.</code><code class="doc-name">last_task</code> [logger.py:324–325](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/logger.py#L324-L325)

```python
last_task(*args, **kwargs)
```

Returh the last registered TaskID.

### meth <code class="doc-parent">VoidProgressTracker.</code><code class="doc-name">advance_task</code> [logger.py:327–328](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/logger.py#L327-L328)

```python
advance_task(*args, **kwargs)
```

Increment the number of finished steps.

**Parameters:**

- **task_id** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)`[TaskID]`) – The progress bar's identifier returned by `start_task`.
Defaults to the most recently created task.
- **advance** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Number of steps to advance.

### meth <code class="doc-parent">VoidProgressTracker.</code><code class="doc-name">update_task</code> [logger.py:330–331](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/logger.py#L330-L331)

```python
update_task(*args, **kwargs)
```

Update the task's progress bar.

**Parameters:**

- **task_id** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)`[TaskID]`) – The progress bar's identifier returned by `start_task`.
Defaults to the most recently created task.

**Other Parameters:**

- **step** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Name of the currently running step to be shown on the progress bar.

See [`rich.progress.Progress.update`](https://rich.readthedocs.io/en/stable/reference/progress.html#rich.progress.Progress.update) for further keyword arguments.

### meth <code class="doc-parent">VoidProgressTracker.</code><code class="doc-name">hide_task</code> [logger.py:333–334](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/logger.py#L333-L334)

```python
hide_task(*args, **kwargs)
```

Hide a task from the list of progress bars.

**Parameters:**

- **task_id** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)`[TaskID]`) – The progress bar's identifier returned by `start_task`.
Defaults to the most recently created task.

### meth <code class="doc-parent">VoidProgressTracker.</code><code class="doc-name">fail_vendor</code> [logger.py:336–337](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/logger.py#L336-L337)

```python
fail_vendor(*args, **kwargs)
```

Clean up the progress bars of a vendor failed mid-way.

Removes the progress bars of the vendor's interrupted steps from the
display (e.g. when an exception interrupted an inventory step before its
`hide_task` call), and stops the vendor's progress bar so its elapsed time
no longer increases while the next vendors are being processed. These are
display entries only, the interrupted work is not running anymore.

**Parameters:**

- **step** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Text to show as the current step on the vendor's progress bar.
