sysrepo / sysrepo

YANG-based configuration and operational state data store for Unix/Linux applications

Home Page:http://www.sysrepo.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to enable libyang logs in sysrepo code?

amitnagraj opened this issue · comments

Hi,

I'm using sysrepo v2.2.12.

I'm trying to enable libyang logs while executing sysrepo code, but I'm not getting the logs.

C snippet:

main():
    /* turn logging on */
    sr_log_stderr(SR_LL_DBG);
    sr_log_syslog(NULL, SR_LL_DBG);

    ly_log_level(LY_LLDBG);
    ly_set_log_clb(sr_cb_ly, 1);


    /* connect to sysrepo */
    rc = sr_connect(0, &connection);
    if (rc != SR_ERR_OK) {
        goto cleanup;
    }

log callback:
void
sr_cb_ly(LY_LOG_LEVEL level, const char *msg, const char *path)
{
    if (path) {
        printf("LY %s (%s)", msg, path);
    } else {
        printf("LY %s", msg);
    }
}

Output:
root@debian10:sysrepo/examples# ./get /ibos-interfaces:interfaces/interface/config/name
Application will get "/ibos-interfaces:interfaces/interface/config/name" from "running" datastore.

[INF] Connection 8 created.
[INF] Session 5 (user "root", CID 8) created.
/ibos-interfaces:interfaces/interface[name='ethernet1/1']/config/name = ethernet1/1
/ibos-interfaces:interfaces/interface[name='ethernet1/2']/config/name = ethernet1/2
/ibos-interfaces:interfaces/interface[name='ethernet1/3']/config/name = ethernet1/3
/ibos-interfaces:interfaces/interface[name='ethernet1/4']/config/name = ethernet1/4
/ibos-interfaces:interfaces/interface[name='et1/4/vid1']/config/name = et1/4/vid1
/ibos-interfaces:interfaces/interface[name='et1/4/vid3']/config/name = et1/4/vid3
/ibos-interfaces:interfaces/interface[name='et1/5/vid2']/config/name = et1/5/vid2
/ibos-interfaces:interfaces/interface[name='et1/5/vid4']/config/name = et1/5/vid4
[INF] No datastore changes to apply.

Enable libyang logging with this code

    ly_log_options(LY_LOLOG | LY_LOSTORE);
    ly_log_level(LY_LLDBG);
    ly_set_log_clb(sr_cb_ly, 1);

sysrepo modifies the logging options to hide irrelevant messages (that you will see this way). I will try to improve this and not having to affect libyang logging this way.

Thanks for the response.

Using above code I'm only getting the initial logs from libyang.

I'm trying to reproduce libyang[1]: String "et1/21/vid15" not freed from the dictionary, refcount 4 by commenting sr_free_values() from the sr_get_items_example.c, but not able to get the logs after sr_disconnect().

Logs:

Application will get "/ibos-interfaces:interfaces/interface/config/name" from "running" datastore.

LY Searching for "ietf-inet-types" in "/home/amit/latest/sysrepo/build/repository/yang".
LY Newer revision than "ietf-inet-types@2013-07-15" not found, using this as the latest revision.
LY Searching for "ietf-yang-types" in "/home/amit/latest/sysrepo/build/repository/yang".
LY Newer revision than "ietf-yang-types@2013-07-15" not found, using this as the latest revision.
LY Searching for "ietf-inet-types" in "/home/amit/latest/sysrepo/build/repository/yang".
LY Newer revision than "ietf-inet-types@2013-07-15" not found, using this as the latest revision.
LY Searching for "ietf-yang-types" in "/home/amit/latest/sysrepo/build/repository/yang".
LY Newer revision than "ietf-yang-types@2013-07-15" not found, using this as the latest revision.
LY Searching for "ietf-datastores" in "/home/amit/latest/sysrepo/build/repository/yang".
LY Loading schema from "/home/amit/latest/sysrepo/build/repository/yang/ietf-datastores@2018-02-14.yang" file.
LY Searching for "ietf-yang-library" in "/home/amit/latest/sysrepo/build/repository/yang".
LY Loading schema from "/home/amit/latest/sysrepo/build/repository/yang/ietf-yang-library@2019-01-04.yang" file.
LY Searching for "ietf-netconf-acm" in "/home/amit/latest/sysrepo/build/repository/yang".
LY Loading schema from "/home/amit/latest/sysrepo/build/repository/yang/ietf-netconf-acm@2018-02-14.yang" file.
LY Searching for "sysrepo-monitoring" in "/home/amit/latest/sysrepo/build/repository/yang".
LY Loading schema from "/home/amit/latest/sysrepo/build/repository/yang/sysrepo-monitoring@2022-08-19.yang" file.
LY Implemented module "ietf-datastores@2018-02-14" is not used for import, revision "2018-02-14" is imported instead.
LY Searching for "sysrepo-plugind" in "/home/amit/latest/sysrepo/build/repository/yang".
LY Loading schema from "/home/amit/latest/sysrepo/build/repository/yang/sysrepo-plugind@2022-08-26.yang" file.
LY Searching for "ietf-netconf" in "/home/amit/latest/sysrepo/build/repository/yang".
LY Loading schema from "/home/amit/latest/sysrepo/build/repository/yang/ietf-netconf@2013-09-29.yang" file.
LY Searching for "ietf-yang-metadata" in "/home/amit/latest/sysrepo/build/repository/yang".
LY Newer revision than "ietf-yang-metadata@2016-08-05" not found, using this as the latest revision.
LY Searching for "ietf-netconf-with-defaults" in "/home/amit/latest/sysrepo/build/repository/yang".
LY Loading schema from "/home/amit/latest/sysrepo/build/repository/yang/ietf-netconf-with-defaults@2011-06-01.yang" file.
LY Searching for "ietf-netconf-notifications" in "/home/amit/latest/sysrepo/build/repository/yang".
LY Loading schema from "/home/amit/latest/sysrepo/build/repository/yang/ietf-netconf-notifications@2012-02-06.yang" file.
LY Implemented module "ietf-netconf@2013-09-29" is not used for import, revision "2013-09-29" is imported instead.
LY Searching for "ietf-origin" in "/home/amit/latest/sysrepo/build/repository/yang".
LY Loading schema from "/home/amit/latest/sysrepo/build/repository/yang/ietf-origin@2018-02-14.yang" file.
LY Searching for "ibos-interfaces" in "/home/amit/latest/sysrepo/build/repository/yang".
LY Loading schema from "/home/amit/latest/sysrepo/build/repository/yang/ibos-interfaces@2022-09-23.yang" file.
LY Searching for "ibos-yang-types" in "/home/amit/latest/sysrepo/build/repository/yang".
LY Loading schema from "/home/amit/latest/sysrepo/build/repository/yang/ibos-yang-types@2022-09-23.yang" file.
LY Searching for "ibos-types" in "/home/amit/latest/sysrepo/build/repository/yang".
LY Loading schema from "/home/amit/latest/sysrepo/build/repository/yang/ibos-types@2022-09-23.yang" file.
LY Searching for "ibos-extensions" in "/home/amit/latest/sysrepo/build/repository/yang".
LY Loading schema from "/home/amit/latest/sysrepo/build/repository/yang/ibos-extensions@2022-09-23.yang" file.
LY Searching for "ibos-ip-route" in "/home/amit/latest/sysrepo/build/repository/yang".
LY Loading schema from "/home/amit/latest/sysrepo/build/repository/yang/ibos-ip-route@2023-08-23.yang" file.
LY Searching for "ibos-inet-types" in "/home/amit/latest/sysrepo/build/repository/yang".
LY Loading schema from "/home/amit/latest/sysrepo/build/repository/yang/ibos-inet-types@2022-09-23.yang" file.
[INF] Connection 10 created.
[INF] Session 7 (user "root", CID 10) created.
/ibos-interfaces:interfaces/interface[name='ethernet1/1']/config/name = ethernet1/1
/ibos-interfaces:interfaces/interface[name='ethernet1/2']/config/name = ethernet1/2
/ibos-interfaces:interfaces/interface[name='ethernet1/3']/config/name = ethernet1/3
/ibos-interfaces:interfaces/interface[name='ethernet1/4']/config/name = ethernet1/4
/ibos-interfaces:interfaces/interface[name='et1/4/vid1']/config/name = et1/4/vid1
/ibos-interfaces:interfaces/interface[name='et1/4/vid3']/config/name = et1/4/vid3
/ibos-interfaces:interfaces/interface[name='et1/5/vid2']/config/name = et1/5/vid2
/ibos-interfaces:interfaces/interface[name='et1/5/vid4']/config/name = et1/5/vid4
[INF] No datastore changes to apply.

Thanks,

sr_val_t structures are not using libyang dictionary so you will never get the warning this way.