-
Notifications
You must be signed in to change notification settings - Fork 651
这是一款基于 Python 的交互式数据应用 WASM 打包器:将复杂的数据流,尤其是可视化,打包到单个文件中,完全可在浏览器内运行,使用… #784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| import * as Comlink from 'comlink'; | ||
| import { createLogger } from '../lib/logger'; | ||
|
|
||
| const logger = createLogger('Service'); | ||
|
|
||
| // import PreswaldWorker from './worker.js?worker&inline'; // ← change | ||
|
|
||
|
|
@@ -7,18 +10,18 @@ let workerInstance = null; | |
| export function createWorker() { | ||
| // If we're already initialized, return the existing worker | ||
| if (workerInstance) { | ||
| console.log('[Service] Reusing existing worker instance'); | ||
| logger.debug('[Service] Reusing existing worker instance'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Double namespace prefix in service.js log messagesLow Severity The logger is created with Additional Locations (2)Reviewed by Cursor Bugbot for commit ec6fe10. Configure here. |
||
| return workerInstance; | ||
| } | ||
|
|
||
| console.log('[Service] Starting new worker initialization'); | ||
| logger.debug('[Service] Starting new worker initialization'); | ||
| try { | ||
| const worker = new Worker(new URL('./worker.js', import.meta.url), { type: 'module' }); | ||
| // const worker = new PreswaldWorker(); // ← no URL needed | ||
| workerInstance = Comlink.wrap(worker); | ||
| return workerInstance; | ||
| } catch (error) { | ||
| console.error('[Service] Worker initialization failed:', error); | ||
| logger.error('[Service] Worker initialization failed:', error); | ||
| workerInstance = null; | ||
| throw error; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| /** | ||
| * Production-ready logging utility with configurable log levels | ||
| * Automatically disables debug logs in production builds | ||
| */ | ||
|
|
||
| const LogLevel = { | ||
| DEBUG: 0, | ||
| INFO: 1, | ||
| WARN: 2, | ||
| ERROR: 3, | ||
| NONE: 4 | ||
| }; | ||
|
|
||
| // Determine log level based on environment | ||
| const getDefaultLogLevel = () => { | ||
| if (typeof process !== 'undefined' && process.env) { | ||
| // Node.js environment | ||
| if (process.env.NODE_ENV === 'production') { | ||
| return LogLevel.WARN; | ||
| } | ||
| if (process.env.NODE_ENV === 'test') { | ||
| return LogLevel.ERROR; | ||
| } | ||
| } | ||
|
|
||
| // Browser environment - check for debug flag | ||
| if (typeof window !== 'undefined') { | ||
| const urlParams = new URLSearchParams(window.location.search); | ||
| if (urlParams.has('debug')) { | ||
| return LogLevel.DEBUG; | ||
| } | ||
| // Check for production indicators | ||
| if (window.location.hostname !== 'localhost' && | ||
| !window.location.hostname.includes('127.0.0.1') && | ||
| !window.location.hostname.includes('dev.')) { | ||
| return LogLevel.WARN; | ||
| } | ||
| } | ||
|
|
||
| return LogLevel.DEBUG; | ||
| }; | ||
|
|
||
| class Logger { | ||
| constructor(namespace = 'App', level = null) { | ||
| this.namespace = namespace; | ||
| this.level = level !== null ? level : getDefaultLogLevel(); | ||
| } | ||
|
|
||
| _shouldLog(level) { | ||
| return level >= this.level; | ||
| } | ||
|
|
||
| _formatMessage(level, message) { | ||
| return `[${this.namespace}] ${message}`; | ||
| } | ||
|
|
||
| debug(message, ...args) { | ||
| if (this._shouldLog(LogLevel.DEBUG)) { | ||
| console.debug(this._formatMessage('DEBUG', message), ...args); | ||
| } | ||
| } | ||
|
|
||
| info(message, ...args) { | ||
| if (this._shouldLog(LogLevel.INFO)) { | ||
| console.info(this._formatMessage('INFO', message), ...args); | ||
| } | ||
| } | ||
|
|
||
| warn(message, ...args) { | ||
| if (this._shouldLog(LogLevel.WARN)) { | ||
| console.warn(this._formatMessage('WARN', message), ...args); | ||
| } | ||
| } | ||
|
|
||
| error(message, ...args) { | ||
| if (this._shouldLog(LogLevel.ERROR)) { | ||
| console.error(this._formatMessage('ERROR', message), ...args); | ||
| } | ||
| } | ||
|
|
||
| // Set log level dynamically | ||
| setLevel(level) { | ||
| this.level = level; | ||
| } | ||
| } | ||
|
|
||
| // Create default logger instance | ||
| const defaultLogger = new Logger('App'); | ||
|
|
||
| // Factory function for creating namespaced loggers | ||
| export const createLogger = (namespace) => { | ||
| return new Logger(namespace); | ||
| }; | ||
|
|
||
| // Export default logger methods | ||
| export const logger = { | ||
| debug: (...args) => defaultLogger.debug(...args), | ||
| info: (...args) => defaultLogger.info(...args), | ||
| warn: (...args) => defaultLogger.warn(...args), | ||
| error: (...args) => defaultLogger.error(...args), | ||
| setLevel: (level) => defaultLogger.setLevel(level), | ||
| LogLevel | ||
| }; | ||
|
|
||
| export { LogLevel, Logger }; | ||
| export default logger; |


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remaining console.warn not migrated to logger in App
Low Severity
One
console.warn('[App] Invalid component found during bulk state update:', component)call was not converted tologger.warn(...)while every otherconsole.*call inApp.jsxwas migrated. This is inconsistent with the logging migration and will bypass the logger's level filtering in production.Reviewed by Cursor Bugbot for commit ec6fe10. Configure here.