Skip to content

LazarusID/yder

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Yder

Logging library written in C.

Simple and easy to use logging library. You can log messages to the console, a file or syslog.

Yder is mono-thread, which mean that you can use only one instance of yder log at the same time in your program.

Installation

Debian-ish packages

Packaging status

Yder is now available in Debian Buster (testing) and some Debian based distributions. To install it on your device, use the following command as root:

# apt install libyder-dev # Or apt install libyder.1 if you don't need the development files

Pre-compiled packages

You can install Yder with a pre-compiled package available in the release pages. Note that you need to install Orcania first. jansson development files packages is required to install Yder.

Manual install

Prerequisites

You must install liborcania first before building libyder. Orcania will be automatically installed if missing and you're using cmake.

CMake - Multi architecture

CMake minimum 3.5 is required.

Run the cmake script in a subdirectory, example:

$ git clone https://github.com/babelouest/yder.git
$ cd yder/
$ mkdir build
$ cd build
$ cmake ..
$ make && sudo make install

The available options for cmake are:

  • -DBUILD_STATIC=[on|off] (default off): Build the static archive in addition to the shared library
  • -DBUILD_TESTING=[on|off] (default off): Build unit tests
  • -DINSTALL_HEADER=[on|off] (default on): Install header file yder.h
  • -DCMAKE_BUILD_TYPE=[Debug|Release] (default Release): Compile with debugging symbols or not

Good ol' Makefile

Download yder from github repository, compile and install.

$ git clone https://github.com/babelouest/yder.git
$ cd yder/src
$ make
$ sudo make install

By default, the shared library and the header file will be installed in the /usr/local location. To change this setting, you can modify the PREFIX value in the src/Makefile.

Example: install yder in /tmp/lib directory

$ cd src
$ make && make PREFIX=/tmp install

You can install Yder without root permission if your user has write access to $(PREFIX). A ldconfig command is executed at the end of the install, it will probably fail if you don't have root permission, but this is harmless. If you choose to install Yder in another directory, you must set your environment variable LD_LIBRARY_PATH properly.

Install libyder as a static archive

Install byderlibrary as a static archive, libyder.a, use the make commands make static*:

$ cd src
$ make static && sudo make static-install # or make PREFIX=/tmp static-install if you want to install in `/tmp/lib`

API Documentation

Header files and compilation

To use yder in your code, you must include the file yder.h.

#include <yder.h>

Initialization

Use the y_init_logs function to start logging. The prototype of this function is:

/**
 * Initialize logging with mode and level parameters, specify a log file if needed
 * Return true on success, false on error
 */
int y_init_logs(const char * app, const unsigned long init_mode, const unsigned long init_level, const char * init_log_file, const char * message);

The parameter init_mode is the initial mode for logging. You can specify and combine the following modes available:

Y_LOG_MODE_CONSOLE
Y_LOG_MODE_SYSLOG
Y_LOG_MODE_FILE

If you use Y_LOG_MODE_FILE in your initial mode, you must specify a valid path for the init_log_file parameter.

The parameter init_level is the bottom level of your log messages. The levels available are, by level order:

Y_LOG_LEVEL_NONE
Y_LOG_LEVEL_ERROR
Y_LOG_LEVEL_WARNING
Y_LOG_LEVEL_INFO
Y_LOG_LEVEL_DEBUG

For example, if you specify Y_LOG_LEVEL_WARNING as init_level, you will see in your log output only Y_LOG_LEVEL_WARNING and Y_LOG_LEVEL_ERROR. If you specify Y_LOG_LEVEL_DEBUG, you will see in your log output all log messages.

Close yder

To close yder and free its allocated memory, use the function y_close_logs:

/**
 * Close the logs
 */
int y_close_logs();

Log a message

To log a message, use the function y_log_message, defined by:

/**
 * Log a message using current parameters
 */
void y_log_message(const unsigned long type, const char * message, ...);

This function uses printf prototype for the message and the log message type. For example:

y_log_message(Y_LOG_LEVEL_INFO, "Initializing application");
y_log_message(Y_LOG_LEVEL_ERROR, "Error in application, you have %d over %d threads in error mode", threads_error, threads_total);

Example source code

See examples folder for detailed sample source codes.

About

Logging library for C applications

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • CMake 63.2%
  • C 26.1%
  • Makefile 10.7%