;; ============================================ ;; Script: error-logger.r ;; downloaded from: www.REBOL.org ;; on: 29-Mar-2024 ;; at: 7:27:22.272937 UTC ;; owner: volker [script library member who can ;; update this script] ;; ============================================ ;; =================================================== ;; email address(es) have been munged to protect them ;; from spam harvesters. ;; If you were logged on the email addresses would not ;; be munged ;; =================================================== REBOL [ Title: "error-logger" Date: 10-Dec-2001/20:08:05+1:00 Version: 1.2.0 File: %error-logger.r Author: "Volker" Usage: { find "test: [", kill all below and do this script, or copy the functions to yours. Following Docu thanks to Sunanda : Problem: Rebol error messages give way to little context. Useful for development maybe, but underpowered for code deployed in the field. Volker's solution. 1. Be structured. Embed all Funcs in Objects: MyObject1: [Myfunc1: func [...] [...] Myfunc2: func [...] [...] ] MyObject2: [Myfunc1: func [...] [...] Myfunc2: func [...] [...] ] This is pretty good practice anyway. 2. For any of these functions you want a better set of reporting on, defined the with the Logged marker word: MyObject1: [Myfunc1: logged func [...] [...] Myfunc2: func [...] [...] ] MyObject2: [Myfunc1: logged func [...] [...] Myfunc2: logged func [...] [...] ] (So for some reason, I've decided not to get a better oversight on MyObject1/MyFunc2) 3. Before you make your first object call, run Volker's initialisation code: Logging MyObject1 Logging MyObject2 (This replaces the 'logged marker word with some magic). Thanks Volker! Sunanda. } Purpose: {give better error feedback. logs a kind of stack-trace on error.} History: [ 1.2.0 "thanks to Sunanda real docu :)" 1.1.0 "logged/logging to have more service added" 1.0.1 "error without log-file, fixed" ] Email: %nitsch-lists--netcologne--de Web: http://www.escribe.com/internet/rebol/index.html?by=OneThread&t=%5BREBOL%5D%20Better%20error%20messages? library: [ level: none platform: none type: 'tool domain: none tested-under: none support: none license: none see-also: none ] ] ; ;control your logging here ;note i prefer logs with newest entries at top, ;otherwise i could use write/append ;-) ; insert-error-log: func [msg] [ msg: rejoin [newline mold now newline msg] print msg if not exists? log-file: %error-log.txt [write log-file ""] (write log-file join msg read log-file) ] ; ;wizzardry ; mission: func [ {like throw-on-error, but on error string is printed and logged.} string "mission-name" blk [block!] ] [ if error? set/any 'blk try blk [ msg: reform [ ">>>mission failed>>>" newline "mission" remold string "error:" newline form-error disarm blk newline "<<