Difference between revisions of "AdvLog"

From ESS-WIKI
Jump to: navigation, search
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
== Introduction ==
 
== Introduction ==
  
This logging library provides one sample way(which is like printf function) to log messages from application, and has many modern features which are listed below
+
This logging library provides one sample way(which is like printf function) to log messages from application, and has many modern features as below
  
 
#Showing on console and storing into storage in the same time.
 
#Showing on console and storing into storage in the same time.
Line 7: Line 7:
 
#Support two kinds of record format in text and HTML.
 
#Support two kinds of record format in text and HTML.
 
#Rolling file to avoid out of storage.
 
#Rolling file to avoid out of storage.
#Support three storage policies to limit the number of amount in folder, the number of file in current process and the size of current file.
+
#Support three storing policies to limit the number of amount in folder, the number of file in current process and the size of current file.
 
#Support remote control to change setting dynamically.
 
#Support remote control to change setting dynamically.
  
 
== Functions ==
 
== Functions ==
 +
 
*ADV_PRINT(level, fmt, ...)
 
*ADV_PRINT(level, fmt, ...)
 +
 +
::level: debug level.
 +
::fmt: format like printf.
 +
::...: arguments like printf.
 +
 
*ADV_C_PRINT(level, color, fmt, ...)
 
*ADV_C_PRINT(level, color, fmt, ...)
 +
 +
::level: debug level.
 +
::color: color code.
 +
::fmt: format like printf.
 +
::...: arguments like printf.
  
 
== Configure File Format ==
 
== Configure File Format ==
Line 56: Line 67:
  
 
*[hide]:Hide DYNAMIC message (default:"", example:"1,3,5" to hide level 1, 3 and 5 message)
 
*[hide]:Hide DYNAMIC message (default:"", example:"1,3,5" to hide level 1, 3 and 5 message)
 +
 
== Remote control ==
 
== Remote control ==
  
 
You can only use the following code to realize your remote control application.
 
You can only use the following code to realize your remote control application.
<syntaxhighlight lang="c">
+
<syntaxhighlight lang="c">#include <unistd.h>
#include <unistd.h>
 
 
#include <stdarg.h>
 
#include <stdarg.h>
 
#include "AdvLog.h"
 
#include "AdvLog.h"
Line 67: Line 78:
 
AdvLog_Control(argc, argv);
 
AdvLog_Control(argc, argv);
 
}
 
}
</syntaxhighlight>and the HELP is showed as below.<syntaxhighlight lang="c">
+
</syntaxhighlight>and the HELP is showed as below.<syntaxhighlight lang="c">Option -p [pid]: Set pid *(MUST be ASSIGNED)*
Option -p [pid]: Set pid *(MUST be ASSIGNED)*
 
  
 
Option -s [level]: Set STATIC level ------------------------------------------------ (default:5) (positive means HTML mode, negative means text mode)
 
Option -s [level]: Set STATIC level ------------------------------------------------ (default:5) (positive means HTML mode, negative means text mode)
Line 86: Line 96:
  
 
Option -v: Show all parameter
 
Option -v: Show all parameter
</syntaxhighlight> An example is<syntaxhighlight lang="c">
+
</syntaxhighlight> An example is<syntaxhighlight lang="c">./logconf -p [your pid] -v
./logconf -p [your pid] -v
+
</syntaxhighlight> and will show
</syntaxhighlight> and will show<syntaxhighlight lang="c">
+
<pre>
 
[s]Static Level: 5
 
[s]Static Level: 5
 
[i]Static Info: 1
 
[i]Static Info: 1
Line 100: Line 110:
 
[f]Configure file: ./log.ini
 
[f]Configure file: ./log.ini
 
[m]Configure name: default
 
[m]Configure name: default
</syntaxhighlight>
+
</pre>
  
 
== Output Log Format ==
 
== Output Log Format ==

Latest revision as of 03:47, 8 October 2018

Introduction

This logging library provides one sample way(which is like printf function) to log messages from application, and has many modern features as below

  1. Showing on console and storing into storage in the same time.
  2. Be colorful and gradational to highlight information.
  3. Support two kinds of record format in text and HTML.
  4. Rolling file to avoid out of storage.
  5. Support three storing policies to limit the number of amount in folder, the number of file in current process and the size of current file.
  6. Support remote control to change setting dynamically.

Functions

  • ADV_PRINT(level, fmt, ...)
level: debug level.
fmt: format like printf.
...: arguments like printf.
  • ADV_C_PRINT(level, color, fmt, ...)
level: debug level.
color: color code.
fmt: format like printf.
...: arguments like printf.

Configure File Format

Configure file is in JSON Format:

{
    "default":  {
        "static":  {
            "level":  5,
            "information":  1
        },
        "dynamic":  {
            "level":  5,
            "information":  0,
            "hide":  ""
        },
        "path":  "./logs",
        "files":  30,
        "limit":  102400,
        "number":  2
    }
}
  • [path]: set log files path (default:./logs)
  • [files]: set the max existing file number of all the files in the log path (a.k.a amount) (default:100, min:30, max:200)
  • [limit]: set the max rolling threshold byte of this process -------------- (unit: byte) (default:102400, min:10240)
  • [number]: set the max rolling file number of this process ---------------- (a.k.a count) (default:2, min:2, max:20)
  • [static/dynamic]: "static" means the settings of writing to log file. "dynamic" means the setting of display on console.
  • [level]: Set log level (default:5)(negative means gray mode in dynamic and  text mode in static),
1:Fatal
2:Error
3:Warning
4:Notice
5:Info(Normal)
7:Debug
  • [information]: Enable additional information Flag(default:0)
0: No other information;
1: Showing timestamp, message level, file path, line number and etc.
  • [hide]:Hide DYNAMIC message (default:"", example:"1,3,5" to hide level 1, 3 and 5 message)

Remote control

You can only use the following code to realize your remote control application.

#include <unistd.h>
#include <stdarg.h>
#include "AdvLog.h"

int main(int argc, char **argv) {
	AdvLog_Control(argc, argv);
}
and the HELP is showed as below.
Option -p [pid]: Set pid *(MUST be ASSIGNED)*

Option -s [level]: Set STATIC level ------------------------------------------------ (default:5) (positive means HTML mode, negative means text mode)
Option -i [0|1]: Enable STATIC info ------------------------------------------------ (default:1)

Option -d [level]: Set DYNAMIC level ----------------------------------------------- (default:5) (positive means colorful mode, negative means gray mode)
Option -j [0|1]: Enable DYNAMIC info ----------------------------------------------- (default:0)
Option -b {level string}: Hide DYNAMIC message ------------------------------------- (default:"", example:"1,3,5")

Option -x [path]: set log files path ----------------------------------------------- (default:./logs)
Option -a [files]: set the max existing file number of all the files in the log path (a.k.a amount) (default:100, min:30, max:200)
Option -l [limit]: set the max rolling threshold byte of this process -------------- (unit: byte)   (default:102400, min:10240)
Option -n [number]: set the max rolling file number of this process ---------------- (a.k.a count)  (default:2, min:2, max:20)

Option -f: import configure file
Option -e: export configure file

Option -v: Show all parameter
An example is
./logconf -p [your pid] -v
and will show
[s]Static Level: 5
[i]Static Info: 1
[d]Dynamic Level: 5
[j]Dynamic Info: 1
[b]Hide:
[x]Path: ./logs
[a]Files: 30
[l]Limit: 10240
[n]Number: 5
[f]Configure file: ./log.ini
[m]Configure name: default

Output Log Format

Default output format is html file:

<!DOCTYPE html><html><head><style type="text/css">body{color:white;background-color:black}log{display:block;}red>script{color:red;background-color:black}red{color:red;background-color:black}green>script{color:green;background-color:black}green{color:green;background-color:black}yellow>script{color:yellow;background-color:black}yellow{color:yellow;background-color:black}blue>script{color:#1569C7;background-color:black}blue{color:#1569C7;background-color:black}purple>script{color:purple;background-color:black}purple{color:purple;background-color:black}cyan>script{color:cyan;background-color:black}cyan{color:cyan;background-color:black}gray{color:#1C1C1C;background-color:black}redbg>script{color:white;background-color:red}redbg{color:white;background-color:red}greenbg>script{color:white;background-color:green}greenbg{color:white;background-color:green}yellowbg>script{color:black;background-color:yellow}yellowbg{color:black;background-color:yellow}bluebg>script{color:white;background-color:blue}bluebg{color:white;background-color:blue}purplebg>script{color:white;background-color:purple}purplebg{color:white;background-color:purple}cyanbg>script{color:black;background-color:cyan}cyanbg{color:black;background-color:cyan}whitebg>script{color:black;background-color:white}whitebg{color:black;background-color:white}script{display:block;}</style></head><body><pre><log><code> general> Initialize
</code><gray>	[2016/06/29 16:27:42] [INFO] (.\SAGeneralHandler.c,General_Initialize,327)</gray>
</log><log><script type="text/plain"> general>Recv Topic [/cagent/admin/0000000BAB4231C8/agentcallbackreq] Data {"susiCommData":{"commCmd":2051,"requestID":0,"agentID":"","handlerName":"general","sendTS":1467188865}}
</script><gray>	[2016/06/29 16:27:45] [INFO] (.\SAGeneralHandler.c,General_HandleRecv,372)</gray>
</log><log><script type="text/plain"> general>Recv Topic [/cagent/admin/0000000BAB4231C8/agentcallbackreq] Data {"susiCommData":{"requestItems":{},"commCmd":2056,"requestID":0,"agentID":"","handlerName":"general","sendTS":1467188865}}
</script><gray>	[2016/06/29 16:27:45] [INFO] (.\SAGeneralHandler.c,General_HandleRecv,372)</gray>
</log></pre></body></html>
and showed on browser as below.
Output sample