From fba17e4d34d6df538fc44ad2190f0f8becf85966 Mon Sep 17 00:00:00 2001 From: Henning Stahlke Date: Mon, 20 Apr 2020 16:24:49 +0200 Subject: [PATCH] Replace printlog by logprint --- Nasal/aircraft.nas | 6 +-- Nasal/canvas/MapStructure.nas | 26 ++++----- Nasal/canvas/api.nas | 4 +- Nasal/canvas/draw/draw.nas | 4 +- Nasal/canvas/gui/dialogs/AircraftCenter.nas | 2 +- Nasal/canvas/gui/dialogs/MessageBox.nas | 4 +- Nasal/canvas/map/DTO.symbol | 2 +- Nasal/canvas/map/FIX.lcontroller | 2 +- Nasal/canvas/map/FLT.lcontroller | 4 +- Nasal/canvas/map/RTE.lcontroller | 2 +- Nasal/canvas/map/TFC.lcontroller | 4 +- Nasal/canvas/map/VOR-airbus.lcontroller | 2 +- Nasal/canvas/map/VOR-g1000.lcontroller | 2 +- Nasal/canvas/map/VOR.lcontroller | 2 +- Nasal/canvas/map/WPT.lcontroller | 2 +- Nasal/canvas/map/WXR.lcontroller | 2 +- Nasal/canvas/map/aircraftpos.controller | 2 +- Nasal/canvas/map/navdisplay.mfd | 6 +-- Nasal/canvas/svg.nas | 47 ++++++++-------- Nasal/canvas/tooltip.nas | 3 +- Nasal/console/repl.nas | 54 +++++++++---------- Nasal/contrail.nas | 2 +- Nasal/globals.nas | 21 +++----- Nasal/input_helpers/goflight.nas | 2 +- Nasal/modules/canvas_efis/efis.nas | 10 ++-- .../modules/canvas_efis/eicas-message-sys.nas | 4 +- Nasal/mp_broadcast.nas | 3 +- Nasal/props.nas | 12 ++--- Nasal/route_manager.nas | 2 +- Nasal/screen.nas | 4 +- Nasal/seaport.nas | 4 +- Nasal/wildfire.nas | 14 ++--- 32 files changed, 124 insertions(+), 136 deletions(-) diff --git a/Nasal/aircraft.nas b/Nasal/aircraft.nas index 570920d3c..e1a248842 100644 --- a/Nasal/aircraft.nas +++ b/Nasal/aircraft.nas @@ -1186,9 +1186,9 @@ _setlistener("/sim/signals/nasal-dir-initialized", func { ##### temporary hack to provide backward compatibility for /sim/auto-coordination ##### remove this code when all references to /sim/auto-coordination are gone var ac = props.globals.getNode("/sim/auto-coordination"); - if(ac != nil ) { - printlog("alert", - "WARNING: using deprecated property /sim/auto-coordination. Please change to /controls/flight/auto-coordination" ); + if (ac != nil) { + logprint(LOG_ALERT, "WARNING: using deprecated property "~ + "/sim/auto-coordination. Please change to /controls/flight/auto-coordination"); ac.alias(props.globals.getNode("/controls/flight/auto-coordination", 1)); } #### end of temporary hack for /sim/auto-coordination diff --git a/Nasal/canvas/MapStructure.nas b/Nasal/canvas/MapStructure.nas index c3a3a55b5..a56286ebb 100644 --- a/Nasal/canvas/MapStructure.nas +++ b/Nasal/canvas/MapStructure.nas @@ -19,10 +19,10 @@ ## - searchCmd -> filtering ## ## APIs to be wrapped for each layer: -## printlog(), die(), debug.bt(), benchmark() +## logprint(), die(), debug.bt(), benchmark() -var _MP_dbg_lvl = "debug"; -#var _MP_dbg_lvl = "alert"; +var _MP_dbg_lvl = LOG_DEBUG; +#var _MP_dbg_lvl = DEV_ALERT; var makedie = func(prefix) func(msg) globals.die(prefix~" "~msg); @@ -475,7 +475,7 @@ var Symbol = { var tp = typeof(val); if(tp != 'scalar'){ val = ''; - #printlog("warn", "formattedString: invalid type for "~prop~" (" ~ tp ~ ")"); + #logprint(LOG_WARN, "formattedString: invalid type for "~prop~" (" ~ tp ~ ")"); } else { append(args, val); } @@ -722,7 +722,7 @@ var DotSym = { return m; }, del: func() { - printlog(_MP_dbg_lvl, "DotSym.del()"); + logprint(_MP_dbg_lvl, "DotSym.del()"); me.deinit(); call(Symbol.del, nil, me); me.element.del(); @@ -852,7 +852,7 @@ var LineSymbol = { draw: func() { if (!me.needs_update) return; me.callback('draw_before'); - printlog(_MP_dbg_lvl, "redrawing a LineSymbol "~me.layer.type); + logprint(_MP_dbg_lvl, "redrawing a LineSymbol "~me.layer.type); me.element.reset(); var cmds = []; var coords = []; @@ -879,7 +879,7 @@ var LineSymbol = { me.callback('draw_after'); }, del: func() { - printlog(_MP_dbg_lvl, "LineSymbol.del()"); + logprint(_MP_dbg_lvl, "LineSymbol.del()"); me.deinit(); call(Symbol.del, nil, me); me.element.del(); @@ -1060,7 +1060,7 @@ var MultiSymbolLayer = { } }, del: func() { - printlog(_MP_dbg_lvl, "MultiSymbolLayer.del()"); + logprint(_MP_dbg_lvl, "MultiSymbolLayer.del()"); foreach (var e; me.list) e.del(); call(SymbolLayer.del, nil, me); @@ -1094,13 +1094,13 @@ var MultiSymbolLayer = { }, # Adds a symbol. onAdded: func(model) { - printlog(_MP_dbg_lvl, "Adding symbol of type "~me.type); + logprint(_MP_dbg_lvl, "Adding symbol of type "~me.type); if (model == nil) __die("MultiSymbolLayer: Model was nil for layer:"~debug.string(me.type)~ " Hint:check your equality check method!"); append(me.list, Symbol.new(me.type, me.group, me, model)); }, # Removes a symbol. onRemoved: func(model) { - printlog(_MP_dbg_lvl, "Deleting symbol of type "~me.type); + logprint(_MP_dbg_lvl, "Deleting symbol of type "~me.type); if (!me.delsym(model)) __die("model not found"); try_aux_method(model, "del"); #call(func model.del(), nil, var err = []); # try... @@ -1121,7 +1121,7 @@ var NavaidSymbolLayer = { make: func(query) { #print("Creating searchCmd() for NavaidSymbolLayer:", query); return func { - printlog(_MP_dbg_lvl, "Running query:", query); + logprint(_MP_dbg_lvl, "Running query:", query); var range = me.map.getRange(); if (range == nil) return; return positioned.findWithinRange(me.map.getPosCoord(), range, query); @@ -1177,7 +1177,7 @@ var SingleSymbolLayer = { } }, del: func() { - printlog(_MP_dbg_lvl, "SymbolLayer.del()"); + logprint(_MP_dbg_lvl, "SymbolLayer.del()"); me.symbol.del(); call(SymbolLayer.del, nil, me); }, @@ -1433,7 +1433,7 @@ var TileLayer = { } }, del: func() { - printlog(_MP_dbg_lvl, "SymbolLayer.del()"); + logprint(_MP_dbg_lvl, "SymbolLayer.del()"); call(OverlayLayer.del, nil, me); }, }; # of TileLayer diff --git a/Nasal/canvas/api.nas b/Nasal/canvas/api.nas index 5cc96c96c..18b852c71 100644 --- a/Nasal/canvas/api.nas +++ b/Nasal/canvas/api.nas @@ -537,7 +537,7 @@ var Map = { addLayer: func(factory, type_arg=nil, priority=nil, style=nil, opts=nil, visible=1) { if(contains(me.layers, type_arg)) - printlog("warn", "addLayer() warning: overwriting existing layer:", type_arg); + logprint(DEV_ALERT, "addLayer() warning: overwriting existing layer:", type_arg); var options = opts; # Argument handling @@ -625,7 +625,7 @@ var Map = { if (predicate == nil or predicate(layer)) layer.update(); } - printlog(_MP_dbg_lvl, "Took "~((systime()-t)*1000)~"ms to update map()"); + logprint(_MP_dbg_lvl, "Took "~((systime()-t)*1000)~"ms to update map()"); me.setBool("update", 1); # update any coordinates that changed, to avoid floating labels etc. return me; }, diff --git a/Nasal/canvas/draw/draw.nas b/Nasal/canvas/draw/draw.nas index eca6d07d6..b709d66b9 100644 --- a/Nasal/canvas/draw/draw.nas +++ b/Nasal/canvas/draw/draw.nas @@ -276,7 +276,7 @@ draw.marksStyle = { draw.marksLinear = func(cgroup, orientation, num_marks, interval, style) { if (!isa(style, draw.marksStyle)) { - printlog("alert", "draw.marks: invalid style argument."); + logprint(DEV_WARN, "draw.marks: invalid style argument."); return nil; } orientation = chr(string.tolower(orientation[0])); @@ -347,7 +347,7 @@ draw.marksCircular = func(cgroup, radius, interval, phi_start = 0, phi_stop = 36 style = draw.marksStyle.new(); } if (!isa(style, draw.marksStyle)) { - printlog("info", "draw.marksCircular: invalid style argument"); + logprint(DEV_WARN, "draw.marksCircular: invalid style argument"); return nil; } # normalize diff --git a/Nasal/canvas/gui/dialogs/AircraftCenter.nas b/Nasal/canvas/gui/dialogs/AircraftCenter.nas index 7941a37fb..dcf617ad9 100644 --- a/Nasal/canvas/gui/dialogs/AircraftCenter.nas +++ b/Nasal/canvas/gui/dialogs/AircraftCenter.nas @@ -179,7 +179,7 @@ var AircraftCenter = { var acft_id = variant; b.listen("clicked", func { - printlog("warn", "Switching to aircraft '" ~ acft_id ~ "'"); + logprint(LOG_WARN, "Switching to aircraft '" ~ acft_id ~ "'"); fgcommand("switch-aircraft", props.Node.new({"aircraft": acft_id})); }); launch_bar.addItem(b); diff --git a/Nasal/canvas/gui/dialogs/MessageBox.nas b/Nasal/canvas/gui/dialogs/MessageBox.nas index 9b5b8ac93..b17a8af71 100644 --- a/Nasal/canvas/gui/dialogs/MessageBox.nas +++ b/Nasal/canvas/gui/dialogs/MessageBox.nas @@ -187,7 +187,7 @@ var MessageBox = { if( io.stat(me._save_path) != nil ) { - printlog("info", "Load dialog selection from '" ~ me._save_path ~ "'"); + logprint(LOG_INFO, "Load dialog selection from '" ~ me._save_path ~ "'"); return int(io.readfile(me._save_path)); } @@ -195,7 +195,7 @@ var MessageBox = { }, _saveSelection: func(sel) { - printlog("info", "Saving dialog selection to '" ~ me._save_path ~ "'"); + logprint(LOG_INFO, "Saving dialog selection to '" ~ me._save_path ~ "'"); # ensure directory exists os.path.new(me._save_path).create_dir(); diff --git a/Nasal/canvas/map/DTO.symbol b/Nasal/canvas/map/DTO.symbol index f57bcf1d8..51554006a 100644 --- a/Nasal/canvas/map/DTO.symbol +++ b/Nasal/canvas/map/DTO.symbol @@ -22,7 +22,7 @@ var init = func { var draw = func() { me.callback('draw_before'); - printlog(_MP_dbg_lvl, "redrawing a LineSymbol "~me.layer.type); + logprint(_MP_dbg_lvl, "redrawing a LineSymbol "~me.layer.type); me.element.reset(); var cmds = []; var coords = []; diff --git a/Nasal/canvas/map/FIX.lcontroller b/Nasal/canvas/map/FIX.lcontroller index 316690c85..701a55d70 100644 --- a/Nasal/canvas/map/FIX.lcontroller +++ b/Nasal/canvas/map/FIX.lcontroller @@ -22,7 +22,7 @@ var new = func(layer) { return m; }; var del = func() { - printlog(_MP_dbg_lvl, "VOR.lcontroller.del()"); + logprint(_MP_dbg_lvl, "VOR.lcontroller.del()"); foreach (var l; me.listeners) removelistener(l); }; diff --git a/Nasal/canvas/map/FLT.lcontroller b/Nasal/canvas/map/FLT.lcontroller index 6e6be70d8..cf3422ad0 100644 --- a/Nasal/canvas/map/FLT.lcontroller +++ b/Nasal/canvas/map/FLT.lcontroller @@ -43,10 +43,10 @@ var del = func() { }; var searchCmd = func() { - printlog(_MP_dbg_lvl, "Running query: FLT"); + logprint(_MP_dbg_lvl, "Running query: FLT"); var hist = aircraft.history(); var path = hist.pathForHistory(1000); - printlog(_MP_dbg_lvl, "FLT size: "~size(path)); + logprint(_MP_dbg_lvl, "FLT size: "~size(path)); while (size(me.models) <= me.active_path) append(me.models, []); for (var i=size(me.models[me.active_path]); i 0 ) - printlog( - "warn", - "Invalid number of coords for cmd 'a' " - ~ "(" ~ size(args) ~ " mod 7 != 0)" - ); + if( math.mod(size(args), 7) > 0 ) { + logpr(LOG_WARN, "Invalid number of coords for cmd 'a' ("~ + size(args)~" mod 7 != 0)"); + } } else { var cmd_vg = cmd_map[cmd]; if( cmd_vg == nil ) { - printlog("warn", "command not found: '" ~ cmd ~ "'"); + logpr(LOG_WARN, "command not found: '" ~ cmd ~ "'"); continue; } @@ -312,10 +309,8 @@ var parsesvg = func(group, path, options = nil) } if( math.mod(size(args), num_coords) > 0 ) - printlog( - "warn", - "Invalid number of coords for cmd '" ~ cmd ~ "' " - ~ "(" ~ size(args) ~ " mod " ~ num_coords ~ " != 0)" + logpr(LOG_WARN,"Invalid number of coords for cmd '" ~ cmd ~ "' (" + ~size(args)~" mod "~num_coords~" != 0)" ); } } @@ -439,7 +434,7 @@ var parsesvg = func(group, path, options = nil) } else { - printlog("info", "Skipping unknown element in : <" ~ name ~ ">"); + logpr(LOG_INFO, "Skipping unknown element in : <" ~ name ~ ">"); skip = level; } return; @@ -456,7 +451,7 @@ var parsesvg = func(group, path, options = nil) cur_clip = clip_dict[clip_id]; if( cur_clip == nil ) - printlog("warn", "Clip not found: '" ~ clip_id ~ "'"); + logpr(LOG_WARN, "Clip not found: '" ~ clip_id ~ "'"); } if( style['display'] == 'none' ) @@ -565,11 +560,11 @@ var parsesvg = func(group, path, options = nil) { var ref = attr["xlink:href"]; if( ref == nil or size(ref) < 2 or ref[0] != `#` ) - return printlog("warn", "Invalid or missing href: '" ~ ref ~ "'"); + return logpr(LOG_WARN, "Invalid or missing href: '" ~ ref ~ "'"); var el_src = id_dict[ substr(ref, 1) ]; if( el_src == nil ) - return printlog("warn", "Reference to unknown element '" ~ ref ~ "'"); + return logpr(LOG_WARN, "Reference to unknown element '" ~ ref ~ "'"); # Create new element and copy sub branch from source node pushElement(el_src._node.getName(), attr['id']); @@ -591,10 +586,10 @@ var parsesvg = func(group, path, options = nil) # by adding another backslash - otherwise parse error anywhere below if (ref == nil or find("\\", ref) > -1) { - return printlog("info", "Invalid or missing href in image tag: '" ~ ref ~ "'"); + return logpr(LOG_INFO, "Invalid or missing href in image tag: '" ~ ref ~ "'"); } if (substr(ref, 0, 5) == "data:") { - return printlog("info", "Unsupported embedded image"); + return logpr(LOG_INFO, "Unsupported embedded image"); } elsif (substr(ref, 0, 5) != "file:") { # absolute paths seem to start with "file:" @@ -614,7 +609,7 @@ var parsesvg = func(group, path, options = nil) } else { - printlog("info", "Skipping unknown element '" ~ name ~ "'"); + logpr(LOG_INFO, "Skipping unknown element '" ~ name ~ "'"); skip = level; return; } @@ -764,7 +759,7 @@ var parsesvg = func(group, path, options = nil) msg ~= (i == 1 ? "\n at " : "\n called from: ") ~ err[i] ~ ", line " ~ err[i + 1] } - printlog("alert", msg ~ "\n "); + logpr(LOG_ALERT, msg ~ "\n "); return 0; } diff --git a/Nasal/canvas/tooltip.nas b/Nasal/canvas/tooltip.nas index 61b2c5727..dc3735481 100644 --- a/Nasal/canvas/tooltip.nas +++ b/Nasal/canvas/tooltip.nas @@ -134,8 +134,7 @@ var Tooltip = { # wrap mapping in 'call' to catch conversion errors var val_mapped = call(me._remapValue, [val], me, nil, var err = []); if( size(err) ) { - printlog( - "warn", + logprint(LOG_WARN, "Tooltip: failed to remap " ~ debug.string(p, 0) ~ ":\n" ~ debug.string(err, 0) ); diff --git a/Nasal/console/repl.nas b/Nasal/console/repl.nas index 86b42f9f2..9135a93fe 100644 --- a/Nasal/console/repl.nas +++ b/Nasal/console/repl.nas @@ -1,5 +1,5 @@ -var _REPL_dbg_level = "debug"; -#var _REPL_dbg_level = "alert"; +var _REPL_dbg_level = LOG_DEBUG; +#var _REPL_dbg_level = LOG_ALERT; var REPL = { df_status: 0, @@ -42,7 +42,7 @@ var REPL = { me.current = nil; - printlog(_REPL_dbg_level, "compiling code..."~debug.string(code)); + logprint(_REPL_dbg_level, "compiling code..."~debug.string(code)); var fn = call(func compile(code, me.name), nil, var err=[]); if (size(err)) { @@ -73,7 +73,7 @@ var REPL = { var str = substr(str, 0, 1); if (contains(me.brackets, str)) { append(level, str); - printlog(_REPL_dbg_level, "> level add "~str); + logprint(_REPL_dbg_level, "> level add "~str); return 1; } elsif (contains(me.brackets_rev, str)) { var l = pop(level); @@ -84,7 +84,7 @@ var REPL = { me.placement.handle_parse_error("bracket mismatch: "~me.brackets[l]~" vs "~str, me.name, line_number); return nil; } else { - printlog(_REPL_dbg_level, "< level pop "~str); + logprint(_REPL_dbg_level, "< level pop "~str); return 1; } } @@ -112,9 +112,9 @@ var REPL = { me.current.last_operator = nil; if (line[i] == `\\`) { i += 1; # skip the next character - printlog(_REPL_dbg_level, " skip backslash"); + logprint(_REPL_dbg_level, " skip backslash"); } elsif (line[i] == me.current.level[-1][0]) { - printlog(_REPL_dbg_level, "< out of string with "~me.current.level[-1]); + logprint(_REPL_dbg_level, "< out of string with "~me.current.level[-1]); pop(me.current.level); } continue; @@ -127,7 +127,7 @@ var REPL = { me.current.last_operator = nil; if (me.current.statement_level == size(me.current.level) and (line[i] == `;` or line[i] == `,`)) { - printlog(_REPL_dbg_level, "statement ended by ;/,"); + logprint(_REPL_dbg_level, "statement ended by ;/,"); me.current.statement = nil; me.current.statement_level = nil; } else { @@ -136,13 +136,13 @@ var REPL = { me.current = nil; return 0; } elsif (me.current.statement_level > size(me.current.level)) { - printlog(_REPL_dbg_level, "statement ended by level below"); + logprint(_REPL_dbg_level, "statement ended by level below"); # cancel out of statement me.current.statement = nil; me.current.statement_level = nil; } elsif (line[i] == `{`) { # cancel out of looking for `;`, because we have a real block here - printlog(_REPL_dbg_level, "statement ended by braces"); + logprint(_REPL_dbg_level, "statement ended by braces"); me.current.statement = nil; me.current.statement_level = nil; } @@ -155,7 +155,7 @@ var REPL = { (i+size(stmt) >= len or !string.isalnum(line[i+size(stmt)]) and line[i+size(stmt)] != `_`)) { - printlog(_REPL_dbg_level, "found: "~stmt); + logprint(_REPL_dbg_level, "found: "~stmt); me.current.statement = stmt; me.current.statement_level = size(me.current.level); i += size(stmt)-1; @@ -165,7 +165,7 @@ var REPL = { } elsif (me._is_str_char(line[i])) { me.current.last_operator = nil; append(me.current.level, chr(line[i])); - printlog(_REPL_dbg_level, "> into string with "~me.current.level[-1]); + logprint(_REPL_dbg_level, "> into string with "~me.current.level[-1]); } else { var ret = me._handle_level(me.current.level, chr(line[i]), size(me.current.line)+1); me.current.last_operator = nil; @@ -174,7 +174,7 @@ var REPL = { elsif (ret == 0) { foreach (var o; me.operators_binary_unary) if (line[i] == o[0]) - { me.current.last_operator = o; printlog(_REPL_dbg_level, "found operator "~o); break } + { me.current.last_operator = o; logprint(_REPL_dbg_level, "found operator "~o); break } } } } @@ -564,18 +564,18 @@ var CanvasPlacement = { } elsif (modifiers.ctrl) { if (keyCode == `c`) { - printlog(_REPL_dbg_level, "ctrl+c: "~debug.string(me.input)); + logprint(_REPL_dbg_level, "ctrl+c: "~debug.string(me.input)); me.reset_input_from_history(); if( size(me.input) and !clipboard.setText(me.input) ) print("Failed to write to clipboard"); } elsif (keyCode == `x`) { - printlog(_REPL_dbg_level, "ctrl+x"); + logprint(_REPL_dbg_level, "ctrl+x"); me.reset_input_from_history(); if( size(me.input) and !clipboard.setText(me.clear_input()) ) print("Failed to write to clipboard"); } elsif (keyCode == `v`) { var input = clipboard.getText(); - printlog(_REPL_dbg_level, "ctrl+v: "~debug.string(input)); + logprint(_REPL_dbg_level, "ctrl+v: "~debug.string(input)); me.reset_input_from_history(); var abnormal = func string.iscntrl(input[j]) or (string.isxspace(input[j]) and input[j] != ` `) or !string.isascii(input[j]); var i=0; @@ -599,13 +599,13 @@ var CanvasPlacement = { i=j; } } elsif (keyCode == `d`) { # ctrl-D/EOF - printlog(_REPL_dbg_level, "EOF"); + logprint(_REPL_dbg_level, "EOF"); me.del(); return 1; } else return 0; } elsif (key == "Enter") { - printlog(_REPL_dbg_level, "return (key: "~key~", shift: "~modifiers.shift~")"); + logprint(_REPL_dbg_level, "return (key: "~key~", shift: "~modifiers.shift~")"); me.reset_input_from_history(); var reset_text = 1; if (modifiers.shift) { @@ -621,21 +621,21 @@ var CanvasPlacement = { CanvasPlacement.current_instance = me; var res = me.repl.get_input(); CanvasPlacement.current_instance = nil; - printlog(_REPL_dbg_level, "return code: "~debug.string(res)); + logprint(_REPL_dbg_level, "return code: "~debug.string(res)); } if (res == -1) me.continue_line(reset_text:reset_text); else me.new_prompt(); } elsif (key == "Backspace") { # backspace - printlog(_REPL_dbg_level, "back"); + logprint(_REPL_dbg_level, "back"); me.reset_input_from_history(); if (me.remove_char() == nil) return 1; # nothing happened, since the input # field was blank, but capture the event me.completion_pos = -1; } elsif (key == "Up") { # up - printlog(_REPL_dbg_level, "up"); + logprint(_REPL_dbg_level, "up"); if (me.curr == 0) return 1; me.curr -= 1; if (me.curr == size(me.history)) @@ -645,7 +645,7 @@ var CanvasPlacement = { me.completion_pos = -1; } elsif (key == "Down") { # down - printlog(_REPL_dbg_level, "down"); + logprint(_REPL_dbg_level, "down"); if (me.curr == size(me.history)) return 1; me.curr += 1; if (me.curr == size(me.history)) @@ -655,12 +655,12 @@ var CanvasPlacement = { me.completion_pos = -1; } elsif (key == "Escape") { # escape -> cancel - printlog(_REPL_dbg_level, "esc"); + logprint(_REPL_dbg_level, "esc"); me.del(); return 1; } elsif (key == "Tab") { # tab - printlog(_REPL_dbg_level, "tab"); + logprint(_REPL_dbg_level, "tab"); return 0; me.reset_input_from_history(); if (size(text) and text[0] == `/`) { @@ -668,16 +668,16 @@ var CanvasPlacement = { } } elsif (size(key) > 1 or !string.isprint(key[0])) { - printlog(_REPL_dbg_level, "other key: "~key); + logprint(_REPL_dbg_level, "other key: "~key); return 0; # pass other funny events } else { - printlog(_REPL_dbg_level, "key: "~key[0]~" (`"~key~"`)"); + logprint(_REPL_dbg_level, "key: "~key[0]~" (`"~key~"`)"); me.add_char(key[0]); me.completion_pos = -1; } - #printlog(_REPL_dbg_level, " -> "~me.input); + #logprint(_REPL_dbg_level, " -> "~me.input); me.update(); me.reset_view(); diff --git a/Nasal/contrail.nas b/Nasal/contrail.nas index 5890ec760..3391346ac 100644 --- a/Nasal/contrail.nas +++ b/Nasal/contrail.nas @@ -27,7 +27,7 @@ contrailTimer = maketimer(30, updateContrail); contrailTimer.simulatedTime = 1; _setlistener("/sim/signals/nasal-dir-initialized", func { - printlog ("debug", "init contrail"); + logprint(LOG_INFO, "Init contrail"); props.globals.initNode("environment/pressure-inhg", 1, "DOUBLE"); props.globals.initNode("environment/temperature-degc", 1, "DOUBLE"); props.globals.initNode("environment/contrail", 1, "BOOL"); diff --git a/Nasal/globals.nas b/Nasal/globals.nas index 273611797..74b656698 100644 --- a/Nasal/globals.nas +++ b/Nasal/globals.nas @@ -118,10 +118,8 @@ var setlistener = func(node, fn, init = 0, runtime = 1) { var id = _setlistener(node, func(chg, lst, mode, is_child) { fn(props.wrapNode(chg), props.wrapNode(lst), mode, is_child); }, init, runtime); - if(__.log_level <= 2) { - var c = caller(1); - printf("setting listener #%d in %s, line %s", id, c[2], c[3]); - } + var c = caller(); + logprint(LOG_DEBUG, "setting listener #",id," in ",c[2],":",c[3]); return id; } @@ -164,17 +162,14 @@ var values = func(hash) { return vec; } +# printlog is depricated, use logprint instead -## -# Print log messages in appropriate --log-level. -# Usage: printlog("warn", "..."); -# The underscore hash prevents helper functions/variables from -# needlessly polluting the global namespace. -# __.dbg_types = { none:0, bulk:1, debug:2, info:3, warn:4, alert:5 }; -__.log_level = __.dbg_types[getprop("/sim/logging/priority")]; -var printlog = func(level) { - if(__.dbg_types[level] >= __.log_level) call(print, arg); +var printlog = func(level, msg...) { + var c = caller(); + logprint(LOG_ALERT, "Deprecated printlog() call from ",c[2]~":"~c[3]~ + ", please use logprint instead."); + logprint([__.dbg_types[level]]~msg); } diff --git a/Nasal/input_helpers/goflight.nas b/Nasal/input_helpers/goflight.nas index 33874f5c9..dd3bc1374 100644 --- a/Nasal/input_helpers/goflight.nas +++ b/Nasal/input_helpers/goflight.nas @@ -261,7 +261,7 @@ var mcp = { watchPropertyForLED: func(prop, ledName) { if (!contains(me._ledNames, ledName)) { - printlog('warn', 'Unknown GoFlight MCP LED:' ~ ledName); + logprint(LOG_WARN, 'Unknown GoFlight MCP LED:' ~ ledName); return; } diff --git a/Nasal/modules/canvas_efis/efis.nas b/Nasal/modules/canvas_efis/efis.nas index 9dcbbf2d2..ffa445c40 100644 --- a/Nasal/modules/canvas_efis/efis.nas +++ b/Nasal/modules/canvas_efis/efis.nas @@ -48,8 +48,8 @@ var EFIS = { # object_names: vector of same size and order as display_names, containing # 3D object names for canvas placement of the DisplayUnits new: func(display_names, object_names, canvas_settings=nil) { - if (typeof(display_names) != "vector") { - printlog("error", "EFIS.new: 'display_names' not a vector!"); + if (!isvec(display_names)) { + logprint(DEV_ALERT, "EFIS.new: 'display_names' not a vector!"); return; } var obj = { @@ -63,14 +63,14 @@ var EFIS = { active_sources: [], powerN: nil, }; - if (object_names != nil and typeof(object_names) == "vector" + if (object_names != nil and isvec(object_names) and size(display_names) == size(object_names)) { foreach (var i; display_names) { append(obj.active_sources, EFIS.NO_SRC); } var settings = obj.defaultcanvas_settings; - if (canvas_settings != nil and typeof(canvas_settings) == "hash") { + if (canvas_settings != nil and ishash(canvas_settings)) { foreach (var key; keys(canvas_settings)) { settings[key] = canvas_settings[key]; } @@ -96,7 +96,7 @@ var EFIS = { #print("setDisplaySource unit "~du_id~" src "~source_id~" prev "~prev_source); if (prev_source >= 0) { if (me.source_records[prev_source] == nil) - printlog("error", "_setDisplaySource error: prev: "~prev_source~" #"~size(me.source_records)); + logprint(LOG_ALERT, "_setDisplaySource error: prev: "~prev_source~" #"~size(me.source_records)); var n = me.source_records[prev_source].visibleN; n.setValue(n.getValue() - 1); } diff --git a/Nasal/modules/canvas_efis/eicas-message-sys.nas b/Nasal/modules/canvas_efis/eicas-message-sys.nas index 5aae2f353..1a66eaefb 100644 --- a/Nasal/modules/canvas_efis/eicas-message-sys.nas +++ b/Nasal/modules/canvas_efis/eicas-message-sys.nas @@ -271,7 +271,7 @@ var MessageSystem = { addAuralAlert: func(id, filename, volume=1.0, path=nil) { if (typeof(id) == "hash") { - printlog(5, "First argument to addAuralAlert() must be a string but is a hash. Use addAuralAlerts() to pass all alerts in one hash."); + logprint(DEV_ALERT, "First argument to addAuralAlert() must be a string but is a hash. Use addAuralAlerts() to pass all alerts in one hash."); } me.sounds[id] = { path: (path == nil) ? me.sound_path : path, @@ -284,7 +284,7 @@ var MessageSystem = { addAuralAlerts: func(alert_hash) { if (typeof(alert_hash) != "hash") { - print("MessageSystem.addAuralAlerts: parameter must be a hash!"); + logprint(DEV_ALERT, "MessageSystem.addAuralAlerts: parameter must be a hash!"); return; } me.sounds = alert_hash; diff --git a/Nasal/mp_broadcast.nas b/Nasal/mp_broadcast.nas index 5457738fa..75f251149 100644 --- a/Nasal/mp_broadcast.nas +++ b/Nasal/mp_broadcast.nas @@ -125,8 +125,7 @@ BroadcastChannel.new = func (mpp_path, process, last_send : 0.0 # For the send queue }; if (enable_send and (obj.send_node == nil)) { - printlog("warn", - "BroadcastChannel invalid send node."); + logprint(LOG_WARN, "BroadcastChannel invalid send node."); return nil; } setlistener(obj.ONLINE_pp, func { diff --git a/Nasal/props.nas b/Nasal/props.nas index 9f063fbf0..3ee20b583 100644 --- a/Nasal/props.nas +++ b/Nasal/props.nas @@ -288,11 +288,11 @@ var createNodeObjectsFromHash = func (property_list, namespace = nil) { namespace = caller(1)[0]; } if (typeof(namespace) != "hash") { - printlog("warning", "createNodeObjectsFromHash: Error, namespace argument is not a hash."); + logprint(LOG_WARN, "createNodeObjectsFromHash: Error, namespace argument is not a hash."); return nil; } if (typeof(property_list) != "hash") { - printlog("warning", "createNodeObjectsFromHash: Error, property_list argument is not a hash."); + logprint(LOG_WARN, "createNodeObjectsFromHash: Error, property_list argument is not a hash."); return nil; } foreach (key; keys(property_list)) { @@ -380,7 +380,7 @@ var _cond = func(p) { if(n == "less-than-equals") return !_cond_cmp(p, 1); if(n == "greater-than-equals") return !_cond_cmp(p, -1); if(n == "property") return !!getprop(p.getValue()); - printlog("alert", "condition: invalid operator ", n); + logprint(LOG_ALERT, "condition: invalid operator ", n); dump(p); return nil; } @@ -389,7 +389,7 @@ var _cond_cmp = func(p, op) { var left = p.getChild("property", 0, 0); if(left != nil) { left = getprop(left.getValue()); } else { - printlog("alert", "condition: no left value"); + logprint(LOG_ALERT, "condition: no left value"); dump(p); return nil; } @@ -399,13 +399,13 @@ var _cond_cmp = func(p, op) { right = p.getChild("value", 0, 0); if(right != nil) { right = right.getValue(); } else { - printlog("alert", "condition: no right value"); + logprint(LOG_ALERT, "condition: no right value"); dump(p); return nil; } } if(left == nil or right == nil) { - printlog("alert", "condition: comparing with nil"); + logprint(LOG_ALERT, "condition: comparing with nil"); dump(p); return nil; } diff --git a/Nasal/route_manager.nas b/Nasal/route_manager.nas index 74f8da328..8c0eaeeea 100644 --- a/Nasal/route_manager.nas +++ b/Nasal/route_manager.nas @@ -269,7 +269,7 @@ var DefaultGPSDeleagte = { me.landingCheck = nil; # delete timer } - #printlog('info', 'saw current WP changed, now ' ~ me.flightplan.current); + #logprint(LOG_INFO, 'saw current WP changed, now ' ~ me.flightplan.current); var active = me.flightplan.currentWP(); if (active == nil) return; diff --git a/Nasal/screen.nas b/Nasal/screen.nas index f930e495b..03abfe605 100644 --- a/Nasal/screen.nas +++ b/Nasal/screen.nas @@ -561,7 +561,7 @@ _setlistener("/sim/signals/nasal-dir-initialized", func { # map ATC messages to the screen log and to the voice subsystem var map = func(type, msg, r, g, b, cond = nil) { - printlog("info", "{", type, "} ", msg); + logprint(LOG_INFO, "{", type, "} ", msg); setprop("/sim/sound/voices/" ~ type, msg); if (cond == nil or cond()) @@ -584,7 +584,7 @@ _setlistener("/sim/signals/nasal-dir-initialized", func { } m ~= "I say again: " ~ msg; atclast.setValue(m); - printlog("debug", "ATC_LAST_MESSAGE: ", m); + logprint(LOG_DEBUG, "ATC_LAST_MESSAGE: ", m); } } } diff --git a/Nasal/seaport.nas b/Nasal/seaport.nas index 81786fd55..bcba59a12 100644 --- a/Nasal/seaport.nas +++ b/Nasal/seaport.nas @@ -1,6 +1,6 @@ _setlistener("/sim/signals/nasal-dir-initialized", func { - _setlistener("/sim/presets/latitude-deg", func { - printlog("info", "*** NEW LOCATION ***"); + setlistener("/sim/presets/latitude-deg", func { + logprint(LOG_INFO, "*** NEW LOCATION ***"); settimer(func { var typ = getprop("/sim/type"); var lat = getprop("/position/latitude-deg"); diff --git a/Nasal/wildfire.nas b/Nasal/wildfire.nas index fea0e3928..74e864eaa 100644 --- a/Nasal/wildfire.nas +++ b/Nasal/wildfire.nas @@ -205,7 +205,7 @@ var parse_msg = func (source, msg) { var pos = Binary.decodeCoord(substr(msg, 6)); ignite(pos, 0); } else { - printlog("alert", "wildfire.nas: Ignored ignite event flood from " ~ + logprint(LOG_ALERT, "wildfire.nas: Ignored ignite event flood from " ~ source.getNode("callsign").getValue()); } mp_last_limited_event[i] = cur_time; @@ -790,7 +790,7 @@ CAFire.load_event_log = func (filename, skip_ahead_until) { if (!fgcommand("loadxml", props.Node.new({ filename : filename, targetnode : logbase }))) { - printlog("alert", "Wildfire ... failed loading '" ~ filename ~ "'"); + logprint(LOG_ALERT, "Wildfire ... failed loading '" ~ filename ~ "'"); return; } @@ -888,7 +888,7 @@ CAFire.update = func { me.next = 0; } if (me.cells_burning > 0) { - printlog("info", + logprint(LOG_INFO, "Wildfire: generation " ~ me.generation ~ " updating " ~ size(me.remaining_work) ~" / " ~ me.cells_created ~ " created cells. " ~ me.cells_burning ~ " burning cells."); @@ -943,7 +943,7 @@ _setlistener("/sim/signals/nasal-dir-initialized", func { Binary = mp_broadcast.Binary; - # Create configuration properties if they don't exist already. + # Create configuration properties if they do not exist already. props.globals.initNode(CA_enabled_pp, 1, "BOOL"); setlistener(CA_enabled_pp, func (n) { if (getprop("/sim/signals/reinit")) return; # Ignore resets. @@ -980,14 +980,14 @@ _setlistener("/sim/signals/nasal-dir-initialized", func { # Determine the skip-ahead-to time, if any. var time_hack = time_string_to_epoch(getprop(time_hack_pp)); if (time_hack > SimTime.current_time()) { - printlog("alert", + logprint(LOG_ALERT, "wildfire.nas: Ignored time hack " ~ (SimTime.current_time() - time_hack) ~ " seconds into the future."); # Skip ahead to current time instead. time_hack = -1; } elsif (time_hack > 0) { - printlog("alert", + logprint(LOG_ALERT, "wildfire.nas: Time hack " ~ (SimTime.current_time() - time_hack) ~ " seconds ago."); @@ -1030,7 +1030,7 @@ _setlistener("/sim/signals/nasal-dir-initialized", func { }); - printlog("info", "Wildfire ... initialized."); + logprint(LOG_INFO, "Wildfire ... initialized."); }); ###############################################################################