From 2fe243d0561c19009964003aa2ced7c695a46d17 Mon Sep 17 00:00:00 2001 From: Aravinda VK Date: Wed, 3 Jul 2019 15:08:31 +0530 Subject: logging: Structured logging reference PR To convert the existing `gf_msg` to `gf_smsg`: - Define `_STR` of respective Message ID as below(In `*-messages.h`) #define PC_MSG_REMOTE_OP_FAILED_STR "remote operation failed." - Change `gf_msg` to use `gf_smsg`. Convert values into fields and add any missing fields. Note: `errno` and `error` fields will be added automatically to log message in case errnum is specified. Example: gf_smsg( this->name, // Name or log domain GF_LOG_WARNING, // Log Level rsp.op_errno, // Error number PC_MSG_REMOTE_OP_FAILED, // Message ID "path=%s", local->loc.path, // Key Value 1 "gfid=%s", loc_gfid_utoa(&local->loc), // Key Value 2 NULL // Log End ); Key value pairs formatting Help: gf_slog( this->name, // Name or log domain GF_LOG_WARNING, // Log Level rsp.op_errno, // Error number PC_MSG_REMOTE_OP_FAILED, // Message ID "op=CREATE", // Static Key and Value "path=%s", local->loc.path, // Format for Value "brick-%d-status=%s", brkidx, brkstatus, // Use format for key and val NULL // Log End ); Before: [2019-07-03 08:16:18.226819] W [MSGID: 114031] [client-rpc-fops_v2.c \ :2633:client4_0_lookup_cbk] 0-gv3-client-0: remote operation failed. \ Path: / (00000000-0000-0000-0000-000000000001) [Transport endpoint \ is not connected] After: [2019-07-29 07:50:15.773765] W [MSGID: 114031] \ [client-rpc-fops_v2.c:2633:client4_0_lookup_cbk] 0-gv1-client-0: \ remote operation failed. [{path=/f1}, \ {gfid=00000000-0000-0000-0000-000000000000}, \ {errno=107}, {error=Transport endpoint is not connected}] To add new `gf_smsg`, Add a Message ID in respective `*-messages.h` file and the follow the steps mentioned above. Change-Id: I4e7d37f27f106ab398e991d931ba2ac7841a44b1 Updates: #657 Signed-off-by: Aravinda VK --- libglusterfs/src/glusterfs/logging.h | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'libglusterfs/src/glusterfs') diff --git a/libglusterfs/src/glusterfs/logging.h b/libglusterfs/src/glusterfs/logging.h index 31ecbfcbdb6..b3a6ac191f0 100644 --- a/libglusterfs/src/glusterfs/logging.h +++ b/libglusterfs/src/glusterfs/logging.h @@ -368,10 +368,6 @@ gf_log_disable_suppression_before_exit(struct _glusterfs_ctx *ctx); #define GF_ERROR(xl, format, args...) \ gf_log((xl)->name, GF_LOG_ERROR, format, ##args) -int -_gf_slog(const char *domain, const char *file, const char *function, int line, - gf_loglevel_t level, const char *event, ...); - int _gf_smsg(const char *domain, const char *file, const char *function, int32_t line, gf_loglevel_t level, int errnum, int trace, @@ -381,12 +377,7 @@ _gf_smsg(const char *domain, const char *file, const char *function, #define gf_smsg(dom, level, errnum, msgid, event...) \ do { \ _gf_smsg(dom, __FILE__, __FUNCTION__, __LINE__, level, errnum, 0, \ - msgid, ##event); \ - } while (0) - -#define gf_slog(dom, level, event...) \ - do { \ - _gf_slog(dom, __FILE__, __FUNCTION__, __LINE__, level, ##event); \ + msgid, msgid##_STR, ##event); \ } while (0) #endif /* __LOGGING_H__ */ -- cgit