{"id":42920660,"url":"https://github.com/kala13x/slog","last_synced_at":"2026-01-30T17:36:51.332Z","repository":{"id":45885557,"uuid":"33304490","full_name":"kala13x/slog","owner":"kala13x","description":"Advanced cross-platform logging library for C/C++","archived":false,"fork":false,"pushed_at":"2025-03-20T21:44:25.000Z","size":495,"stargazers_count":143,"open_issues_count":0,"forks_count":44,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-03-20T22:31:50.293Z","etag":null,"topics":["cross-platform","file-logger","file-logging","formatting","libray","log","log-level","log-management","logger","logging","logging-library","logs","verbose","verbosity-level"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kala13x.png","metadata":{"files":{"readme":"README.md","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":"2015-04-02T11:05:11.000Z","updated_at":"2025-03-20T21:44:28.000Z","dependencies_parsed_at":"2025-03-20T22:37:43.330Z","dependency_job_id":null,"html_url":"https://github.com/kala13x/slog","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/kala13x/slog","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kala13x%2Fslog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kala13x%2Fslog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kala13x%2Fslog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kala13x%2Fslog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kala13x","download_url":"https://codeload.github.com/kala13x/slog/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kala13x%2Fslog/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28916265,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-30T16:37:38.804Z","status":"ssl_error","status_checked_at":"2026-01-30T16:37:37.878Z","response_time":66,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["cross-platform","file-logger","file-logging","formatting","libray","log","log-level","log-management","logger","logging","logging-library","logs","verbose","verbosity-level"],"created_at":"2026-01-30T17:36:50.822Z","updated_at":"2026-01-30T17:36:51.320Z","avatar_url":"https://github.com/kala13x.png","language":"C","readme":"[![MIT License](https://img.shields.io/badge/License-MIT-brightgreen.svg?)](https://github.com/kala13x/slog/blob/master/LICENSE)\n[![Linux](https://github.com/kala13x/slog/actions/workflows/linux.yml/badge.svg)](https://github.com/kala13x/slog/actions/workflows/linux.yml)\n[![MacOS](https://github.com/kala13x/slog/actions/workflows/macos.yml/badge.svg)](https://github.com/kala13x/slog/actions/workflows/macos.yml)\n[![Windows](https://github.com/kala13x/slog/actions/workflows/windows.yml/badge.svg)](https://github.com/kala13x/slog/actions/workflows/windows.yml)\n[![Valgrind](https://github.com/kala13x/slog/actions/workflows/tests.yml/badge.svg)](https://github.com/kala13x/slog/actions/workflows/tests.yml)\n[![CodeQL](https://github.com/kala13x/slog/actions/workflows/codeql.yml/badge.svg)](https://github.com/kala13x/slog/actions/workflows/codeql.yml)\n\n## SLOG - Logging Library\n`slog` is a cross-platform and thread-safe logging library for C/C++ that offers rich functionality, including the ability to easily control verbosity levels, tag and colorize output, log to files, change configuration parameters on the fly, and provide an optional log callback for log collection, among many other features. Despite its extensive capabilities, the primary goal of `slog` is to remain as stable as possible while delivering maximum performance. For more details, refer to the `src/slog.h` file to check the release version you are using.\n\n### Installation\nInstallation is possible with `CMake` for all platforms.\n```bash\ngit clone https://github.com/kala13x/slog.git \u0026\u0026 cd slog\nmkdir build \u0026\u0026 cd build\ncmake .. \u0026\u0026 make\nsudo make install\n```\n\nIf for some reason `CMake` is not available on your system, you can try the `Makefile` that comes with the project (Linux only):\n```bash\ngit clone https://github.com/kala13x/slog.git\ncd slog \u0026\u0026 make \u0026\u0026 sudo make install\n```\n\n### Usage\nIf you want to use slog in your C/C++ application, include `slog.h` header in your source file and link the slog library with `-lslog` linker flag while compiling your project. See the example directory for more information.\n\n### Logging flags\nSLog has logging flags to control log levels and to display messages with tagged and colorized output.\n\n- `SLOG_NOTAG`\n- `SLOG_LIVE`\n- `SLOG_INFO`\n- `SLOG_WARN`\n- `SLOG_DEBUG`\n- `SLOG_TRACE`\n- `SLOG_ERROR`\n- `SLOG_FATAL`\n\n### Simple API\nAt first, you should initialize slog:\n```c\nint nEnabledLevels = SLOG_NOTAG | SLOG_ERROR;\nnEnabledLevels |= SLOG_WARN | SLOG_FATAL;\n\n/* Setting SLOG_FLAGS_ALL will activate all logging levels */\n// nEnabledLevels = SLOG_FLAGS_ALL;\n\nslog_init(\"logfile\", nEnabledLevels, 0);\n```\n\n - The first argument is the name of the file where we want to save logs.\n - The second argument is the logging level flags which are allowed to print. \n - Third argument is a thread safety flag *(1 enabled, 0 disabled)*.\n\nIf the thread safety flag is greater than zero, the function initializes mutex and every other call of any slog function is protected by lock.\n\nWith the above slog initialization example only errors, warnings, and not tagged messages will be displayed because there are no other flags activated during initialization. Any logging level can also be activated or deactivated after slog initialization by setting the flag with the `slog_enable()` and `slog_disable()` functions.\n\n```c\n/* Enable all logging levels */\nslog_enable(SLOG_FLAGS_ALL);\n\n/* Disable trace level (trace logs will not be displayed anymore) */\nslog_disable(SLOG_TRACE);\n\n/* Enable trace messages again */\nslog_enable(SLOG_TRACE);\n\n/* Disable all logging levels */\nslog_disable(SLOG_FLAGS_ALL);\n```\n\nDeinitialization is needed only if the `nTdSafe` and/or `nKeepOpen` flags are greater than zero.\n```c\nslog_destroy();\n```\nFunction destroys the mutex context, closes the output file, and resets the thread safety flag to zero.\n\n\n### Print and log something in the file\nHere is an example of how to use slog:\n```c\nslog(\"Simple message\");\n```\n\nYou can use old way logging function with a bit more control of parameters\n```c\nslog_display(SLOG_DEBUG, 0, \"Simple debug message without new line character\");\n```\n\n - The first argument is a log-level flag of the current message.\n - The second argument is the flag to add a new line character at the end of the output *(1 add, 0 don't add)*.\n - The third argument is the formatted string which we want to display in the output.\n\n#### Macros\nSLog has the cleaner option to log messages without the need to provide the flag parameter. \n\nHere are defined macros based on the logging levels.\n\n- `slog()`\n- `slog_live()`\n- `slog_info()`\n- `slog_warn()`\n- `slog_debug()`\n- `slog_error()`\n- `slog_trace()`\n- `slog_fatal()`\n\nEven shorter macros:\n\n- `slogl()` same as `slog_live()`\n- `slogi()` same as `slog_info()`\n- `slogw()` same as `slog_warn()`\n- `slogd()` same as `slog_debug()`\n- `sloge()` same as `slog_error()`\n- `slogt()` same as `slog_trace()`\n- `slogf()` same as `slog_fatal()`\n\nEach macro takes a formatted string and has another definition that does the same without newline characters.\n- Format tags prototype follows the same rules as the C standard library function `printf()`.\n- Definitions without new line characters begin with original names and end with the `_wn` string.\n\n```c\nslog(\"Simple message\");\nslog_wn(\"Simple message without new line character\\n\");\n\nslogd(\"Debug message\")\nslogd_wn(\"Debug message without new line character\\n\")\n\nslog_debug_wn(\"Another debug message without new line character\\n\")\nslog_debug(\"The %s contains between %d and %d billion stars and at least %d billion planets.\", \"Milky Way\", 200, 400, 100);\n```\n\nIn addition, there are several options to print the corresponding file name and line number where a slog macro was called. This rule follows the macros which relate to a fatal or trace flag, as shown bellow:\n\n- `slog_trace()`\n- `slog_fatal()`\n\nDisplay message with trace tag and print source location:\n```c\nslog_trace(\"Trace message throws source location.\");\n```\n\nWith an expected output to be:\n```\n2017.01.22-19:03:17.03 - \u003ctrace\u003e [example.c:71] Trace message throws source location.\n```\n\nIt can also trace source location without any output message:\n```c\nslog_trace();\n```\n\nWith an expected output to be:\n```\n2017.01.22-19:03:17.03 - \u003ctrace\u003e [example.c:72]\n```\n\n*Output, taken from example directory:*\n\n![alt tag](https://github.com/kala13x/slog/blob/master/screens/slog.png)\n\n### Configuration\n\nVariables of `slog_config_t` structure:\nParameter    | Type              | Default           | Description\n-------------|-------------------|-------------------|---------------------------\nsFileName    | char array        | \"slog\"            | Output file name for logs.\nsFilePath    | char array        | \"./\"              | Output file path for logs.\nsSeparator   | char array        | \" \"               | Separator between info and log.\nlogCallback  | slog_cb_t         | NULL              | Centralized log callback function.\npCallbackCtx | void*             | NULL              | User data pointer passed to log callback.\neColorFormat | slog_coloring_t   | SLOG_COLORING_TAG | Output coloring format control.\neDateControl | slog_date_ctrl_t  | SLOG_TIME_ONLY    | Time and date control in the log output.\nnKeepOpen    | uint8_t           | 1 (enabled)       | Keep the file handle open for future writes.\nnTraceTid    | uint8_t           | 0 (disabled)      | Trace thread ID and display in output.\nnToScreen    | uint8_t           | 1 (enabled)       | Enable or disable screen logging.\nnUseHeap     | uint8_t           | 0 (disabled)      | Use dynamic allocation for output.\nnToFile      | uint8_t           | 0 (disabled)      | Enable or disable file logging.\nnIndent      | uint8_t           | 0 (disabled)      | Enable or disable indentations.\nnRotate      | uint8_t           | 1 (enabled)       | Create new log file for each day.\nnFlush       | uint8_t           | 0 (disabled)      | Flush output file after log.\nnFlags       | uint16_t          | 0 (no logs)       | Enabled log flags.\n\nAny of those parameters above can be changed at runtime with the `slog_config_set()` function.\n\nExample:\n```c\nslog_config_t slgCfg;\n\n/* Setup configuration parameters */\nslgCfg.eColorFormat = SLOG_COLORING_TAG;\nslgCfg.eDateControl = SLOG_TIME_ONLY;\nstrcpy(slgCfg.sFileName, \"myproject\");\nstrcpy(slgCfg.sFilePath, \"./logs/\");\nslgCfg.logCallback = NULL;\nslgCfg.pCallbackCtx = NULL;\nslgCfg.nKeepOpen = 1;\nslgCfg.nTraceTid = 1;\nslgCfg.nToScreen = 1;\nslgCfg.nUseHeap = 0;\nslgCfg.nToFile = 0;\nslgCfg.nFlush = 1;\nslgCfg.nFlags = SLOG_FLAGS_ALL;\n\n/* Tread safe call to update slog configuration */\nslog_config_set(\u0026slgCfg);\n```\n\nIf you want to change only a few parameters without resetting other ones, you can thread safely read the current working configuration and update only the needed parameters.\n\n```c\nslog_config_t slgCfg;\nslog_config_get(\u0026slgCfg);\n\n/* Update needed parameters */\nslgCfg.nTraceTid = 1;\nslgCfg.nToFile = 1;\n\n/* Tread safe call to update slog configuration */\nslog_config_set(\u0026slgCfg);\n```\n\n### Dynamic allocation\nIf the output message is larger than the slog default message limit (8196 bytes) there is a possibility to enable dynamic allocation and use the heap for output messages:\n```c\nslog_config_t slgCfg;\nslog_config_get(\u0026slgCfg);\nslgCfg.nUseHeap = 1;\nslog_config_set(\u0026slgCfg);\n\nslog_debug(\"Your too big output message here\");\n```\n\n### Coloring\nSLog also has a coloring control and the possibility to colorize whole lines, just tag or disable coloring.\n```c\nslog_config_t slgCfg;\nslog_config_get(\u0026slgCfg);\n\n/* Colorize only tags */\nslgCfg.eColorFormat = SLOG_COLORING_TAG;\nslog_config_set(\u0026slgCfg);\nslog_debug(\"Message with colorized tag\");\n\n/* Colorize full line */\nslgCfg.eColorFormat = SLOG_COLORING_FULL;\nslog_config_set(\u0026slgCfg);\nslog_debug(\"Message with full line color\");\n\n/* Disable coloring at all */ \nslgCfg.eColorFormat = SLOG_COLORING_DISABLE;\nslog_config_set(\u0026slgCfg);\nslog_debug(\"Message without coloring\");\n```\n\n### Time and date\nSLog allows you to control the time and date format in the log output.\n```c\nslog_config_t slgCfg;\nslog_config_get(\u0026slgCfg);\n\n/* Disable time and date in output */\nslgCfg.eDateControl = SLOG_TIME_DISABLE;\nslog_config_set(\u0026slgCfg);\nslog_debug(\"Message without time and date\");\n\n/* Enable only time in output */\nslgCfg.eDateControl = SLOG_TIME_ONLY;\nslog_config_set(\u0026slgCfg);\nslog_debug(\"Message with time only\");\n\n/* Enable date + time in output */ \nslgCfg.eDateControl = SLOG_DATE_FULL;\nslog_config_set(\u0026slgCfg);\nslog_debug(\"Message with time and date\");\n```\n\nExample output:\n```\n\u003cdebug\u003e Message without time and date\n02:11:33.36 - \u003cdebug\u003e Message with time only\n2021.05.23-02:11:34.36 - \u003cdebug\u003e Message with time and date\n```\n\n### Thread ID tracing\nIf you are looking for additional information about threads while debugging, you can trace thread IDs and display them in the output.\n\nHere is an example:\n```c\nslog_config_t slgCfg;\nslog_config_get(\u0026slgCfg);\nslgCfg.nTraceTid = 1;\nslog_config_set(\u0026slgCfg);\n\nslog_debug(\"Message with thread id\");\n```\n\nWith an expected output to be:\n```\n(15203) 2017.01.22-19:03:17.03 - \u003cdebug\u003e Message with thread id.\n```\nWhere `15203` is a thread identifier from which the message was printed.\n\n\n### Indentations\nWith an enabled indentation flag, slog will automatically adjust the spacing between the information and the message.\n\n```c\nslog_config_t slgCfg;\nslog_config_get(\u0026slgCfg);\nslgCfg.nIndnets = 1;\nslog_config_set(\u0026slgCfg);\n```\n\nWith indentations enabled:\n\n![alt tag](https://github.com/kala13x/slog/blob/master/screens/indent.png)\n\nWithout indentations enabled:\n\n![alt tag](https://github.com/kala13x/slog/blob/master/screens/no-indent.png)\n\n\n### Callback\nIf you want to collect logs for any purpose, use a callback function pointer. If this pointer is set, any log will be passed to the function this pointer points to.\n```c\nint log_callback(const char *pLog, size_t nLength, slog_flag_t eFlag, void *pCtx)\n{\n    (void)nLength; // Log message length\n    (void)eFlag; // Logging flag of this message\n    (void)pCtx; // Optional pointer passed to the callback\n\n    printf(\"%s\", pLog);\n    return 0;\n}\n\nint main()\n{\n    slog_init(\"logfile\", SLOG_FLAGS_ALL, 0);\n\n    slog_config_t slgCfg;\n    slog_config_get(\u0026slgCfg);\n    slgCfg.logCallback = log_callback;\n    slgCfg.pCallbackCtx = NULL; // Optional pointer passed to the callback\n    slog_config_set(\u0026slgCfg);\n\n    slog(\"This message will be passed to the callback function\");\n\n    slog_destroy();\n    return 0;\n}\n```\n\nIf you return `-1` from the callback function, the log will no longer be printed to the screen or written to a file by `slog`. If you return `0`, the log will not be written to the screen but still to a file (if nToFile \u003e 1). If you return `1` the logger will normally continue its routine.\n\n### Version\nGet `slog` version with the function `slog_version()`. The argument `uint8_t nShort` is a flag to get a short or full string of the version (1 short, 0 full).\n\nUsage:\n```c\nprintf(\"slog version: %s\", slog_version(0));\n```\n\nThe output will be something like this:\n```\nslog version: 1.8 build 22 (Dec 14 2020)\n```\n\nThere are also definitions that can be used to check the version without using the function.\n\n- `SLOG_VERSION_MAJOR` - Major version of the library.\n- `SLOG_VERSION_MINOR` - Minor version of the library.\n- `SLOG_BUILD_NUMBER` - Build number.\n\n\n### Output\nHere is an example of the log file context created by Slog:\n```\nSimple message without anything\n02:11:34.36 - Simple message with time only\n02:11:34.36 - Simple message with our own new line character\n02:11:34.36 - \u003cdebug\u003e Old way printed debug message with our own new line character\n02:11:34.36 - \u003cerror\u003e Old way printed error message with auto new line character\n02:11:34.36 - \u003cwarn\u003e Warning message without variable\n02:11:34.36 - \u003cinfo\u003e Info message with string variable: test string\n02:11:34.36 - \u003cnote\u003e Note message with integer variable: 69\n(8180) 02:11:34.36 - \u003cdebug\u003e Debug message with enabled thread id tracing\n(8180) 02:11:34.36 - \u003cerror\u003e Error message with errno string: Success\n(8180) 02:11:34.36 - \u003cdebug\u003e Debug message in the file with full line color enabled\n(8180) 02:11:34.36 - \u003ctrace\u003e [example.c:105] Trace message throws source location\n(8180) 02:11:34.36 - \u003cfatal\u003e [example.c:108] Fatal message also throws source location\n(8180) 2021.05.23-02:11:34.36 - \u003cdebug\u003e Debug message with time and date\n(8180) 2021.05.23-02:11:34.36 - \u003cdebug\u003e Disabled output coloring\n(8180) 2021.05.23-02:11:34.36 - \u003ctrace\u003e [example.c:124] \n(8180) 2021.05.23-02:11:34.36 - \u003cdebug\u003e Above we traced source location without output message\n\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkala13x%2Fslog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkala13x%2Fslog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkala13x%2Fslog/lists"}