Skip to content

Commit

Permalink
doc: for README.md again
Browse files Browse the repository at this point in the history
  • Loading branch information
HardySimpson committed Nov 24, 2013
1 parent 13c1b31 commit ab52cbe
Showing 1 changed file with 54 additions and 44 deletions.
98 changes: 54 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
0. What is zlog?
-------------

zlog is a reliable, high-performance, thread safe, flexible, clear-model, pure C logging library.

Expand All @@ -7,27 +8,31 @@ zlog is a reliable, high-performance, thread safe, flexible, clear-model, pure C
It is faster, safer and more powerful than log4c. So it can be widely used.

1. Install
-------------

Downloads: https://github.com/HardySimpson/zlog/releases

$ tar -zxvf zlog-latest-stable.tar.gz
$ cd zlog-latest-stable/
$ make
$ sudo make install
$ tar -zxvf zlog-latest-stable.tar.gz
$ cd zlog-latest-stable/
$ make
$ sudo make install

or
$ make PREFIX=/usr/local/
$ sudo make PREFIX=/usr/local/ install

$ make PREFIX=/usr/local/
$ sudo make PREFIX=/usr/local/ install

PREFIX indicates the installation destination for zlog. After installation, refresh your dynamic linker to make sure your program can find zlog library.

$ sudo vi /etc/ld.so.conf
/usr/local/lib
$ sudo ldconfig
$ sudo vi /etc/ld.so.conf
/usr/local/lib
$ sudo ldconfig

Before running a real program, make sure libzlog.so is in the directory where the system's dynamic lib loader can find it. The command metioned above are for linux. Other systems will need a similar set of actions.


2. Introduce configure file
-------------

There are 3 important concepts in zlog: categories, formats and rules.

Expand All @@ -38,57 +43,59 @@ Formats describe log patterns, such as: with or without time stamp, source file,
Rules consist of category, level, output file (or other channel) and format. In brief, if the category string in a rule in the configuration file equals the name of a category variable in the source, then they match. Still there is complex match range of category. Rule decouples variable conditions. For example, log4j must specify a level for each logger(or inherit from father logger). That's not convenient when each grade of logger has its own level for output(child logger output at the level of debug, when father logger output at the level of error)

Now create a configuration file. The function zlog_init takes the files path as its only argument.
$ cat /etc/zlog.conf
$ cat /etc/zlog.conf

[formats]
simple = "%m%n"
[rules]
my_cat.DEBUG >stdout; simple
[formats]
simple = "%m%n"
[rules]
my_cat.DEBUG >stdout; simple

In the configuration file log messages in the category "my_cat" and a level of DEBUG or higher are output to standard output, with the format of simple(%m - usermessage %n - newline). If you want to direct out to a file and limit the files maximum size, use this configuration

my_cat.DEBUG "/var/log/aa.log", 1M; simple
my_cat.DEBUG "/var/log/aa.log", 1M; simple

3. Using zlog API in C source file
$ vi test_hello.c
-------------
$ vi test_hello.c

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

#include "zlog.h"
#include "zlog.h"

int main(int argc, char** argv)
{
int rc;
zlog_category_t *c;
int main(int argc, char** argv)
{
int rc;
zlog_category_t *c;

rc = zlog_init("/etc/zlog.conf");
if (rc) {
printf("init failed\n");
return -1;
}
rc = zlog_init("/etc/zlog.conf");
if (rc) {
printf("init failed\n");
return -1;
}

c = zlog_get_category("my_cat");
if (!c) {
printf("get cat fail\n");
zlog_fini();
return -2;
}
c = zlog_get_category("my_cat");
if (!c) {
printf("get cat fail\n");
zlog_fini();
return -2;
}

zlog_info(c, "hello, zlog");
zlog_info(c, "hello, zlog");

zlog_fini();
zlog_fini();

return 0;
}
return 0;
}

4. Complie, and run it!s

$ cc -c -o test_hello.o test_hello.c -I/usr/local/include
$ cc -o test_hello test_hello.o -L/usr/local/lib -lzlog -lpthread
$ ./test_hello
hello, zlog
-------------
$ cc -c -o test_hello.o test_hello.c - I/usr/local/include
$ cc -o test_hello test_hello.o -L/usr/local/lib -lzlog -lpthread
$ ./test_hello
hello, zlog

5. Advanced Usage
-------------
* syslog model, better than log4j model
* log format customization
* multiple output destinations including static file path, dynamic file path, stdout, stderr, syslog, user-defined ouput
Expand All @@ -103,12 +110,15 @@ hello, zlog
* No external dependencies, just based on a POSIX system and a C99 compliant vsnprintf.


6. Links:
6.Links:
-------------

Homepage: http://hardysimpson.github.com/zlog
Downloads: https://github.com/HardySimpson/zlog/releases
Author's Email: [email protected]

auto tools version: https://github.com/bmanojlovic/zlog
cmake verion: https://github.com/lisongmin/zlog
windows version: https://github.com/lopsd07/WinZlog
windows version: https://github.com/lopsd07/WinZlog# 开源中国社区


0 comments on commit ab52cbe

Please sign in to comment.