Git Product home page Git Product logo

ring_log's Introduction

For Linux systems, there is logrotate. For embedded systems, there's ring_log.

Specify how many total logs you want to keep (in bytes), and then use ring_log's API to add new log entries.

ring_log will manage the on-disk log storage such that only the N most recent log entries are kept. It will use the amount of disk space that you allow it to, and no more.

How to use:

Copy over ring_log.c, ring_log.h, and the ring_log_arch_*.c matching your OS.

Copy and edit ring_log_config.c. Important values such as the total log size, the number of logs, etc, are defined there.

Start up ring_log and write a few entries (see example.c):

if (!ring_log_init()) {
    puts("ring_log_init failed");
    exit(1);
}

ring_log_write_tail("log_a", "one", 3);
ring_log_write_tail_complete("log_a");

ring_log_write_tail("log_a", "two", 3);
ring_log_write_tail_complete("log_a");

ring_log_write_tail("log_a", "three", 5);
ring_log_write_tail_complete("log_a");

Read all the entries out:

while (ring_log_has_unread("log_a")) {
    int read_now;
    char buffer[8];
    size_t read_total = 0;
    printf("entry: ");
    while ((read_now = ring_log_read_head("log_a", &buffer, sizeof(buffer), &read_total))) {
        printf("%.*s", read_now, (char *)&buffer);
    };
    puts("");
    ring_log_read_head_success("log_a");
}

ring_log's People

Contributors

edmund-huber avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ring_log's Issues

No license?

This is a very interesting project! Would you mind adding a license, preferably a permissive license, to it so there is no legal ambiguity to its use?

Missing implementation of ring_log_arch_deinit()

On the esp32, unless I am wrong, there is no implementation of the ring_log_arch_deinit() function called inside ring_log_deinit(). You have the declaration of the function in ring_log.h but misses the implementation somewhere in the ring_log_arch_freertos.c

Does this run on the ESP32?

Apologies in advance: This is a question, not an issue.

Does this code run on the ESP32?

I can see that your code opens files to write to them - and I know on the ESP32 supports a FAT file system.

But the documentation there suggests that I need to run some config/bootstrap calls before I can use the POSIX file open/write/read/close functions from the C library : https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/storage/fatfs.html#using-fatfs-with-vfs

I presume that your code does NOT handle this FatFs initialization process and that's something I need to handle myself before I start logging?

ring_log library shows up previously read log

Hi Menhirsys,

Thank you for writing such a nice library.

I am trying to use it to store the data in the flash. But I am facing one issue.

I compiled example.c file from
https://github.com/menhirsys/ring_log/blob/master/example.c
for the ESP32.

But when I run this example first time on the fresh device, It shows correct data(3 data) read as below.
one
two
three

But when I restart this device then it shows incorrect data read(4 instead of 3 data) as below.
three
one
two
three

So basically it remembers last read data "three" after restart/power lost. But actually there is only 3 data which was written and not read yet.

I tried to check this problem but couldn't figure out the exact issue.

Will you please check this?

fallbacks in case file or entry headers are corrupt

If power cuts off in the middle of a write operation, it's conceivable that a file or entry header could be only partially written. We should add a checksum to both headers, and then figure out what ring_log should do when it encounters a corrupt file or entry header based on that checksum.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.