ITADN

Not able to intercept log neither console output from HIGHS

#47Closedsgnieto 创建于 2025-06-25
S
sgnietocommented
Hi, I'm trying to intercept print and printErr, as well as get the log file generated from HIGHS with no success. This is the code used for initialization: export class SolverService implements OnModuleInit { private highs: any; private readonly logger = new Logger(SolverService.name); private highsInitializationPromise: Promise<void>; private logs: string[] = []; private errors: string[] = []; const promise = highsFactory({ locateFile: (file: string) => { const highsPath = path.dirname(require.resolve('highs')); const filePath = path.join(highsPath, file); this.logger.log(`Locating Highs resource: ${filePath}`); return filePath; }, print: (text: string) => { this.logs.push(text); }, printErr: (text: string) => { this.errors.push(text); }, }); this.highs = await promise; This is the code where I call the solve method: const solverOptions = { presolve: 'on', // cadena aceptada por HiGHS parallel: 'on', log_to_console: true, // booleano → stdout output_flag: false, // activa cualquier salida //log_file: 'highs.log', // HiGHS (compilado para Node) escribe en el FS real use_implied_bounds_from_presolve: true, time_limit: 300.0, // segundos mip_rel_gap: 0.00001 }; this.logger.log(`Opciones del Solver: ${JSON.stringify(solverOptions)}`); let result: any; let highsError: any; try { result = this.highs.solve(modelString, solverOptions); } catch (err) { highsError = err; this.logger.error('HiGHS lanzó una excepción', err); } finally { console.log("Logs capturados:", this.logs); console.error("Errores capturados:", this.errors); // --- Intentar volcar el log aunque se haya producido un error --- try { const hostLogPath = path.join(process.cwd(), 'highs.log'); const logContent = await fs.readFile(hostLogPath, { encoding: 'utf8' }); this.logger.log('--- LOG DE HiGHS ---\n' + logContent.split('\n').slice(-30).join('\n')); } catch (errLog) { this.logger.warn('No se pudo extraer /highs.log del FS de HiGHS', errLog?.message || errLog); } } And this is the log generated: [Nest] 36916 - 25/06/2025, 11:23:40 LOG [SolverService] Calling Highs solver... [Nest] 36916 - 25/06/2025, 11:23:40 LOG [SolverService] Opciones del Solver: {"presolve":"on","parallel":"on","log_to_console":true,"output_flag":false,"use_implied_bounds_from_presolve":true,"time_limit":300,"mip_rel_gap":0.00001} [Nest] 36916 - 25/06/2025, 11:24:18 ERROR [SolverService] HiGHS lanzó una excepción [Nest] 36916 - 25/06/2025, 11:24:18 ERROR [SolverService] Error: Unable to solve the problem. HiGHS error RuntimeError: Aborted(). Build with -sASSERTIONS for more info. Logs capturados: [] Errores capturados: [] [Nest] 36916 - 25/06/2025, 11:24:18 WARN [SolverService] No se pudo extraer /highs.log del FS de HiGHS [Nest] 36916 - 25/06/2025, 11:24:18 WARN [SolverService] ENOENT: no such file or directory, open 'C:\sgn\wspc\pocTsCompras\highs.log'
关闭于 2026-05-28 1 条评论