Giter Club home page Giter Club logo

slog's Introduction

Hi there ๐Ÿ‘‹ I'm Sandro

ProtonMail ProtonMail

A Software Engineer with more than 10 years of experience specializing in C/C++ and Linux/Unix development. Demonstrated prowess in multithreading, socket programming, and the implementation of streaming protocols. An open-source enthusiast who likes low-level languages and enjoys writing code. Proficient in an array of programming languages including but not limited to Rust, Python, C#, TypeScript, Perl, and Lua.

GitHub Streak

GitHub Statistics GitHub Top Languages

slog's People

Contributors

burnett01 avatar carton avatar dominikwin avatar everte avatar flynn1973 avatar freshxopensource avatar georgegkas avatar gregoryvds avatar hamandchris avatar kala13x avatar rede97 avatar theosakamg avatar

Stargazers

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

Watchers

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

slog's Issues

Question about memory

Hello kala13x, I checked my program for memory-leaks using "Valgrind". We all know that Valgrin shouts at almost everything, even if theres no problem. However. Whilst checking I got the following output:

==24231== HEAP SUMMARY:
==24231==     in use at exit: 140 bytes in 2 blocks
==24231==   total heap usage: 74 allocs, 72 frees, 22,956 bytes allocated
==24231==
==24231== 20 bytes in 1 blocks are still reachable in loss record 1 of 2
==24231==    at 0x4C28BED: malloc (vg_replace_malloc.c:263)
==24231==    by 0x4EAEAB1: strdup (strdup.c:43)
==24231==    by 0x402133: init_slog (slog.c:211)
==24231==    by 0x401349: pipe_init (pipe.c:62)
==24231==    by 0x401230: main (main.c:84)
==24231==
==24231== 120 bytes in 1 blocks are definitely lost in loss record 2 of 2
==24231==    at 0x4C28BED: malloc (vg_replace_malloc.c:263)
==24231==    by 0x4E97108: getdelim (iogetdelim.c:68)
==24231==    by 0x401E4A: parse_config (slog.c:107)
==24231==    by 0x402157: init_slog (slog.c:216)
==24231==    by 0x401349: pipe_init (pipe.c:62)
==24231==    by 0x401230: main (main.c:84)
==24231==
==24231== LEAK SUMMARY:
==24231==    definitely lost: 120 bytes in 1 blocks
==24231==    indirectly lost: 0 bytes in 0 blocks
==24231==      possibly lost: 0 bytes in 0 blocks
==24231==    still reachable: 20 bytes in 1 blocks
==24231==         suppressed: 0 bytes in 0 blocks
==24231==

As you can see there are two blocks still reachable at exit. One is 20 bytes and the other 120 bytes.
So I decided to add free() after line 204 @slog.c and now it looks like:

fclose(file);
free(line);

and one of the 'loss records' in Valgrin is gone:

==32333== HEAP SUMMARY:
==32333==     in use at exit: 20 bytes in 1 blocks
==32333==   total heap usage: 68 allocs, 67 frees, 21,207 bytes allocated
==32333==
==32333== 20 bytes in 1 blocks are still reachable in loss record 1 of 1
==32333==    at 0x4C28BED: malloc (vg_replace_malloc.c:263)
==32333==    by 0x4EAEAB1: strdup (strdup.c:43)
==32333==    by 0x40213F: init_slog (slog.c:211)
==32333==    by 0x401349: pipe_init (pipe.c:62)
==32333==    by 0x401230: main (main.c:84)
==32333==
==32333== LEAK SUMMARY:
==32333==    definitely lost: 0 bytes in 0 blocks
==32333==    indirectly lost: 0 bytes in 0 blocks
==32333==      possibly lost: 0 bytes in 0 blocks
==32333==    still reachable: 20 bytes in 1 blocks
==32333==         suppressed: 0 bytes in 0 blocks

So my question is: Is that just another 'false-positive' of Valgrin or does it make sense to have a free() at that place?

Thank you very much, regards Steven.

Specs: Debian 7.8 (Wheezy) - Compiler: gcc

Compiling slog with MSYS64 on Win11 64bits

Hello!
I like this slog lib.
I had to modify the slog.c to able to compile it with MSYS64 (on Win11 64bits).

  • Replcaced macros __FUNCTION__ by __func__ to meet the C99 standard.
  • There is no syscall.h in MSYS64, so I modified the next lines
    from these:
    #if !defined(__APPLE__) && !defined(DARWIN) && !defined(WIN32)
    #include <syscall.h>
    #endif
    
    to these:
    #if !defined(__APPLE__) && !defined(DARWIN) && !defined(WIN32) && !defined(__MSYS__)
    #include <syscall.h>
    #endif
    
  • There is no syscall() and __NR_gettid in MSYS64, and no 32 bits but 64 bits, so I modified from uint32_t to size_t the next lines
    from these:
    static uint32_t slog_get_tid()
    {
    #if defined(__APPLE__) || defined(DARWIN) || defined(WIN32)
        return (uint32_t)pthread_self();
    #else
        return syscall(__NR_gettid);
    #endif
    }
    
    to these:
    static size_t slog_get_tid()
    {
    #if defined(__APPLE__) || defined(DARWIN) || defined(WIN32) || defined(__MSYS__)
        return (size_t)pthread_self();
    #else
        return syscall(__NR_gettid);
    #endif
    }
    
  • I modified %u to %lu in the next lines
    from these:
    static void slog_create_tid(char *pOut, int nSize, uint8_t nTraceTid)
    {
        if (!nTraceTid) pOut[0] = SLOG_NUL;
        else snprintf(pOut, nSize, "(%u) ", slog_get_tid());
    }
    
    to these:
    static void slog_create_tid(char *pOut, int nSize, uint8_t nTraceTid)
    {
        if (!nTraceTid) pOut[0] = SLOG_NUL;
        else snprintf(pOut, nSize, "(%lu) ", slog_get_tid());
    }
    

Now, with these modifications I am able to compile the slog library without any warnings and errors with MSYS64 (on Win11 64bits).

Release tags

Would it be possible for you to tag the 1.5 release so that it's easy to clone a shallow copy (i.e., git clone https://github.com/kala13x/slog --branch 1.5 --depth 1)?

Thank you!

beautiful and lightweight

Thanks for your contribution @kala13x! This is one of the simpliest, yet easy to use logging-library.
This lib will be a part of my new project. Thumbs up !

Segmentation fault

When initializing slog after I try to log once it fails with segmentation fault.
Here is the code below:

slog_init("logfile", 1, 0);
slog_config_t slg_cfg;
slg_cfg.eColorFormat = SLOG_COLORING_FULL;
slg_cfg.eDateControl = SLOG_TIME_ONLY;
strcpy(slg_cfg.sFileName, "logfile");
strcpy(slg_cfg.sFilePath, "../logs/");

slg_cfg.nTraceTid = 1;
slg_cfg.nToScreen = 0;
slg_cfg.nToFile = 1;
slg_cfg.nUseHeap = 0;
slg_cfg.nFlush = 0;
slg_cfg.nFlags = 1;
slog_config_set(&slg_cfg);

slog_trace("some.");

NOTE: I checked and the directory exists
I found out that what causes it to crash is this: slg_cfg.nFlags = 1;
If I remove that line it runs but doesn't output anything to the file

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.