使用 Progress 4GL 防止调试代码投入生产?

发布于 2024-07-19 03:41:17 字数 45 浏览 7 评论 0原文

使用 Progress 4GL 时,如何防止调试代码块意外泄漏到生产环境中?

How would you prevent chunks of debugging code from accidentally leaking into production enviroment when using Progress 4GL?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

过期情话 2024-07-26 03:41:17

我通常只发布一个特殊事件 - 调试消息。 在我的开发环境中,应用程序中有一个菜单项,它将启动一个窗口,该窗口在任何地方订阅调试消息并显示生成的任何消息。 因此,我可以将调试消息插入到我的代码中,然后如果我想查看这些消息,则打开窗口。 如果我忘记整理调试代码,那么实时用户将看不到任何消息,尽管我仍然可以打开调试窗口来查看发生了什么。

(此版本的 webspeed 只会将输出写入操作系统文件)

I usually just publish a special event - debug-message. In my dev environment there's a menu item in the application which will fire up a window which susbscribes to debug-message anywhere and displays any messages generated. So I can insert debug-messages into my code and then open the window if I want to see the messages. If I forget to tidy up the debug code then the live users don't see any messages, although I can still open the debug window to see what's going on.

( The webspeed version of this would just write the output to an OS file )

晨曦÷微暖 2024-07-26 03:41:17

如果您的测试数据库和生产数据库具有不同的名称,您可以使用以下代码:

IF DBNNAME = "TESTDB" THEN
DO:
  <DEBUG CODE>
END.

If your test database and production databases have different names, you could use this code:

IF DBNNAME = "TESTDB" THEN
DO:
  <DEBUG CODE>
END.
黑寡妇 2024-07-26 03:41:17

与我关于断言的其他答案类似,您可以设置一个包含,该包含在包含调试标志的生产站点上将为空。 在开发站点上,您只需定义该值,以便将调试代码包含在您的程序中。

通过将代码包装在预处理器中,当您将其编译到生产站点时,编译器将完全省略调试代码。

&如果已定义( debugalert ) <> 0 &然后
<代码>
&endif

然后,您可以在要包含调试代码的代码版本中使用“&global-define debug”。 不定义“debug”会导致编译器忽略代码。


/* debug.i 在生产中省略以下内容 */

&GLOBAL-DEFINE DEBUGALERT


/* test.p */
{debug.i}

DEF VAR h_ct AS INT NO-UNDO

DO h_ct = 1 TO 10:

&IF DEFINED( DEBUGALERT ) <> 0 &THEN

    MESSAGE "debug message" h_ct.
    <debug code goes here>

&ENDIF

结束。

Similar to my other answer about the assertions, you can setup an include that will be empty on production sites containing the debug flag. On development sites you just need to define the value so that your debugging code is included in your program.

By wrapping code in a preprocessor the compiler will omit the debug code altogether when you compile it onto a production site.

&if defined( debugalert ) <> 0 &then

&endif

You would then use the "&global-define debug" in versions of the code you want to contain the debug code. Not defining "debug" should cause the compiler to omit the code.


/* debug.i omit the following on production */

&GLOBAL-DEFINE DEBUGALERT


/* test.p */
{debug.i}

DEF VAR h_ct AS INT NO-UNDO

DO h_ct = 1 TO 10:

&IF DEFINED( DEBUGALERT ) <> 0 &THEN

    MESSAGE "debug message" h_ct.
    <debug code goes here>

&ENDIF

END.

挽梦忆笙歌 2024-07-26 03:41:17

解决方案基于这样的假设:开发环境具有唯一的 propath 条目,该条目在其他环境中不可用,并且代码在移动时会重新编译:

&IF DEFINED(DEBUGGING) = 0 &THEN
    &IF PROPATH MATCHES '*development*' &THEN 
        &GLOBAL-DEFINE DEBUGGING TRUE
    &ELSE
        &GLOBAL-DEFINE DEBUGGING FALSE
        &MESSAGE Remove debugging: search for DEBUG within the code. 
    &ENDIF        
&ENDIF                                

&IF DEFINED(DEBUGGING_STARTED) = 0 &THEN
    &GLOBAL-DEFINE DEBUGGING_STARTED TRUE
    IF {&DEBUGGING} THEN
    DO:
&ELSE
    END.
    &UNDEFINE DEBUGGING_STARTED
&ENDIF

用法

将文件另存为“debug”(不带扩展名)到propath指向的目录,则:

{debug}

 /* some debugging code here */

{debug/}

A solution is based on the assumption that development enviroment has a unique propath entry that is not available in other enviroments and code is recompiled when moved over:

&IF DEFINED(DEBUGGING) = 0 &THEN
    &IF PROPATH MATCHES '*development*' &THEN 
        &GLOBAL-DEFINE DEBUGGING TRUE
    &ELSE
        &GLOBAL-DEFINE DEBUGGING FALSE
        &MESSAGE Remove debugging: search for DEBUG within the code. 
    &ENDIF        
&ENDIF                                

&IF DEFINED(DEBUGGING_STARTED) = 0 &THEN
    &GLOBAL-DEFINE DEBUGGING_STARTED TRUE
    IF {&DEBUGGING} THEN
    DO:
&ELSE
    END.
    &UNDEFINE DEBUGGING_STARTED
&ENDIF

Usage

Save file as "debug" (without extension) to a directory pointed at by propath, then:

{debug}

 /* some debugging code here */

{debug/}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文