mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-20 10:47:35 -05:00
This PR tries to improve and rationalize what we log. Key points:
- introduce `logger.ts`: each file/component is encouraged to use the logger instead of writing directly to `console.*`
* the logger automatically prepend a prefix like `[py-config]`, `[py-env]` which make it easier to understand where a certain message is printed from
* it provide a central place where to add more features in the future. E.g., I can imagine having a config setting to completely silence the logs (not implemented yet)
- use the new loggers everywhere
- write to `.info()` instead of `.log()`. The idea is to keep `console.log` free, so that for the users it's easier to tell apart their own messages and the pyscript ones
- generally improve what we log. This is an endless exercise, but I tried to print more things which are useful to understand what's going on and in which order the various things are executed, and remove prints which were clearly debugging leftovers
44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
import { BaseEvalElement } from './base';
|
|
import { getLogger } from '../logger';
|
|
|
|
const logger = getLogger('py-loader');
|
|
|
|
export class PyLoader extends BaseEvalElement {
|
|
widths: Array<string>;
|
|
label: string;
|
|
mount_name: string;
|
|
details: HTMLElement;
|
|
operation: HTMLElement;
|
|
constructor() {
|
|
super();
|
|
}
|
|
|
|
connectedCallback() {
|
|
this.innerHTML = `<div id="pyscript_loading_splash" class="py-overlay">
|
|
<div class="py-pop-up">
|
|
<div class="smooth spinner"></div>
|
|
<div id="pyscript-loading-label" class="label">
|
|
<div id="pyscript-operation-details">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>`;
|
|
this.mount_name = this.id.split('-').join('_');
|
|
this.operation = document.getElementById('pyscript-operation');
|
|
this.details = document.getElementById('pyscript-operation-details');
|
|
}
|
|
|
|
log(msg: string) {
|
|
// loader messages are showed both in the HTML and in the console
|
|
logger.info(msg);
|
|
const newLog = document.createElement('p');
|
|
newLog.innerText = msg;
|
|
this.details.appendChild(newLog);
|
|
}
|
|
|
|
close() {
|
|
logger.info('Closing');
|
|
this.remove();
|
|
}
|
|
}
|