Commit 19383fbd authored by Claes's avatar Claes Committed by Esteban Blanc

Test log functions added

parent 273df1b0
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2020 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
#include <stdio.h>
#include <stdarg.h>
#include "co_msg.h"
#include "co_dcli.h"
#include "co_time.h"
#include "co_tst_log.h"
void tst_log::log(const char severity, const char *text, pwr_tStatus status)
{
if (!m_fp)
return;
char msg[200] = "";
char timstr[40];
time_AtoAscii(0, time_eFormat_DateAndTime, timstr, sizeof(timstr));
if (status != 0xffffffff)
msg_GetMsg(status, msg, sizeof(msg));
if (text && strcmp(msg, "") != 0)
fprintf(m_fp, "%c %s %s, %s: %s\n", severity, timstr, m_category, text, msg);
else if (text)
fprintf(m_fp, "%c %s %s, %s\n", severity, timstr, m_category, text);
else if (strcmp(msg, "") != 0)
fprintf(m_fp, "%c %s %s, %s\n", severity, timstr, m_category, msg);
else
fprintf(m_fp, "%c %s %s\n", severity, timstr, m_category);
}
void tst_log::log(const char severity, const char *text1,
const char *text2, pwr_tStatus status)
{
if (!m_fp)
return;
char msg[200] = "";
char timstr[40];
time_AtoAscii(0, time_eFormat_DateAndTime, timstr, sizeof(timstr));
if (status != 0xffffffff)
msg_GetMsg(status, msg, sizeof(msg));
if (strcmp(msg, "") != 0)
fprintf(m_fp, "%c %s %s, %s, %s: %s\n", severity, timstr, m_category, text1, text2, msg);
else
fprintf(m_fp, "%c %s %s, %s, %s\n", severity, timstr, m_category, text1, text2);
}
void tst_log::vlog(const char severity, const char *format, ...)
{
if (!m_fp)
return;
va_list ap;
char msg[200];
char timstr[40];
time_AtoAscii(0, time_eFormat_DateAndTime, timstr, sizeof(timstr));
va_start(ap, format);
vsnprintf(msg, sizeof(msg), format, ap);
va_end(ap);
fprintf(m_fp, "%c %s %s, %s\n", severity, timstr, m_category, msg);
}
tst_log::tst_log(pwr_tStatus *sts, const char *category, const char *filename)
{
*sts = TST__SUCCESS;
strncpy(m_category, category, sizeof(m_category));
dcli_translate_filename(m_filename, filename);
m_fp = fopen(m_filename, "w");
if (!m_fp)
*sts = TST__OPENFILE;
}
tst_log::~tst_log()
{
if (m_fp)
fclose(m_fp);
}
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2020 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
#ifndef co_tst_log_h
#define co_tst_log_h
/* co_tst_log.h -- Log test results */
#if defined __cplusplus
extern "C" {
#endif
#include <string.h>
#include <stdio.h>
#include "pwr.h"
#include "co_cdh.h"
#include "co_tst_msg.h"
class tst_log {
pwr_tStatus m_sts;
pwr_tFileName m_filename;
char m_category[80];
FILE *m_fp;
public:
tst_log(pwr_tStatus *sts, const char *category, const char *filename);
~tst_log();
void log(const char severity, const char *text,
pwr_tStatus status = 0xffffffff);
void log(const char severity, const char *text1,
const char *text2, pwr_tStatus status = 0xffffffff);
void vlog(const char severity, const char *format, ...);
};
#if defined __cplusplus
}
#endif
#endif
!
! ProviewR Open Source Process Control.
! Copyright (C) 2005-2020 SSAB EMEA AB.
!
! This file is part of ProviewR.
!
! This program is free software; you can redistribute it and/or
! modify it under the terms of the GNU General Public License as
! published by the Free Software Foundation, either version 2 of
! the License, or (at your option) any later version.
!
! This program is distributed in the hope that it will be useful
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with ProviewR. If not, see <http://www.gnu.org/licenses/>
!
! Linking ProviewR statically or dynamically with other modules is
! making a combined work based on ProviewR. Thus, the terms and
! conditions of the GNU General Public License cover the whole
! combination.
!
! In addition, as a special exception, the copyright holders of
! ProviewR give you permission to, from the build function in the
! ProviewR Configurator, combine ProviewR with modules generated by the
! ProviewR PLC Editor to a PLC program, regardless of the license
! terms of these modules. You may copy and distribute the resulting
! combined work under the terms of your choice, provided that every
! copy of the combined work is accompanied by a complete copy of
! the source code of ProviewR (the version used to produce the
! combined work), being distributed under the terms of the GNU
! General Public License plus this exception.
!
.facility TST,29 /prefix = TST__ !
success <Successful completion> /succ
openfile <Unable to open file> /error
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
26 SIM 26 SIM
27 REDU 27 REDU
28 MVA 28 MVA
29 TST
50 HD 50 HD
100 CDH 100 CDH
101 TIME 101 TIME
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment