@silver-zepp/vis-log
Version:
An on-screen logger for ZeppOS Mini apps.
1 lines • 1.34 kB
JavaScript
import VisLogSideCore from"./core";export class VisLogAppSettings extends VisLogSideCore{_settings_storage=null;_is_initialized=false;constructor(options={}){super(options)}attachSettingsRelay(settings_storage,options={}){if(this._is_initialized){return}this._settings_storage=settings_storage;if(options.filename){this._filename=options.filename}if(options.clear_on_init!==false){this._clearOldLogs()}this._is_initialized=true}initialized(){return this._is_initialized&&this._settings_storage!==null}_writeLog(level,...args){if(!this.initialized()){return}if(!this.getEnabled()){return}try{const message=this.formatMessage(...args);const log_entry=this.createLogEntry(level,message,"AppSettings");const key=`${this.getDebugKeyPrefix()}${String(log_entry.counter).padStart(4,"0")}`;this._settings_storage.setItem(key,JSON.stringify(log_entry))}catch(err){console.log("VisLogAppSettings error:",err)}}clear(){this._clearOldLogs()}_clearOldLogs(){if(!this._settings_storage)return;try{const all_settings=this._settings_storage.toObject?.()||{};Object.keys(all_settings).filter(key=>key.startsWith(this.getDebugKeyPrefix())).forEach(key=>{this._settings_storage.removeItem(key)})}catch(error){console.log("VisLogAppSettings: Error clearing old logs:",error)}}destroy(){this.setEnabled(false);this._settings_storage=null;this._is_initialized=false}}