Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ $ 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.
it. The command mentioned above are for linux. Other systems will need a similar set of actions.

## 2. Configuration file

Expand Down
8 changes: 4 additions & 4 deletions doc/GettingStart-EN.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ $ 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.
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 mentioned above are for linux. Other systems will need a similar set of actions.


2. Introduce configure file
Expand Down Expand Up @@ -81,7 +81,7 @@ int main(int argc, char** argv)
return 0;
}

4. Complie, and run it!s
4. Compile, 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
Expand All @@ -91,7 +91,7 @@ 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
* multiple output destinations including static file path, dynamic file path, stdout, stderr, syslog, user-defined output
* runtime manually or automatically refresh configure(safely)
* high-performance, 250'000 logs/second on my laptop, about 1000 times faster than syslog(3) with rsyslogd
* user-defined log level
Expand All @@ -110,5 +110,5 @@ Downloads: https://github.com/HardySimpson/zlog/releases
Author's Email: HardySimpson1984@gmail.com

auto tools version: https://github.com/bmanojlovic/zlog
cmake verion: https://github.com/lisongmin/zlog
cmake version: https://github.com/lisongmin/zlog
windows version: https://github.com/lopsd07/WinZlog
4 changes: 2 additions & 2 deletions doc/UsersGuide-CN.lyx
Original file line number Diff line number Diff line change
Expand Up @@ -5064,7 +5064,7 @@ $ zlog-chk-conf -h
\end_layout

\begin_layout LyX-Code
Useage: zlog-chk-conf [conf files]...
Usage: zlog-chk-conf [conf files]...

\end_layout

Expand Down Expand Up @@ -5591,7 +5591,7 @@ line
\bar under
func
\bar default
填写为__func__或者__FUNCTION__,如果编译器支持的话,如果不支持,就填写为"<unkown>"。
填写为__func__或者__FUNCTION__,如果编译器支持的话,如果不支持,就填写为"<unknown>"。
\end_layout

\begin_layout Standard
Expand Down
36 changes: 18 additions & 18 deletions doc/UsersGuide-EN.lyx
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ log format customization

\begin_layout Itemize
multiple output, include static file path, dynamic file path, stdout, stderr,
syslog, user-defined ouput
syslog, user-defined output
\end_layout

\begin_layout Itemize
Expand Down Expand Up @@ -351,7 +351,7 @@ literal "false"
\end_layout

\begin_layout Standard
cmake verion:
cmake version:
\begin_inset CommandInset href
LatexCommand href
target "https://github.com/lisongmin/zlog"
Expand Down Expand Up @@ -390,7 +390,7 @@ zlog 1.2 provides these features:
\begin_deeper
\begin_layout Enumerate
support for pipeline.
Now zlog can send ouput log through programs like cronolog
Now zlog can send output log through programs like cronolog
\end_layout

\begin_layout Enumerate
Expand Down Expand Up @@ -1134,7 +1134,7 @@ But in bb.log, there will be two
\begin_layout Standard
From this example, you see the difference.
Log4j can not do it easily.
In zlog, one category may correspond to mutiple rules, and rules can have
In zlog, one category may correspond to multiple rules, and rules can have
different level, output, and format combinations.
The user has an easy, clear way to filter and multi-ouput all logs on demand.
\end_layout
Expand All @@ -1145,7 +1145,7 @@ Expand syslog model

\begin_layout Standard
You can see that category in zlog is more like facility in syslog.
Unfortunately, facility in sylog is an int, and the value of facility must
Unfortunately, facility in syslog is an int, and the value of facility must
be chosen from a limited system-defined range.
zlog does better, making it a string variable.
\end_layout
Expand Down Expand Up @@ -1510,7 +1510,7 @@ mutex_lock is for multi-thread and fcntl_lock is for multi-process.
The lock is system-wide, and when a process dies unexpectedly, the operating
system releases all locks owned by the process.
That's why I chose fcntl lock for rotating log safely.
The process needs read-write permisson for lock_file to lock it.
The process needs read-write permission for lock_file to lock it.
\end_layout

\begin_layout Standard
Expand Down Expand Up @@ -1678,7 +1678,7 @@ reference "ite:synchronous-I/O-file"

\end_inset

.The defualt is 0, which means let the operating system flush the output
.The default is 0, which means let the operating system flush the output
buffer when it wants.

\end_layout
Expand Down Expand Up @@ -4320,7 +4320,7 @@ This section begins with [rules].

\begin_layout Standard
When zlog_init() is called, all rules will be read into memory.
When zlog_get_category() is called, mutiple rules will be assigned to each
When zlog_get_category() is called, multiple rules will be assigned to each
category, in the way
\begin_inset CommandInset ref
LatexCommand ref
Expand Down Expand Up @@ -5031,7 +5031,7 @@ This is an example of how zlog pipelines its output to cronolog.
zlog_init(), and forward logs will be written to the open descriptor in
the "normal" format.
Writing through pipeline and cronnolog is faster than dynamic file of zlog,
as there is no need to open and close file descripter each time when logs
as there is no need to open and close file descriptor each time when logs
are written to a pipe.
\end_layout

Expand Down Expand Up @@ -5484,7 +5484,7 @@ Using zlog, there is no need for external rotate action to complete the
\end_layout

\begin_layout Standard
or using cronolog for faster performace:
or using cronolog for faster performance:
\end_layout

\begin_layout LyX-Code
Expand Down Expand Up @@ -5746,7 +5746,7 @@ $ zlog-chk-conf -h
\end_layout

\begin_layout LyX-Code
Useage: zlog-chk-conf [conf files]...
Usage: zlog-chk-conf [conf files]...

\end_layout

Expand Down Expand Up @@ -6409,7 +6409,7 @@ ZLOG_LEVEL_FATAL = 120
\end_layout

\begin_layout Standard
Each fuction has its macros for easy use.
Each function has its macros for easy use.
For example,
\end_layout

Expand Down Expand Up @@ -7082,7 +7082,7 @@ record
\end_layout

\begin_layout Standard
The members of struct zlog_msg_t are decribed below:
The members of struct zlog_msg_t are described below:
\end_layout

\begin_layout Standard
Expand Down Expand Up @@ -7480,7 +7480,7 @@ $ grep Li aa.log >Li.log
\end_layout

\begin_layout Standard
Or, another way is to seperate them to different log file when log action
Or, another way is to separate them to different log file when log action
is taken.
In .conf
\end_layout
Expand Down Expand Up @@ -7590,7 +7590,7 @@ zlog.error.log is not created, as no error occurs.
\begin_layout Standard
As you can see, debug log shows how zlog is inited and finished, but no
debug log is written when zlog_info() is executed.
That's for efficency.
That's for efficiency.
\end_layout

\begin_layout Standard
Expand Down Expand Up @@ -7651,7 +7651,7 @@ Now, you could find the reason why the expected log doesn't generate, and
\end_layout

\begin_layout Standard
Runtime profiling causes a loss of efficency.
Runtime profiling causes a loss of efficiency.
Normally, I keep ZLOG_PROFILE_ERROR on and ZLOG_PROFILE_DEBUG off in my
environment.

Expand Down Expand Up @@ -7980,7 +7980,7 @@ means that level >= TRACE, which is TRACE, INFO, NOTICE, WARN, ERROR, FATAL
\end_layout

\begin_layout Standard
The conversion charactor %V of format string generates the uppercase value
The conversion character %V of format string generates the uppercase value
of the level string and %v generates the lowercase value of the level string.
\end_layout

Expand Down Expand Up @@ -8247,7 +8247,7 @@ INFO info hello, zlog - info

\begin_layout Standard
That's just what we expect.
The configuration file only allows >=TRACE ouput to screen.
The configuration file only allows >=TRACE output to screen.
And %V and %v work as well.
\end_layout

Expand Down
36 changes: 18 additions & 18 deletions doc/UsersGuide-EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ zlog has these features:

* syslog model, better than log4j model
* log format customization
* multiple output, include static file path, dynamic file path, stdout, stderr, syslog, user-defined ouput
* multiple output, include static file path, dynamic file path, stdout, stderr, syslog, user-defined output
* runtime with manual or automatic refresh of configuration (done safely)
* high-performance, 250’000 logs/second on my laptop, about 1000 times faster than syslog(3) with rsyslogd
* user-defined log level
Expand Down Expand Up @@ -93,7 +93,7 @@ Author’s Email: [HardySimpson1984@gmail.com](mailto:HardySimpson1984@gmail.com

auto tools version: [https://github.com/bmanojlovic/zlog](https://github.com/bmanojlovic/zlog)

cmake verion: [https://github.com/lisongmin/zlog](https://github.com/lisongmin/zlog)
cmake version: [https://github.com/lisongmin/zlog](https://github.com/lisongmin/zlog)

windows version: [https://github.com/lopsd07/WinZlog](https://github.com/lopsd07/WinZlog)

Expand All @@ -102,7 +102,7 @@ Author’s Email: [HardySimpson1984@gmail.com](mailto:HardySimpson1984@gmail.com
--------------------------

1. zlog 1.2 provides these features:
1. support for pipeline. Now zlog can send ouput log through programs like cronolog
1. support for pipeline. Now zlog can send output log through programs like cronolog
2. Full rotation support, see [5.6](#56-rotation)
3. Other code compatible details, bug fixes.
2. zlog 1.2 is binary compatible with zlog 1.0. The differences are:
Expand Down Expand Up @@ -406,12 +406,12 @@ But in bb.log, there will be two
2012-05-29 10:41:36 DEBUG [11288:test_hello.c:42] debug, zlog
```

From this example, you see the difference. Log4j can not do it easily. In zlog, one category may correspond to mutiple rules, and rules can have different level, output, and format combinations. The user has an easy, clear way to filter and multi-ouput all logs on demand.
From this example, you see the difference. Log4j can not do it easily. In zlog, one category may correspond to multiple rules, and rules can have different level, output, and format combinations. The user has an easy, clear way to filter and multi-ouput all logs on demand.

4.3 Expand syslog model
-----------------------

You can see that category in zlog is more like facility in syslog. Unfortunately, facility in sylog is an int, and the value of facility must be chosen from a limited system-defined range. zlog does better, making it a string variable.
You can see that category in zlog is more like facility in syslog. Unfortunately, facility in syslog is an int, and the value of facility must be chosen from a limited system-defined range. zlog does better, making it a string variable.

In syslog, there is a special wildcard "\*", which matches all facilities. It does the same thing in zlog. "\*" matches all categories. That is a convenient way to make all errors generated by multiple components in your system redirect to one log file. Just write in the configuration file like this:

Expand Down Expand Up @@ -544,7 +544,7 @@ Global section begins with \[global\]. This section can be omitted.The syntax is
pthread_mutex_unlock;
```

mutex\_lock is for multi-thread and fcntl\_lock is for multi-process. fcntl\_lock is the POSIX advisory record locking. See man 3 fcntl for details. The lock is system-wide, and when a process dies unexpectedly, the operating system releases all locks owned by the process. That’s why I chose fcntl lock for rotating log safely. The process needs read-write permisson for lock\_file to lock it.
mutex\_lock is for multi-thread and fcntl\_lock is for multi-process. fcntl\_lock is the POSIX advisory record locking. See man 3 fcntl for details. The lock is system-wide, and when a process dies unexpectedly, the operating system releases all locks owned by the process. That’s why I chose fcntl lock for rotating log safely. The process needs read-write permission for lock\_file to lock it.

By default, rotate lock file = self. This way, zlog does not create any lock file and sets the configuration file as the lock file. As fcntl is advisory, it does not really forbid programmers to change and store the configuration file. Generally speaking, one log file will not be rotated by processes run by different operating system users, so using the configuration file as lock file is safe.

Expand Down Expand Up @@ -598,7 +598,7 @@ Global section begins with \[global\]. This section can be omitted.The syntax is
sys 0m0.550s
```

If you want extreme safety but do not care about speed, use synchronous file I/O, see [5.5.3](https://hardysimpson.github.io/zlog/UsersGuide-EN.html#ite:synchronous-I/O-file).The defualt is 0, which means let the operating system flush the output buffer when it wants.
If you want extreme safety but do not care about speed, use synchronous file I/O, see [5.5.3](https://hardysimpson.github.io/zlog/UsersGuide-EN.html#ite:synchronous-I/O-file).The default is 0, which means let the operating system flush the output buffer when it wants.


5.2 Levels
Expand Down Expand Up @@ -757,7 +757,7 @@ This section begins with \[rules\]. It decides how log actions are filtered, for

`(category).(level) (output), (option,optional); (format name, optional)`

When zlog\_init() is called, all rules will be read into memory. When zlog\_get\_category() is called, mutiple rules will be assigned to each category, in the way [5.5.2](https://hardysimpson.github.io/zlog/UsersGuide-EN.html#sub:Category-Matching) describes. When logging is performed, the level between matched rules and INFO will be checked to decide whether this single log will be output through the rule. When zlog\_reload() is called, the configuration file will be re-read into memory, including rules. All category rules will be re-calculated.
When zlog\_init() is called, all rules will be read into memory. When zlog\_get\_category() is called, multiple rules will be assigned to each category, in the way [5.5.2](https://hardysimpson.github.io/zlog/UsersGuide-EN.html#sub:Category-Matching) describes. When logging is performed, the level between matched rules and INFO will be checked to decide whether this single log will be output through the rule. When zlog\_reload() is called, the configuration file will be re-read into memory, including rules. All category rules will be re-calculated.

### 5.5.1 Level Matching

Expand Down Expand Up @@ -814,7 +814,7 @@ zlog supports various output methods. The syntax is

`*.* | /usr/bin/cronolog /www/logs/example_%Y%m%d.log ; normal`

This is an example of how zlog pipelines its output to cronolog. The implementation is simple. popen("/usr/bin/cronolog /www/logs/example\_%Y%m%d.log","w") is called at zlog\_init(), and forward logs will be written to the open descriptor in the "normal" format. Writing through pipeline and cronnolog is faster than dynamic file of zlog, as there is no need to open and close file descripter each time when logs are written to a pipe.
This is an example of how zlog pipelines its output to cronolog. The implementation is simple. popen("/usr/bin/cronolog /www/logs/example\_%Y%m%d.log","w") is called at zlog\_init(), and forward logs will be written to the open descriptor in the "normal" format. Writing through pipeline and cronnolog is faster than dynamic file of zlog, as there is no need to open and close file descriptor each time when logs are written to a pipe.

```bash
[rules]
Expand Down Expand Up @@ -979,7 +979,7 @@ Why rotation I have see more than once in a production environment, that the har

`*.* "aa.%d(%F).log"`

or using cronolog for faster performace:
or using cronolog for faster performance:

`*.* | cronolog aa.%F.log`

Expand Down Expand Up @@ -1087,7 +1087,7 @@ For zlog as a library, it is not good to receive signals. zlog provide zlog\_rel
```bash
$ zlog-chk-conf -h

Useage: zlog-chk-conf [conf files]...
Usage: zlog-chk-conf [conf files]...

-q, suppress non-error message

Expand Down Expand Up @@ -1267,7 +1267,7 @@ ZLOG_LEVEL_FATAL = 120
} zlog_level;
```

Each fuction has its macros for easy use. For example,
Each function has its macros for easy use. For example,

```c
#define zlog_fatal(cat, format, args...)
Expand Down Expand Up @@ -1480,7 +1480,7 @@ zlog allows a user to define an output function. The output function bonds to a

zlog\_set\_record() does the bonding operation. Rules with the $rname will be output through user-defined function record. The callback function has the type of zlog\_record\_fn.

The members of struct zlog\_msg\_t are decribed below:
The members of struct zlog\_msg\_t are described below:

path comes from the second parameter of rule after $name, which is generated dynamically like the file path.

Expand Down Expand Up @@ -1654,7 +1654,7 @@ $ grep Zhang aa.log > Zhang.log
$ grep Li aa.log >Li.log
```

Or, another way is to seperate them to different log file when log action is taken. In .conf
Or, another way is to separate them to different log file when log action is taken. In .conf

`*.* "mdc_%M(customer_name).log";`

Expand Down Expand Up @@ -1695,7 +1695,7 @@ $ more zlog.debug.log

zlog.error.log is not created, as no error occurs.

As you can see, debug log shows how zlog is inited and finished, but no debug log is written when zlog\_info() is executed. That’s for efficency.
As you can see, debug log shows how zlog is inited and finished, but no debug log is written when zlog\_info() is executed. That’s for efficiency.

If there is anything wrong with zlog library, all will show in zlog.error.log. For example, using a wrong printf syntax in zlog()

Expand Down Expand Up @@ -1725,7 +1725,7 @@ $ cat zlog.error.log

Now, you could find the reason why the expected log doesn’t generate, and fix the wrong printf syntax.

Runtime profiling causes a loss of efficency. Normally, I keep ZLOG\_PROFILE\_ERROR on and ZLOG\_PROFILE\_DEBUG off in my environment.
Runtime profiling causes a loss of efficiency. Normally, I keep ZLOG\_PROFILE\_ERROR on and ZLOG\_PROFILE\_DEBUG off in my environment.

There is another way to profile the zlog library. zlog\_init() reads the configuration file into memory. Throughout all log actions, the configure structure remains unchanged. There is possibility that this memory is damaged by other functions in an application, or the memory doesn’t equal what the configuration file describes. So there is a function to show this memory at runtime and print it to ZLOG\_PROFILE\_ERROR.

Expand Down Expand Up @@ -1872,7 +1872,7 @@ Here are all the steps to define your own levels.

means that level >= TRACE, which is TRACE, INFO, NOTICE, WARN, ERROR, FATAL will be written to standard output.

The conversion charactor %V of format string generates the uppercase value of the level string and %v generates the lowercase value of the level string.
The conversion character %V of format string generates the uppercase value of the level string and %v generates the lowercase value of the level string.

In the level definition LOG\_DEBUG means when using >syslog in a rule, all TRACE log will output as syslog’ s LOG\_DEBUG level.

Expand Down Expand Up @@ -1978,7 +1978,7 @@ Here are all the steps to define your own levels.
INFO info hello, zlog - info
```

That’s just what we expect. The configuration file only allows >=TRACE ouput to screen. And %V and %v work as well.
That’s just what we expect. The configuration file only allows >=TRACE output to screen. And %V and %v work as well.


7.4 User-defined Output
Expand Down
2 changes: 1 addition & 1 deletion note.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ w thread:
check if reload config


category -> standlone, per print, shared by threads
category -> standalone, per print, shared by threads
rule * n // ref conf.rules

conf.formats
Expand Down
Loading
Loading