A process log is a file that records the events that occur while a process is running.

1 Process log example

This section examines an example of the use of the process log.

  • First, the process log recording is initialized.
  • Then the foreach containing the try-catch statements is launched.
  • Inside the try can execute the process that want to control, and notify in the process log.
  • Inside the catch, notify those errors that the process returns.
  • Once out of the foreach, close the process record.

Copy
<!-- ================================================================================ -->
<!-- PROCESS LOG EXAMPLE                                                              -->
<!-- ================================================================================ -->
<xsql-script>
   <body>
        <!-- ======================================================================== -->
        <!-- The process log record is initialized.                                   -->
        <!-- ======================================================================== -->
        <call name='clogproh_ini' into='clogproh_log_id'>
            <string><system.function.getName /></string>
            <null />
            <number>1</number>
        </call>

        <!-- ======================================================================== -->
        <!-- The foreach is launched.                                                 -->
        <!-- ======================================================================== -->
        <foreach>
            <select prefix='m_' first='20' >
                <columns>
                    tabname, tabid
                </columns>
                <from table='systables' />
            </select>
            <do>
                <try>
                    <body>
                        <connection.begin />

                        <!-- ======================================================== -->
                        <!-- In this section you program the process.                 -->
                        <!-- ======================================================== -->
                        <if>
                            <expr>
                                <eq><m_tabid />10</eq>
                            </expr>
                            <then>
                                <exception code='CLP_EXAMPLE' message='Throw example exception in tabid: [{0}]'>
                                    <arg><m_tabid /></arg>
                                </exception>
                            </then>
                        </if>

                        <!-- ======================================================== -->
                        <!-- Notify in the process log.                               -->
                        <!-- ======================================================== -->
                        <call name='clogprol_set' >
                            <clogproh_log_id />
                            <string><string>Process tabname: </string><m_tabname/></string>
                            <null />
                            <null />
                            <null />
                            <null />
                            <null />
                            <m_tabid />
                            <null  />
                        </call>

                        <connection.commit />
                    </body>
                    <catch>
                        <connection.rollback />

                        <!-- ======================================================== -->
                        <!-- Save the error in the process log.                       -->
                        <!-- ======================================================== -->
                        <call name='clogprol_set' >
                            <clogproh_log_id />
                            <error.message />
                            <error.sqlcode />
                            <null />
                            <null />
                            <null />
                            <null />
                            <m_tabid />
                            <null  />
                        </call>
                    </catch>
                </try>
            </do>
        </foreach>

        <!-- ======================================================================== -->
        <!-- Close the process record.                                                -->
        <!-- ======================================================================== -->
        <call name='clogproh_fin' >
            <clogproh_log_id />
        </call>

        <return><clogproh_log_id /></return>
    </body>
</xsql-script>
Copy
/**
 * PROCESS LOG EXAMPLE
 */ 
    /**
     * The process log record is initialized.
     */
    mObjProcLog = require('clogproh');
    
    Ax.db.beginWork();
    mObjProcLog.start('clogproh_example', null, 1);
    Ax.db.commitWork();

    mIntLogId = mObjProcLog.getLogId();        

    let mRsSystables = Ax.db.executeQuery(`
        <select first='20' >
            <columns>
                tabname, tabid
            </columns>
            <from table='systables' />
        </select>`);
    
    /**
     * The foreach is launched.
     */
    for (let mRowSystables of mRsSystables) {
        try { 
            Ax.db.beginWork();

            if (mRowSystables.tabid == 10) {
                throw new Ax.ext.Exception('CLP_EXAMPLE',
                    'Throw example exception in tabid: [${tabid}].',
                    {tabid : mRowSystables.tabid}
                );
            }

            /**
             * Notify in the process log.   
             * The relation between parameters and columns from clogprol table are:
             * 
             * mObjProcLog.log(log_message, log_err_code, log_err_code1, log_err_stat, 
             *                 log_fieldc_1, log_fieldc_2, log_fieldn_1, log_fieldn_2);
             */
            mObjProcLog.log(`Process tabid: [${mRowSystables.tabid}]`, 
                null, null, null, null, null, null, null);

            Ax.db.commitWork();

        } catch(e) {
            Ax.db.rollbackWork();
            /**
             * Save the error in the process log.
             * The relation between parameters and columns from clogprol table are:
             * 
             * mObjProcLog.err(e, e.message, log_fieldc_1, log_fieldc_2, log_fieldn_1,
             *                 log_fieldn_2);
             */
            mObjProcLog.err(e, e.message, null, null, null, null);
        }
    }

    /**
     * Close the process record. 
     */
    mObjProcLog.end();

    return mIntLogId;