{"id":19430241,"url":"https://github.com/8dcc/liblog","last_synced_at":"2025-03-15T18:19:20.085Z","repository":{"id":248892198,"uuid":"830059451","full_name":"8dcc/liblog","owner":"8dcc","description":"Personal C99 logging library","archived":false,"fork":false,"pushed_at":"2025-02-22T15:24:05.000Z","size":37,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-11T04:52:17.869Z","etag":null,"topics":["c","logging"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/8dcc.png","metadata":{"files":{"readme":"README.org","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-17T14:04:29.000Z","updated_at":"2025-02-22T15:22:23.000Z","dependencies_parsed_at":"2024-07-23T16:59:29.458Z","dependency_job_id":null,"html_url":"https://github.com/8dcc/liblog","commit_stats":null,"previous_names":["8dcc/log.h","8dcc/liblog"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/8dcc%2Fliblog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/8dcc%2Fliblog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/8dcc%2Fliblog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/8dcc%2Fliblog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/8dcc","download_url":"https://codeload.github.com/8dcc/liblog/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243770120,"owners_count":20345247,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","logging"],"created_at":"2024-11-10T14:24:06.314Z","updated_at":"2025-03-15T18:19:20.080Z","avatar_url":"https://github.com/8dcc.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"#+title: liblog\n#+author: 8dcc\n#+startup: showeverything\n\n*Personal C99 logging library.*\n\nThis simple library provides a way of logging messages with different importance\nlevels to multiple files.\n\n* Usage example\n\nUsing the library is pretty straight-forward. The process is usually something\nlike:\n\n1. Open the necessary files for logging, using something like [[https://man.cx/fopen(3)][=fopen(3)=]].\n2. Register the files using =log_add_file=, specifying the tags that should be\n   included in that file.\n3. Write the desired log messages using =low_write= or (preferably) one of its\n   wrappers.\n4. After the program is done, clear all registered log files with\n   =log_clear_files=.\n5. Close the files, using something like [[https://man.cx/fclose(3)][=fclose(3)=]].\n\nHere is a simple example without much error checking. For a more detailed\nexplanation of the library's functions, see the [[*Interface][Interface]] specification below.\n\n#+begin_src C\n/* Register the standard error for printing all messages */\nlog_add_file(stderr, LOG_TAG_ALL);\n\n/* Open 'error.log' and register it for error and fatal messages */\nFILE* err_file = fopen(\"error.log\", \"w\");\nlog_add_file(err_file, LOG_TAG_AND_ABOVE(LOG_TAG_ERR));\n\n/* Open 'debug.log' and register it for info and debug messages */\nFILE* dbg_file = fopen(\"debug.log\", \"w\");\nlog_add_file(dbg_file, LOG_TAG_AND_BELOW(LOG_TAG_INF));\n\n/* Unrelated tags can be OR'd together */\nFILE* misc_file = fopen(\"misc.log\", \"w\");\nlog_add_file(dbg_file, LOG_TAG_DBG | LOG_TAG_FTL);\n\n/* Write the desired messages. Formats are supported. */\nlog_inf(\"Hello, world!\\n\");\nlog_err(\"Unexpected value: %p\", NULL);\n\n/* We are done, clear the registered files and close them */\nlog_clear_files();\nfclose(misc_file);\nfclose(dbg_file);\nfclose(err_file);\n#+end_src\n\nThis repository also contains a [[file:src/main.c][full example]] on how this library can be used. Simply\nclone the repository, compile it, and run =liblog-test.out=.\n\n#+begin_src console\n$ git clone https://github.com/8dcc/liblog\n$ cd liblog\n$ make\n$ ./liblog-test.out\n#+end_src\n\n* Interface\n\nThe following specification describes how the programmer can interact with this\nlibrary.\n\n** Functions\n\nThese are the public functions that the programmer can access when including the\nheader.\n\n- Function: log_add_file fp enabled_tags ::\n\n  Register a log file with the specified tags. Returns /true/ if the file was\n  registered successfully.\n\n  Whenever the =log_write= function is called, it will write the relevant\n  information to all log files that are registered with that specific tag.\n\n  Multiple log tags from the =ELogTag= enum can be OR'd together for the\n  =enabled_tags= argument.\n\n- Function: log_clear_files ::\n\n  Forget about all log files that were registered with =log_add_file=.\n\n  This function doesn't close any =FILE=, so the caller is responsible for calling\n  something like =fclose=. It's usually safer to call this function before closing\n  the log files.\n\n- Function: log_write tag func fmt ... ::\n\n  Write the specified (formatted) log message to the relevant log files. These\n  files should have been registered with =log_add_file=.\n\n  Note that, even if the tag name is not printed, this function needs to know\n  which log files are interested in messages with the current tag.\n\n  This function is not supposed to be called directly, since the =func= argument\n  is supposed to be set by one of the following macro wrappers:\n\n  1. =log_dbg=\n  2. =log_inf=\n  3. =log_wrn=\n  4. =log_err=\n  5. =log_ftl=\n\n  These macros, defined in [[file:src/liblog.h][liblog.h]], take a variable list of arguments (hence\n  the C99 requirement) that must be valid for =printf=.\n\n** Tag macros\n\nThere are currently 5 tags that can be used to represent different logging\nlevels based on their importance, defined as a =ELogTag= enum. From lowest to\nhighest importance, the are:\n\n1. =LOG_TAG_DBG=: Debug messages.\n2. =LOG_TAG_INF=: Information messages.\n3. =LOG_TAG_WRN=: Warning messages.\n4. =LOG_TAG_ERR=: Error messages.\n5. =LOG_TAG_FTL=: Fatal messages.\n\nThere is also a =LOG_TAG_MAX= macro, corresponding to the tag with the highest\nimportance; and a =LOG_TAG_ALL= macro, an integer with all the tag bits set.\n\nFurthermore, the following callable macros can be used to /OR/ multiple tags,\nwhich can be convenient when calling =log_add_file=, for example.\n\n- Macro: LOG_TAG_AND_BELOW ::\n\n  Return an integer representing the specified flag, along with all inferior\n  ones.\n\n- Macro: LOG_TAG_AND_ABOVE ::\n\n  Return an integer representing the specified flag, along with all superior\n  ones.\n\n* Compile-time features\n\nThis library is very modular, and you can enable the features you want by\ndefining only the macros you need. The =log_write= function prints the following\ninformation:\n\n1. If =LOG_DATE= is defined, the current year, month and day.\n2. If =LOG_TIME= is defined, the current hour, minute and second.\n3. If =LOG_TAG= is defined, a tag determined by the wrapper used.\n4. If =LOG_FUNC= is defined, the current function name.\n5. The user format string that was passed to the wrapper.\n\nIn addition to these content-related macros, =LOG_COLOR= can be defined to enable\nASCII color escape sequences when printing.\n\nThese =LOG_= macros should be defined in the =liblog.h= header, or by calling the\ncompiler with =-D...= arguments.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F8dcc%2Fliblog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F8dcc%2Fliblog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F8dcc%2Fliblog/lists"}