Coder Social home page Coder Social logo

ulog's Introduction

ulog

Build Status

A library written in C/C ++ for printing logs of lightweight embedded devices.

Platforms and Dependent

  • Current version only supports unix-like platforms.
  • LOGGER_TOKEN and LOGGER_MULTI_TOKEN requires C++11 or GCC extension support, but other functions are not needed.

Features

  • Different log levels
  • Log color identification
  • Print token (any basic type is automatically recognized and printed)
  • Hex dump (print the hexadecimal content in the specified address)
  • Statistics code running time

Quick Demo

Code

#include "ulog/ulog.h"

#include <stdio.h>
#include <time.h>

static int put_str(void *user_data, const char *str) {
  user_data = user_data; // unused
#if defined(WIN32) || defined(__unix__) || defined(__APPLE__)
  return printf("%s", str);
#else
  return 0;  // Need to implement a function to put string
#endif
}

int main() {
  // Initial logger
  logger_set_output_callback(ULOG_GLOBAL, NULL, put_str);

  double pi = 3.14159265;
  // Different log levels
  LOGGER_TRACE("PI = %.3f", pi);
  LOGGER_DEBUG("PI = %.3f", pi);
  LOGGER_INFO("PI = %.3f", pi);
  LOGGER_WARN("PI = %.3f", pi);
  LOGGER_ERROR("PI = %.3f", pi);
  LOGGER_FATAL("PI = %.3f", pi);
  LOGGER_RAW("PI = %.3f\r\n", pi);

  // Output debugging expression
  LOGGER_TOKEN(pi);
  LOGGER_TOKEN(50 * pi / 180);
  LOGGER_TOKEN(&pi);  // print address of pi

  char *text = (char *)"Ulog is a micro log library.";
  LOGGER_TOKEN((char *)text);

  // Hex dump
  LOGGER_HEX_DUMP(text, 45, 16);

  // Output multiple tokens to one line
  time_t now = 1577259816;
  struct tm lt = *localtime(&now);

  LOGGER_MULTI_TOKEN(lt.tm_year + 1900, lt.tm_mon + 1, lt.tm_mday);
  LOGGER_MULTI_TOKEN(lt.tm_wday, lt.tm_hour, lt.tm_min, lt.tm_sec);

  // Output execution time of some statements
  LOGGER_TIME_CODE(

      uint32_t n = 1000 * 1000; while (n--);

  );

  return 0;
}

Output

example

Build and integration into the project

git submodule add https://github.com/ShawnFeng0/ulog.git
  1. As a submodule or Download the entire project.

If you use cmake (recommended):

  1. Configure the following in the cmakelists.txt of the main project:
add_subdirectory(ulog)
target_link_libraries(${PROJECT_NAME} PUBLIC ulog) # Link libulog.a and include ulog/include path

or:

  1. Add ulog/include to the include path of your project

  2. Add ulog / src / ulog.c to the project's source file list

Install (Optional, Only in Unix)

If you want to install this library system-wide, you can do so via

mkdir build && cd build
cmake ../
sudo make install

Document

Extension tools

logrotate

logrotate is a command-line tool for circularly writing the output of other programs to some files via a pipe ("|").

It is written using ulog's asynchronous fifo and extended headers for file loop writing.

Usage:

your_program | logrotate --file-path /tmp/example/log.txt --file-size=100000 --file-number=3

ulog's People

Contributors

shawnfeng0 avatar

Stargazers

 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

Forkers

richardwqj

ulog's Issues

Please release a new tag containing logrotate

Hi @shawnfeng0,

Thanks for the amazing tool :)

I was using the log_rotate program everyday and just found out that you migrated that tool to this repository.

However, the latest release tag - v0.4.0 does not seem to include the log_rotate tool yet.

May I kindly ask you to create a new tag that contains your latest code since I have a code to manually build it with the latest tag?

Thanks in advance.

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.