Hi Anders Widell,

 >>Using a standardized format means that OpenSAF can more easily be 
used together with third-party log servers and log processing tools.

I know the  complexity of implementing , but i putting my proposal :

Even our  TRACE`s are not formatted according to the protocol described 
in rfc5424, but they have  TRACE level (T5, T8, T2 )

and any way we are using  separate process `osaftransportd` for MDS 
loging,  so why don't we use  TRACE`s even for  MDS  logging and let us 
have common logic
at  TRACE library which formatted according to the protocol described in 
rfc5424 based on  exported variable like  `export LOG_FARMAT_RFC5424=true`

-AVM


On 11/2/2016 4:59 PM, Anders Widell wrote:
> See replies inline, marked AndersW>.
>
> regards,
>
> Anders Widell
>
>
> On 11/02/2016 11:16 AM, A V Mahesh wrote:
>> Hi Anders Widell,
>>
>> Thanks the attached patches works. Following are my initial comments:
>>
>> 1) Based on the current format , user will not be able to 
>> distinguished the  category of CRITICAL  , ERR , NOTIFY  , INFO , DBG
> AndersW> You can distinguish them, but the priority level is presented 
> in a numerical format which arguably is not so human-readable. The 
> reason is that the messages are formatted according to the protocol 
> described in rfc5424. Using a standardized format means that OpenSAF 
> can more easily be used together with third-party log servers and log 
> processing tools. I supposed I could translate the log priority level 
> into a human-readable string before writing the log messages to disk. 
> But this would mean that the format on disk will no longer comply with 
> the rfc, and it would also cost some performance. In most cases the 
> MDS log messages will be rotated away without anyone ever reading them 
> - so instead I would propose to create an offline log parser that can 
> translate the log priority level. This tool could later be extended 
> with filtering capabilities etc. What do you think?
>>
>> ================================================================================================================================
>>  
>>
>>
>> <135>1 2016-11-02T15:37:52.179638+05:30 SC-1 osafimmloadd 30875 41517 
>> - << mcm_msg_encode_full_or_flat_and_send
>> <134>1 2016-11-02T15:37:52.179663+05:30 SC-1 osafimmloadd 30875 41518 
>> - MDTM: User Sending Data lenght=384 From svc_id = IMMA_OM(26) to 
>> svc_id = IMMND(25)
>> <135>1 2016-11-02T15:37:52.179691+05:30 SC-1 osafimmloadd 30875 41519 
>> - MDTM:Sending message with Service Seqno=695, TO 
>> Dest_Tipc_id=<0x01001001:821559312>
>> <134>1 2016-11-02T15:37:52.179716+05:30 SC-1 osafimmloadd 30875 41520 
>> - MDTM: TIPC Sending Len=423
>> <134>1 2016-11-02T15:37:52.179753+05:30 SC-1 osafimmnd 30642 117944 - 
>> MDTM: Data received: Processing data
>> <135>1 2016-11-02T15:37:52.179768+05:30 SC-1 osafimmnd 30642 117945 - 
>> MDTM: size: 423  anc is NULL
>> <135>1 2016-11-02T15:37:52.179777+05:30 SC-1 osafimmnd 30642 117946 - 
>> >> mds_svc_tbl_get_svc_h
>>
>> ================================================================================================================================
>>  
>>
>>
>> We use to have it *DBG/**INFO/***ERR/*****NOTIFY ***prefix, let us 
>> restore it , other wise it become complex to debug , when 
>> `MDS_LOG_LEVEL=5`
>>
>> ================================================================================================================================
>>  
>>
>>
>> Nov 15  3:10:10.381033 osafimmnd[3912] *DBG *|MDTM: Recd Unfragmented 
>> message with SVC Seq num =810, from src Adest = <72075197334002405>
>> Nov 15  3:10:10.381051 osafimmnd[3912] *INFO *|MDTM: User Recd msg 
>> len=56595
>>
>> Oct  6 11:57:20.040978 osafamfnd[4492] *ERR *|MCM_API : 
>> vdest_chg_role : VDEST id = 0 Doesn't exist
>> Oct  6 11:57:20.041824 osafamfnd[4492] *NOTIFY *|MDTM: install_tipc : 
>> svc_id = IMMA_OM(26), vdest=65535
>>
>> ================================================================================================================================
>>  
>>
>>
>> 2)  The new format should be explained in some README `<135>1 
>> 2016-11-02T15:37:52.179638+05:30 SC-1 osafimmloadd 30875 41517`
> AndersW> The format is explained in rfc5424. I can insert a reference 
> to the RFC in some README file.
>>
>>
>> -AVM
>>
>>
>> On 11/2/2016 2:44 PM, Anders Widell wrote:
>>> Hi!
>>>
>>> I tried applying the patches on the latest from opensaf-staging, and 
>>> building with GCC 4.8.4. I works for me, so it could be that the 
>>> patches have been corrupted by the mail system. Please find the 
>>> patches attached in a tar file. I have removed the pref variable in 
>>> the attached patches, as you suggested.
>>>
>>> regards,
>>> Anders Widell
>>>
>>>
>>> On 11/02/2016 06:51 AM, A V Mahesh wrote:
>>>> Hi Anders Widell,
>>>>
>>>> Can you please re-send the v1 patches fixing following three issues 
>>>> , so that I can proceed for test.
>>>>
>>>>
>>>> 1) build fails with gcc version 4.8.3
>>>>
>>>> libtool: compile:  g++ -DHAVE_CONFIG_H -I. -I../../../.. 
>>>> -I../../../.. -I../../../../osaf/libs/saf/include 
>>>> -I../../../../osaf/libs/core/include 
>>>> -I../../../../osaf/libs/core/leap/include 
>>>> -I../../../../osaf/libs/core/mds/include 
>>>> -I../../../../osaf/libs/core/common/include 
>>>> -I../../../../osaf/libs/core/cplusplus -std=gnu++11 -Wall 
>>>> -fno-strict-aliasing -Werror -fPIC -D__STDC_FORMAT_MACROS 
>>>> -D_FORTIFY_SOURCE=2 -fstack-protector -DINTERNAL_VERSION_ID=\"\" 
>>>> -O2 -g -m64 -fmessage-length=0 -D_FORTIFY_SOURCE=2 
>>>> -fstack-protector -funwind-tables -fasynchronous-unwind-tables -MT 
>>>> libmds_la-mds_log.lo -MD -MP -MF .deps/libmds_la-mds_log.Tpo -c 
>>>> mds_log.cc  -fPIC -DPIC -o .libs/libmds_la-mds_log.o
>>>> mds_log.cc:37:50: fatal error: 
>>>> osaf/libs/core/cplusplus/base/buffer.h: No such file or directory
>>>>  #include "osaf/libs/core/cplusplus/base/buffer.h"
>>>>
>>>> 2) [PATCH 3 of 3] need to be re-based  It fails on latest stating ( 
>>>> but applies clean on change-set : 8200 )
>>>>
>>>> 3)  We can remove   pref[50] varible
>>>>
>>>> --- a/osaf/libs/core/mds/mds_main.c
>>>> +++ b/osaf/libs/core/mds/mds_main.c
>>>>
>>>> @@ -558,7 +557,7 @@ uint32_t mds_lib_req(NCS_LIB_REQ_INFO *r
>>>>               char buff[50], pref[50];
>>>>
>>>> -AVM
>>>>
>>>>
>>>> On 11/2/2016 10:47 AM, A V Mahesh wrote:
>>>>> Hi Anders Widell,
>>>>>
>>>>> I used  hg command  patches applied  cleanly on `change-set : 8200` .
>>>>>
>>>>> But for your information  [PATCH 3 of 3] need to be re-based , it 
>>>>> fails
>>>>> on  latest stating.
>>>>>
>>>>> =============================================================================
>>>>>  
>>>>>
>>>>>
>>>>> # hg import  /avm/2015_1.patch /avm/2015_2.patch /avm/2015_3.patch
>>>>> --no-commit
>>>>> applying /avm/2015_1.patch
>>>>> applying /avm/2015_2.patch
>>>>> applied to working directory
>>>>> applying /avm/2015_3.patch
>>>>> patching file 
>>>>> osaf/services/infrastructure/dtms/scripts/osaf-transport.in
>>>>> Hunk #1 FAILED at 33
>>>>> Hunk #2 FAILED at 99
>>>>> 2 out of 2 hunks FAILED -- saving rejects to file
>>>>> osaf/services/infrastructure/dtms/scripts/osaf-transport.in.rej
>>>>> unable to find 
>>>>> 'osaf/services/infrastructure/dtms/transport/Makefile.am'
>>>>> for patching
>>>>> 2 out of 2 hunks FAILED -- saving rejects to file
>>>>> osaf/services/infrastructure/dtms/transport/Makefile.am.rej
>>>>> unable to find 
>>>>> 'osaf/services/infrastructure/dtms/transport/main.cc' for
>>>>> patching
>>>>> 2 out of 2 hunks FAILED -- saving rejects to file
>>>>> osaf/services/infrastructure/dtms/transport/main.cc.rej
>>>>> unable to find
>>>>> 'osaf/services/infrastructure/dtms/transport/transport_monitor.cc' 
>>>>> for
>>>>> patching
>>>>> 3 out of 3 hunks FAILED -- saving rejects to file
>>>>> osaf/services/infrastructure/dtms/transport/transport_monitor.cc.rej
>>>>> unable to find
>>>>> 'osaf/services/infrastructure/dtms/transport/transport_monitor.h' for
>>>>> patching
>>>>> 4 out of 4 hunks FAILED -- saving rejects to file
>>>>> osaf/services/infrastructure/dtms/transport/transport_monitor.h.rej
>>>>> osaf/services/infrastructure/dtms/transport/Makefile.am: No such 
>>>>> file or
>>>>> directory
>>>>> osaf/services/infrastructure/dtms/transport/main.cc: No such file or
>>>>> directory
>>>>> osaf/services/infrastructure/dtms/transport/transport_monitor.cc: No
>>>>> such file or directory
>>>>> osaf/services/infrastructure/dtms/transport/transport_monitor.h: 
>>>>> No such
>>>>> file or directory
>>>>> abort: patch failed to apply
>>>>>
>>>>> =============================================================================
>>>>>  
>>>>>
>>>>>
>>>>> -AVM
>>>>>
>>>>> On 11/1/2016 2:50 PM, Anders Widell wrote:
>>>>>> Hi!
>>>>>>
>>>>>> I tried the patches that were sent out on the list, and they apply
>>>>>> cleanly for me. Maybe your version of the patch command does not
>>>>>> support renaming files? I tried and it works with version 2.7.1 
>>>>>> of the
>>>>>> patch command. Could you try with patching a newer version of the
>>>>>> command, or by using Mercurial instead, e.g. hg qimport; hg qpush ?
>>>>>>
>>>>>> regards,
>>>>>>
>>>>>> Anders Widell
>>>>>>
>>>>>>
>>>>>> On 11/01/2016 09:59 AM, A V Mahesh wrote:
>>>>>>> Hi Anders Widell,
>>>>>>>
>>>>>>> It seems you missed to do `hg add osaf/libs/core/mds/mds_log.cc` ,
>>>>>>> while trying to apply  [PATCH 2 of 3]
>>>>>>>
>>>>>>> I getting following error , can you please send the updated patch.
>>>>>>>
>>>>>>> ===========================================================
>>>>>>>
>>>>>>> # patch -p1 </avm/[PATCH 2 of 3].patch
>>>>>>> can't find file to patch at input line 4
>>>>>>> Perhaps you used the wrong -p or --strip option?
>>>>>>> The text leading up to this was:
>>>>>>> --------------------------
>>>>>>> |diff --git a/osaf/libs/core/mds/mds_log.cc
>>>>>>> b/osaf/libs/core/mds/mds_log.cc
>>>>>>> |--- a/osaf/libs/core/mds/mds_log.cc
>>>>>>> |+++ b/osaf/libs/core/mds/mds_log.cc
>>>>>>> --------------------------
>>>>>>> File to patch:
>>>>>>>
>>>>>>> ===========================================================
>>>>>>> -AVM
>>>>>>>
>>>>>>>
>>>>>>> On 10/19/2016 5:18 PM, Anders Widell wrote:
>>>>>>>> osaf/libs/core/mds/Makefile.am |    2 +-
>>>>>>>>    osaf/libs/core/mds/include/mds_dt2c.h |    3 -
>>>>>>>>    osaf/libs/core/mds/include/mds_log.h  |   59 +++--
>>>>>>>>    osaf/libs/core/mds/mds_dt_tipc.c      |    5 +-
>>>>>>>>    osaf/libs/core/mds/mds_log.cc         |  369
>>>>>>>> +++++++++++++++++----------------
>>>>>>>>    osaf/libs/core/mds/mds_main.c         |    3 +-
>>>>>>>>    6 files changed, 228 insertions(+), 213 deletions(-)
>>>>>>>>
>>>>>>>>
>>>>>>>> Convert the mds_log.c file to C++ so that it can use C++ classes
>>>>>>>> without the
>>>>>>>> need for any wrappers.
>>>>>>>>
>>>>>>>> diff --git a/osaf/libs/core/mds/Makefile.am
>>>>>>>> b/osaf/libs/core/mds/Makefile.am
>>>>>>>> --- a/osaf/libs/core/mds/Makefile.am
>>>>>>>> +++ b/osaf/libs/core/mds/Makefile.am
>>>>>>>> @@ -37,7 +37,7 @@ libmds_la_SOURCES = \
>>>>>>>>        mds_papi.c \
>>>>>>>>        mds_c_sndrcv.c \
>>>>>>>>        mds_c_api.c \
>>>>>>>> -    mds_log.c \
>>>>>>>> +    mds_log.cc \
>>>>>>>>        ncs_ada.c \
>>>>>>>>        ncs_mda.c \
>>>>>>>>        ncs_vda.c
>>>>>>>> diff --git a/osaf/libs/core/mds/include/mds_dt2c.h
>>>>>>>> b/osaf/libs/core/mds/include/mds_dt2c.h
>>>>>>>> --- a/osaf/libs/core/mds/include/mds_dt2c.h
>>>>>>>> +++ b/osaf/libs/core/mds/include/mds_dt2c.h
>>>>>>>> @@ -316,9 +316,6 @@ typedef struct mds_mbx_evt_info {
>>>>>>>>    /* ******************************************** */
>>>>>>>>    /* ******************************************** */
>>>>>>>>    -/* Initialize Logging */
>>>>>>>> -extern uint32_t mds_log_init(char *log_file_name, char 
>>>>>>>> *line_prefix);
>>>>>>>> -
>>>>>>>>    /* extern gl_mds_checksum */
>>>>>>>>    extern uint32_t gl_mds_checksum;
>>>>>>>>    diff --git a/osaf/libs/core/mds/include/mds_log.h
>>>>>>>> b/osaf/libs/core/mds/include/mds_log.h
>>>>>>>> --- a/osaf/libs/core/mds/include/mds_log.h
>>>>>>>> +++ b/osaf/libs/core/mds/include/mds_log.h
>>>>>>>> @@ -22,39 +22,50 @@
>>>>>>>> ******************************************************************************
>>>>>>>>  
>>>>>>>>
>>>>>>>>
>>>>>>>>      */
>>>>>>>>    -#ifndef _MDS_LOG_H
>>>>>>>> -#define _MDS_LOG_H
>>>>>>>> +#ifndef OSAF_LIBS_CORE_MDS_INCLUDE_MDS_LOG_H_
>>>>>>>> +#define OSAF_LIBS_CORE_MDS_INCLUDE_MDS_LOG_H_
>>>>>>>>    -#include <ncsgl_defs.h>
>>>>>>>> -#include "ncs_lib.h"
>>>>>>>> +#include <stdint.h>
>>>>>>>> +
>>>>>>>> +#ifdef  __cplusplus
>>>>>>>> +extern "C" {
>>>>>>>> +#endif
>>>>>>>>      /* Logging utility functions  - Phani */
>>>>>>>>    -extern uint32_t gl_mds_log_level;
>>>>>>>> +extern int gl_mds_log_level;
>>>>>>>>    -#define NCSMDS_LC_CRITICAL       1
>>>>>>>> -#define NCSMDS_LC_ERR            2
>>>>>>>> -#define NCSMDS_LC_NOTIFY         3
>>>>>>>> -#define NCSMDS_LC_INFO           4
>>>>>>>> -#define NCSMDS_LC_DBG            5
>>>>>>>> +enum {
>>>>>>>> +  NCSMDS_LC_CRITICAL = 1,
>>>>>>>> +  NCSMDS_LC_ERR = 2,
>>>>>>>> +  NCSMDS_LC_NOTIFY = 3,
>>>>>>>> +  NCSMDS_LC_INFO = 4,
>>>>>>>> +  NCSMDS_LC_DBG = 5
>>>>>>>> +};
>>>>>>>>    -#define m_MDS_LOG_CRITICAL  if (gl_mds_log_level <
>>>>>>>> NCSMDS_LC_CRITICAL) {} else log_mds_critical
>>>>>>>> -
>>>>>>>> -#define m_MDS_LOG_ERR if (gl_mds_log_level < NCSMDS_LC_ERR) {} 
>>>>>>>> else
>>>>>>>> log_mds_err
>>>>>>>> -
>>>>>>>> -#define m_MDS_LOG_NOTIFY if (gl_mds_log_level < NCSMDS_LC_NOTIFY)
>>>>>>>> {} else log_mds_notify
>>>>>>>> -
>>>>>>>> -#define m_MDS_LOG_INFO if (gl_mds_log_level < NCSMDS_LC_INFO) {}
>>>>>>>> else log_mds_info
>>>>>>>> -
>>>>>>>> -#define m_MDS_LOG_DBG if (gl_mds_log_level < NCSMDS_LC_DBG) {} 
>>>>>>>> else
>>>>>>>> log_mds_dbg
>>>>>>>> +#define m_MDS_LOG_CRITICAL log_mds_critical
>>>>>>>> +#define m_MDS_LOG_ERR log_mds_err
>>>>>>>> +#define m_MDS_LOG_NOTIFY log_mds_notify
>>>>>>>> +#define m_MDS_LOG_INFO log_mds_info
>>>>>>>> +#define m_MDS_LOG_DBG log_mds_dbg
>>>>>>>>      #define m_MDS_ENTER() m_MDS_LOG_DBG(">> %s", __FUNCTION__)
>>>>>>>>    #define m_MDS_LEAVE() m_MDS_LOG_DBG("<< %s", __FUNCTION__)
>>>>>>>>    -extern void log_mds_dbg(char *fmt, ...);
>>>>>>>> -extern void log_mds_info(char *fmt, ...);
>>>>>>>> -extern void log_mds_notify(char *fmt, ...);
>>>>>>>> -extern void log_mds_err(char *fmt, ...);
>>>>>>>> -extern void log_mds_critical(char *fmt, ...);
>>>>>>>> +uint32_t mds_log_init(const char *log_file_name);
>>>>>>>> +void log_mds_dbg(const char *fmt, ...)
>>>>>>>> +    __attribute__ ((format(printf, 1, 2)));
>>>>>>>> +void log_mds_info(const char *fmt, ...)
>>>>>>>> +    __attribute__ ((format(printf, 1, 2)));
>>>>>>>> +void log_mds_notify(const char *fmt, ...)
>>>>>>>> +    __attribute__ ((format(printf, 1, 2)));
>>>>>>>> +void log_mds_err(const char *fmt, ...)
>>>>>>>> +    __attribute__ ((format(printf, 1, 2)));
>>>>>>>> +void log_mds_critical(const char *fmt, ...)
>>>>>>>> +    __attribute__ ((format(printf, 1, 2)));
>>>>>>>>    +#ifdef  __cplusplus
>>>>>>>> +}
>>>>>>>>    #endif
>>>>>>>> +
>>>>>>>> +#endif  // OSAF_LIBS_CORE_MDS_INCLUDE_MDS_LOG_H_
>>>>>>>> diff --git a/osaf/libs/core/mds/mds_dt_tipc.c
>>>>>>>> b/osaf/libs/core/mds/mds_dt_tipc.c
>>>>>>>> --- a/osaf/libs/core/mds/mds_dt_tipc.c
>>>>>>>> +++ b/osaf/libs/core/mds/mds_dt_tipc.c
>>>>>>>> @@ -31,6 +31,7 @@
>>>>>>>>    #include "ncssysf_tsk.h"
>>>>>>>>    #include "ncssysf_mem.h"
>>>>>>>>    +#include <inttypes.h>
>>>>>>>>    #include <stdbool.h>
>>>>>>>>    #include <stdlib.h>
>>>>>>>>    #include <sched.h>
>>>>>>>> @@ -1107,12 +1108,12 @@ static uint32_t mdtm_process_discovery_e
>>>>>>>>                    m_MDS_LOG_INFO("MDTM: Raising the NODE UP event
>>>>>>>> for NODE id = %d", node_id);
>>>>>>>>                    uint32_t up_node_id;
>>>>>>>>                    if ((up_node_id =
>>>>>>>> m_MDS_GET_NODE_ID_FROM_ADEST(m_MDS_GET_ADEST)) == node_id) {
>>>>>>>> -                    m_MDS_LOG_INFO("MDTM:NODE_UP for
>>>>>>>> subtn_ref_val:%lu node_name:%s, node_id:%u addr_family:%d ",
>>>>>>>> +                    m_MDS_LOG_INFO("MDTM:NODE_UP for
>>>>>>>> subtn_ref_val:%" PRIu64 " node_name:%s, node_id:%u 
>>>>>>>> addr_family:%d ",
>>>>>>>> (uint64_t)subtn_ref_val,gl_mds_mcm_cb->node_name, node_id, 
>>>>>>>> AF_TIPC);
>>>>>>>>                        return mds_mcm_node_up(svc_hdl, node_id, 
>>>>>>>> NULL,
>>>>>>>> AF_TIPC, gl_mds_mcm_cb->node_name);
>>>>>>>>                    } else {
>>>>>>>>    -                    m_MDS_LOG_INFO("MDTM:NODE_UP for
>>>>>>>> subtn_ref_val:%lu node_name:%s, node_id:%u addr_family:%d ",
>>>>>>>> +                    m_MDS_LOG_INFO("MDTM:NODE_UP for
>>>>>>>> subtn_ref_val:%" PRIu64 " node_name:%s, node_id:%u 
>>>>>>>> addr_family:%d ",
>>>>>>>> (uint64_t)subtn_ref_val, "REMOTE_NODE", node_id, AF_TIPC);
>>>>>>>>                        return mds_mcm_node_up(svc_hdl, node_id, 
>>>>>>>> NULL,
>>>>>>>> AF_TIPC, "REMOTE_NODE");
>>>>>>>>                    }
>>>>>>>> diff --git a/osaf/libs/core/mds/mds_log.c
>>>>>>>> b/osaf/libs/core/mds/mds_log.cc
>>>>>>>> rename from osaf/libs/core/mds/mds_log.c
>>>>>>>> rename to osaf/libs/core/mds/mds_log.cc
>>>>>>>> --- a/osaf/libs/core/mds/mds_log.c
>>>>>>>> +++ b/osaf/libs/core/mds/mds_log.cc
>>>>>>>> @@ -19,233 +19,240 @@
>>>>>>>> ..............................................................................
>>>>>>>>  
>>>>>>>>
>>>>>>>>
>>>>>>>>      DESCRIPTION:  MDS LOG APIs
>>>>>>>> -******************************************************************************
>>>>>>>>  
>>>>>>>>
>>>>>>>>
>>>>>>>> -*/
>>>>>>>> +
>>>>>>>> ******************************************************************************
>>>>>>>>  
>>>>>>>>
>>>>>>>> +  */
>>>>>>>>    -#include "mds_log.h"
>>>>>>>> -#include "mds_dt2c.h"        /* Include for arch-word 
>>>>>>>> definitions */
>>>>>>>> +#include "osaf/libs/core/mds/include/mds_log.h"
>>>>>>>> +#include <sys/time.h>
>>>>>>>> +#include <time.h>
>>>>>>>> +#include <unistd.h>
>>>>>>>> +#include <cstdarg>
>>>>>>>> +#include <cstdio>
>>>>>>>> +#include <cstring>
>>>>>>>> +#include "osaf/libs/core/include/mds_papi.h"
>>>>>>>> +#include "osaf/libs/core/include/ncsgl_defs.h"
>>>>>>>> +#include "osaf/libs/core/mds/include/mds_dt2c.h"
>>>>>>>>    -static char *lf = NULL;
>>>>>>>> +constexpr static const size_t kMaxMdsFileNameLen = 256;
>>>>>>>>      static void log_mds(const char *str);
>>>>>>>> +
>>>>>>>> +int gl_mds_log_level = 3;
>>>>>>>> +static char *lf = nullptr;
>>>>>>>>    static char process_name[MDS_MAX_PROCESS_NAME_LEN];
>>>>>>>> +static char mds_log_fname[kMaxMdsFileNameLen];
>>>>>>>> /*****************************************************
>>>>>>>>     Function NAME: get_process_name()
>>>>>>>>     Returns : <process_name>[<pid> or <tipc_port_ref>]
>>>>>>>> *****************************************************/
>>>>>>>> -static void get_process_name(void)
>>>>>>>> -{
>>>>>>>> -    char pid_path[1024];
>>>>>>>> -    uint32_t process_id = getpid();
>>>>>>>> -    char *token, *saveptr;
>>>>>>>> -    char *pid_name = NULL;
>>>>>>>> +static void get_process_name() {
>>>>>>>> +  char pid_path[1024];
>>>>>>>> +  uint32_t process_id = getpid();
>>>>>>>> +  char *token, *saveptr;
>>>>>>>> +  char *pid_name = nullptr;
>>>>>>>>    -    sprintf(pid_path, "/proc/%d/cmdline", process_id);
>>>>>>>> -    FILE* f = fopen(pid_path,"r");
>>>>>>>> -    if(f){
>>>>>>>> -        size_t size;
>>>>>>>> -        size = fread(pid_path, sizeof(char), 1024, f);
>>>>>>>> -        if(size>0){
>>>>>>>> -            if('\n' == pid_path[size-1])
>>>>>>>> -                pid_path[size-1]='\0';
>>>>>>>> -        }
>>>>>>>> -        fclose(f);
>>>>>>>> -    }
>>>>>>>> -    token = strtok_r(pid_path, "/", &saveptr);
>>>>>>>> -    while( token != NULL )
>>>>>>>> -    {
>>>>>>>> -        pid_name = token;
>>>>>>>> -        token = strtok_r(NULL, "/", &saveptr);
>>>>>>>> -    }
>>>>>>>> -    snprintf(process_name, MDS_MAX_PROCESS_NAME_LEN, "%s[%d]",
>>>>>>>> pid_name, process_id);
>>>>>>>> -    return;
>>>>>>>> +  snprintf(pid_path, sizeof(pid_path), "/proc/%d/cmdline",
>>>>>>>> process_id);
>>>>>>>> +  FILE* f = fopen(pid_path, "r");
>>>>>>>> +  if (f) {
>>>>>>>> +    size_t size;
>>>>>>>> +    size = fread(pid_path, sizeof(char), 1024, f);
>>>>>>>> +    if (size > 0) {
>>>>>>>> +      if ('\n' == pid_path[size-1])
>>>>>>>> +        pid_path[size-1] = '\0';
>>>>>>>> +    }
>>>>>>>> +    fclose(f);
>>>>>>>> +  }
>>>>>>>> +  token = strtok_r(pid_path, "/", &saveptr);
>>>>>>>> +  while (token != nullptr) {
>>>>>>>> +    pid_name = token;
>>>>>>>> +    token = strtok_r(nullptr, "/", &saveptr);
>>>>>>>> +  }
>>>>>>>> +  snprintf(process_name, MDS_MAX_PROCESS_NAME_LEN, "%s[%d]", 
>>>>>>>> pid_name,
>>>>>>>> +           process_id);
>>>>>>>> +  return;
>>>>>>>>    }
>>>>>>>> /*******************************************************************************
>>>>>>>>  
>>>>>>>>
>>>>>>>>
>>>>>>>> -* Funtion Name   :    mds_log_init
>>>>>>>> -*
>>>>>>>> -* Purpose        :
>>>>>>>> -*
>>>>>>>> -* Return Value   :    None
>>>>>>>> -*
>>>>>>>> -*******************************************************************************/
>>>>>>>>  
>>>>>>>>
>>>>>>>>
>>>>>>>> -#define MAX_MDS_FNAME_LEN  256
>>>>>>>> -static char mds_log_fname[MAX_MDS_FNAME_LEN];
>>>>>>>> + * Funtion Name   :    mds_log_init
>>>>>>>> + *
>>>>>>>> + * Purpose        :
>>>>>>>> + *
>>>>>>>> + * Return Value   :    None
>>>>>>>> + *
>>>>>>>> +
>>>>>>>> *******************************************************************************/
>>>>>>>>  
>>>>>>>>
>>>>>>>> +uint32_t mds_log_init(const char *log_file_name) {
>>>>>>>> +  FILE *fh;
>>>>>>>> +  memset(process_name, 0, MDS_MAX_PROCESS_NAME_LEN);
>>>>>>>> +  tzset();
>>>>>>>> +  get_process_name();
>>>>>>>>    -uint32_t mds_log_init(char *log_file_name, char *line_prefix)
>>>>>>>> -{
>>>>>>>> -    FILE *fh;
>>>>>>>> -    memset(process_name, 0, MDS_MAX_PROCESS_NAME_LEN);
>>>>>>>> -    tzset();
>>>>>>>> -    get_process_name();
>>>>>>>> +  if (lf != nullptr)
>>>>>>>> +    return NCSCC_RC_FAILURE;
>>>>>>>>    -    if (lf != NULL)
>>>>>>>> -        return NCSCC_RC_FAILURE;
>>>>>>>> +  if (strlen(log_file_name) >= kMaxMdsFileNameLen)
>>>>>>>> +    return NCSCC_RC_FAILURE;
>>>>>>>>    -    if (strlen(log_file_name) >= MAX_MDS_FNAME_LEN)
>>>>>>>> -        return NCSCC_RC_FAILURE;
>>>>>>>> +  snprintf(mds_log_fname, sizeof(mds_log_fname), "%s", 
>>>>>>>> log_file_name);
>>>>>>>>    -    strcpy(mds_log_fname, log_file_name);
>>>>>>>> +  lf = mds_log_fname;
>>>>>>>>    -    lf = mds_log_fname;
>>>>>>>> +  if ((fh = fopen(lf, "a+")) != nullptr) {
>>>>>>>> +    fclose(fh);
>>>>>>>> +    log_mds_notify("BEGIN MDS LOGGING| PID=<%s> |
>>>>>>>> ARCHW=%x|64bit=%zu\n",
>>>>>>>> +                   process_name, MDS_SELF_ARCHWORD,
>>>>>>>> MDS_WORD_SIZE_TYPE);
>>>>>>>> +  }
>>>>>>>>    -    if ((fh = fopen(lf, "a+")) != NULL) {
>>>>>>>> -        fclose(fh);
>>>>>>>> -        log_mds_notify("BEGIN MDS LOGGING| PID=<%s> |
>>>>>>>> ARCHW=%x|64bit=%ld\n",
>>>>>>>> -                process_name, MDS_SELF_ARCHWORD,
>>>>>>>> (long)MDS_WORD_SIZE_TYPE);
>>>>>>>> -    }
>>>>>>>> -
>>>>>>>> -    return NCSCC_RC_SUCCESS;
>>>>>>>> +  return NCSCC_RC_SUCCESS;
>>>>>>>>    }
>>>>>>>> /*******************************************************************************
>>>>>>>>  
>>>>>>>>
>>>>>>>>
>>>>>>>> -* Funtion Name   :    log_mds_critical
>>>>>>>> -*
>>>>>>>> -* Purpose        :
>>>>>>>> -*
>>>>>>>> -* Return Value   :    None
>>>>>>>> -*
>>>>>>>> -*******************************************************************************/
>>>>>>>>  
>>>>>>>>
>>>>>>>>
>>>>>>>> -void log_mds_critical(char *fmt, ...)
>>>>>>>> -{
>>>>>>>> -    char str[MDS_MAX_PROCESS_NAME_LEN + 32];
>>>>>>>> -    int i;
>>>>>>>> -    va_list ap;
>>>>>>>> + * Funtion Name   :    log_mds_critical
>>>>>>>> + *
>>>>>>>> + * Purpose        :
>>>>>>>> + *
>>>>>>>> + * Return Value   :    None
>>>>>>>> + *
>>>>>>>> +
>>>>>>>> *******************************************************************************/
>>>>>>>>  
>>>>>>>>
>>>>>>>> +void log_mds_critical(const char *fmt, ...) {
>>>>>>>> +  if (gl_mds_log_level < NCSMDS_LC_CRITICAL) return;
>>>>>>>> +  char str[MDS_MAX_PROCESS_NAME_LEN + 32];
>>>>>>>> +  int i;
>>>>>>>> +  va_list ap;
>>>>>>>>    -    i = snprintf(str, sizeof(str), "%s CRITICAL |", 
>>>>>>>> process_name);
>>>>>>>> -    va_start(ap, fmt);
>>>>>>>> -    vsnprintf(str + i, sizeof(str) - i, fmt, ap);
>>>>>>>> -    va_end(ap);
>>>>>>>> -    log_mds(str);
>>>>>>>> +  i = snprintf(str, sizeof(str), "%s CRITICAL  |", process_name);
>>>>>>>> +  va_start(ap, fmt);
>>>>>>>> +  vsnprintf(str + i, sizeof(str) - i, fmt, ap);
>>>>>>>> +  va_end(ap);
>>>>>>>> +  log_mds(str);
>>>>>>>>    }
>>>>>>>> /*******************************************************************************
>>>>>>>>  
>>>>>>>>
>>>>>>>>
>>>>>>>> -* Funtion Name   :    log_mds_err
>>>>>>>> -*
>>>>>>>> -* Purpose        :
>>>>>>>> -*
>>>>>>>> -* Return Value   :    None
>>>>>>>> -*
>>>>>>>> -*******************************************************************************/
>>>>>>>>  
>>>>>>>>
>>>>>>>>
>>>>>>>> -void log_mds_err(char *fmt, ...)
>>>>>>>> -{
>>>>>>>> -    char str[MDS_MAX_PROCESS_NAME_LEN + 32];
>>>>>>>> -    int i;
>>>>>>>> -    va_list ap;
>>>>>>>> + * Funtion Name   :    log_mds_err
>>>>>>>> + *
>>>>>>>> + * Purpose        :
>>>>>>>> + *
>>>>>>>> + * Return Value   :    None
>>>>>>>> + *
>>>>>>>> +
>>>>>>>> *******************************************************************************/
>>>>>>>>  
>>>>>>>>
>>>>>>>> +void log_mds_err(const char *fmt, ...) {
>>>>>>>> +  if (gl_mds_log_level < NCSMDS_LC_ERR) return;
>>>>>>>> +  char str[MDS_MAX_PROCESS_NAME_LEN + 32];
>>>>>>>> +  int i;
>>>>>>>> +  va_list ap;
>>>>>>>>    -    i = snprintf(str, sizeof(str), "%s ERR  |", process_name);
>>>>>>>> -    va_start(ap, fmt);
>>>>>>>> -    vsnprintf(str + i, sizeof(str) - i, fmt, ap);
>>>>>>>> -    va_end(ap);
>>>>>>>> -    log_mds(str);
>>>>>>>> +  i = snprintf(str, sizeof(str), "%s ERR  |", process_name);
>>>>>>>> +  va_start(ap, fmt);
>>>>>>>> +  vsnprintf(str + i, sizeof(str) - i, fmt, ap);
>>>>>>>> +  va_end(ap);
>>>>>>>> +  log_mds(str);
>>>>>>>>    }
>>>>>>>> /*******************************************************************************
>>>>>>>>  
>>>>>>>>
>>>>>>>>
>>>>>>>> -* Funtion Name   :    log_mds_notify
>>>>>>>> -*
>>>>>>>> -* Purpose        :
>>>>>>>> -*
>>>>>>>> -* Return Value   :    None
>>>>>>>> -*
>>>>>>>> -*******************************************************************************/
>>>>>>>>  
>>>>>>>>
>>>>>>>>
>>>>>>>> -void log_mds_notify(char *fmt, ...)
>>>>>>>> -{
>>>>>>>> -    char str[MDS_MAX_PROCESS_NAME_LEN + 32];
>>>>>>>> -    int i;
>>>>>>>> -    va_list ap;
>>>>>>>> + * Funtion Name   :    log_mds_notify
>>>>>>>> + *
>>>>>>>> + * Purpose        :
>>>>>>>> + *
>>>>>>>> + * Return Value   :    None
>>>>>>>> + *
>>>>>>>> +
>>>>>>>> *******************************************************************************/
>>>>>>>>  
>>>>>>>>
>>>>>>>> +void log_mds_notify(const char *fmt, ...) {
>>>>>>>> +  if (gl_mds_log_level < NCSMDS_LC_NOTIFY) return;
>>>>>>>> +  char str[MDS_MAX_PROCESS_NAME_LEN + 32];
>>>>>>>> +  int i;
>>>>>>>> +  va_list ap;
>>>>>>>>    -    i = snprintf(str, sizeof(str), "%s NOTIFY |", 
>>>>>>>> process_name);
>>>>>>>> -    va_start(ap, fmt);
>>>>>>>> -    vsnprintf(str + i, sizeof(str) - i, fmt, ap);
>>>>>>>> -    va_end(ap);
>>>>>>>> -    log_mds(str);
>>>>>>>> +  i = snprintf(str, sizeof(str), "%s NOTIFY  |", process_name);
>>>>>>>> +  va_start(ap, fmt);
>>>>>>>> +  vsnprintf(str + i, sizeof(str) - i, fmt, ap);
>>>>>>>> +  va_end(ap);
>>>>>>>> +  log_mds(str);
>>>>>>>>    }
>>>>>>>> /*******************************************************************************
>>>>>>>>  
>>>>>>>>
>>>>>>>>
>>>>>>>> -* Funtion Name   :    log_mds_info
>>>>>>>> -*
>>>>>>>> -* Purpose        :
>>>>>>>> -*
>>>>>>>> -* Return Value   :    None
>>>>>>>> -*
>>>>>>>> -*******************************************************************************/
>>>>>>>>  
>>>>>>>>
>>>>>>>>
>>>>>>>> -void log_mds_info(char *fmt, ...)
>>>>>>>> -{
>>>>>>>> -    char str[MDS_MAX_PROCESS_NAME_LEN + 32];
>>>>>>>> -    int i;
>>>>>>>> -    va_list ap;
>>>>>>>> + * Funtion Name   :    log_mds_info
>>>>>>>> + *
>>>>>>>> + * Purpose        :
>>>>>>>> + *
>>>>>>>> + * Return Value   :    None
>>>>>>>> + *
>>>>>>>> +
>>>>>>>> *******************************************************************************/
>>>>>>>>  
>>>>>>>>
>>>>>>>> +void log_mds_info(const char *fmt, ...) {
>>>>>>>> +  if (gl_mds_log_level < NCSMDS_LC_INFO) return;
>>>>>>>> +  char str[MDS_MAX_PROCESS_NAME_LEN + 32];
>>>>>>>> +  int i;
>>>>>>>> +  va_list ap;
>>>>>>>>    -    i = snprintf(str, sizeof(str), "%s INFO  |", 
>>>>>>>> process_name);
>>>>>>>> -    va_start(ap, fmt);
>>>>>>>> -    vsnprintf(str + i, sizeof(str) - i, fmt, ap);
>>>>>>>> -    va_end(ap);
>>>>>>>> -    log_mds(str);
>>>>>>>> +  i = snprintf(str, sizeof(str), "%s INFO  |", process_name);
>>>>>>>> +  va_start(ap, fmt);
>>>>>>>> +  vsnprintf(str + i, sizeof(str) - i, fmt, ap);
>>>>>>>> +  va_end(ap);
>>>>>>>> +  log_mds(str);
>>>>>>>>    }
>>>>>>>> /*******************************************************************************
>>>>>>>>  
>>>>>>>>
>>>>>>>>
>>>>>>>> -* Funtion Name   :    log_mds_dbg
>>>>>>>> -*
>>>>>>>> -* Purpose        :
>>>>>>>> -*
>>>>>>>> -* Return Value   :    NCSCC_RC_SUCCESS
>>>>>>>> -*                     NCSCC_RC_FAILURE
>>>>>>>> -*
>>>>>>>> -*******************************************************************************/
>>>>>>>>  
>>>>>>>>
>>>>>>>>
>>>>>>>> -void log_mds_dbg(char *fmt, ...)
>>>>>>>> -{
>>>>>>>> -    char str[MDS_MAX_PROCESS_NAME_LEN + 32];
>>>>>>>> -    int i;
>>>>>>>> -    va_list ap;
>>>>>>>> + * Funtion Name   :    log_mds_dbg
>>>>>>>> + *
>>>>>>>> + * Purpose        :
>>>>>>>> + *
>>>>>>>> + * Return Value   :    NCSCC_RC_SUCCESS
>>>>>>>> + *                     NCSCC_RC_FAILURE
>>>>>>>> + *
>>>>>>>> +
>>>>>>>> *******************************************************************************/
>>>>>>>>  
>>>>>>>>
>>>>>>>> +void log_mds_dbg(const char *fmt, ...) {
>>>>>>>> +  if (gl_mds_log_level < NCSMDS_LC_DBG) return;
>>>>>>>> +  char str[MDS_MAX_PROCESS_NAME_LEN + 32];
>>>>>>>> +  int i;
>>>>>>>> +  va_list ap;
>>>>>>>>    -    i = snprintf(str, sizeof(str), "%s DBG  |", process_name);
>>>>>>>> -    va_start(ap, fmt);
>>>>>>>> -    vsnprintf(str + i, sizeof(str) - i, fmt, ap);
>>>>>>>> -    va_end(ap);
>>>>>>>> -    log_mds(str);
>>>>>>>> +  i = snprintf(str, sizeof(str), "%s DBG  |", process_name);
>>>>>>>> +  va_start(ap, fmt);
>>>>>>>> +  vsnprintf(str + i, sizeof(str) - i, fmt, ap);
>>>>>>>> +  va_end(ap);
>>>>>>>> +  log_mds(str);
>>>>>>>>    }
>>>>>>>> /*******************************************************************************
>>>>>>>>  
>>>>>>>>
>>>>>>>>
>>>>>>>> -* Funtion Name   :    log_mds
>>>>>>>> -*
>>>>>>>> -* Purpose        :
>>>>>>>> -*
>>>>>>>> -* Return Value   :    None
>>>>>>>> -*
>>>>>>>> -*******************************************************************************/
>>>>>>>>  
>>>>>>>>
>>>>>>>>
>>>>>>>> -static void log_mds(const char *str)
>>>>>>>> -{
>>>>>>>> -    FILE *fp;
>>>>>>>> -    struct tm *tstamp_data, tm_info;
>>>>>>>> + * Funtion Name   :    log_mds
>>>>>>>> + *
>>>>>>>> + * Purpose        :
>>>>>>>> + *
>>>>>>>> + * Return Value   :    None
>>>>>>>> + *
>>>>>>>> +
>>>>>>>> *******************************************************************************/
>>>>>>>>  
>>>>>>>>
>>>>>>>> +static void log_mds(const char *str) {
>>>>>>>> +  FILE *fp;
>>>>>>>>    -    if (lf != NULL && ((fp = fopen(lf, "a+")) != NULL)) {
>>>>>>>> -        struct timeval tv;
>>>>>>>> -        char asc_tod[128];
>>>>>>>> -        char log_string[512];
>>>>>>>> -        int i;
>>>>>>>> +  if (lf != nullptr && ((fp = fopen(lf, "a+")) != nullptr)) {
>>>>>>>> +    struct tm tm_info;
>>>>>>>> +    struct timeval tv;
>>>>>>>> +    char asc_tod[128];
>>>>>>>> +    char log_string[512];
>>>>>>>> +    int i;
>>>>>>>>    -        gettimeofday(&tv, NULL);
>>>>>>>> -        tstamp_data = localtime_r(&tv.tv_sec, &tm_info);
>>>>>>>> -        osafassert(tstamp_data);
>>>>>>>> +    gettimeofday(&tv, nullptr);
>>>>>>>> +    struct tm* tstamp_data = localtime_r(&tv.tv_sec, &tm_info);
>>>>>>>> +    osafassert(tstamp_data);
>>>>>>>>    -        strftime(asc_tod, sizeof(asc_tod), "%b %e %k:%M:%S",
>>>>>>>> tstamp_data);
>>>>>>>> -        i = snprintf(log_string, sizeof(log_string), "%s.%06ld 
>>>>>>>> %s",
>>>>>>>> -                 asc_tod, tv.tv_usec, str);
>>>>>>>> +    strftime(asc_tod, sizeof(asc_tod), "%b %e %k:%M:%S", 
>>>>>>>> tstamp_data);
>>>>>>>> +    i = snprintf(log_string, sizeof(log_string), "%s.%06ld %s",
>>>>>>>> +                 asc_tod, tv.tv_usec, str);
>>>>>>>>    -        if (i >= sizeof(log_string)) {
>>>>>>>> -            i = sizeof(log_string);
>>>>>>>> -            log_string[i - 1] = '\n';
>>>>>>>> -        } else if (log_string[i - 1] != '\n') {
>>>>>>>> -            log_string[i] = '\n';
>>>>>>>> -            i++;
>>>>>>>> -        }
>>>>>>>> +    if (i < 0) {
>>>>>>>> +      i = 1;
>>>>>>>> +      log_string[i - 1] = '\n';
>>>>>>>> +    } else if (static_cast<size_t>(i) >= sizeof(log_string)) {
>>>>>>>> +      i = sizeof(log_string);
>>>>>>>> +      log_string[i - 1] = '\n';
>>>>>>>> +    } else if (log_string[i - 1] != '\n') {
>>>>>>>> +      log_string[i] = '\n';
>>>>>>>> +      i++;
>>>>>>>> +    }
>>>>>>>>    -        if (! fwrite(log_string, 1, i, fp)) {
>>>>>>>> -            fclose(fp);
>>>>>>>> -            return;
>>>>>>>> -        }
>>>>>>>> +    if (fwrite(log_string, 1, i, fp) != static_cast<size_t>(i)) {
>>>>>>>> +      fclose(fp);
>>>>>>>> +      return;
>>>>>>>> +    }
>>>>>>>>    -        fclose(fp);
>>>>>>>> -    }
>>>>>>>> +    fclose(fp);
>>>>>>>> +  }
>>>>>>>>    }
>>>>>>>> -
>>>>>>>> -
>>>>>>>> diff --git a/osaf/libs/core/mds/mds_main.c
>>>>>>>> b/osaf/libs/core/mds/mds_main.c
>>>>>>>> --- a/osaf/libs/core/mds/mds_main.c
>>>>>>>> +++ b/osaf/libs/core/mds/mds_main.c
>>>>>>>> @@ -102,7 +102,6 @@ static void mds_mutex_init_once(void)
>>>>>>>>    }
>>>>>>>>      /* global Log level variable */
>>>>>>>> -uint32_t gl_mds_log_level = 3;
>>>>>>>>    uint32_t gl_mds_checksum = 0;
>>>>>>>>      uint32_t MDS_QUIESCED_TMR_VAL = 80;
>>>>>>>> @@ -558,7 +557,7 @@ uint32_t mds_lib_req(NCS_LIB_REQ_INFO *r
>>>>>>>>                char buff[50], pref[50];
>>>>>>>>                snprintf(buff, sizeof(buff), PKGLOGDIR "/mds.log");
>>>>>>>>                memset(pref, 0 ,sizeof(pref));
>>>>>>>> -            mds_log_init(buff, pref);
>>>>>>>> +            mds_log_init(buff);
>>>>>>>>            }
>>>>>>>> osaf_mutex_unlock_ordie(&gl_mds_library_mutex);
>>>>>
>>>>> ------------------------------------------------------------------------------
>>>>>  
>>>>>
>>>>> Developer Access Program for Intel Xeon Phi Processors
>>>>> Access to Intel Xeon Phi processor-based developer platforms.
>>>>> With one year of Intel Parallel Studio XE.
>>>>> Training and support from Colfax.
>>>>> Order your platform today. http://sdm.link/xeonphi
>>>>> _______________________________________________
>>>>> Opensaf-devel mailing list
>>>>> [email protected]
>>>>> https://lists.sourceforge.net/lists/listinfo/opensaf-devel
>>>>
>>>
>>
>


------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to