aura  0.1
 All Data Structures Functions Variables Modules Pages
slog.h
1 /*
2  * slog is Advanced logging library for C/C++
3  *
4  * Copyright (c) 2015 Sun Dro (a.k.a. 7th Ghost)
5  * Web: http://off-sec.com/ ; E-Mail: kala0x13@gmail.com
6  *
7  * This is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 3 of the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  */
17 
18 #ifndef SLOG_H
19 #define SLOG_H
20 #include <stdarg.h>
21 
22 /* For include header in CPP code */
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 
28 /* Definations for version info */
29 #define SLOGVERSION_MAX 1
30 #define SLOGVERSION_MIN 2
31 #define SLOGBUILD_NUM 63
32 
33 
34 /* Loging flags */
35 #define SLOG_LIVE 1
36 #define SLOG_INFO 2
37 #define SLOG_WARN 3
38 #define SLOG_DEBUG 4
39 #define SLOG_ERROR 5
40 #define SLOG_FATAL 6
41 #define SLOG_NONE 7
42 
43 
44 /* Date variables */
45 typedef struct {
46  int year;
47  int mon;
48  int day;
49  int hour;
50  int min;
51  int sec;
52 } SystemDate;
53 
54 
55 /* Flags */
56 typedef struct {
57  const char* fname;
58  int level;
59  int to_file;
60 } slog_flags;
61 
62 
63 /*
64  * Get library version. Function returns version and build number of slog
65  * library. Return value is char pointer. Argument min is flag for output
66  * format. If min is 0, function returns version in full format, if flag
67  * is 1 function returns only version number, For examle: 1.3.0
68  */
69 const char* slog_version(int min);
70 
71 
72 /*
73  * strclr - Colorize string. Function takes color value and string
74  * and returns colorized string as char pointer. First argument clr
75  * is color value (if it is invalid, function retunrs NULL) and second
76  * is string with va_list of arguments which one we want to colorize.
77  */
78 char* strclr(int clr, char* str, ...);
79 
80 
81 /*
82  * Initialize slog library. Function parses config file and reads log
83  * level and save to file flag from config. First argument is file name
84  * where log will be saved and second argument conf is config file path
85  * to be parsed and third argument lvl is log level for this message.
86  */
87 void slog_init(const char* fname, int lvl);
88 
89 
90 /*
91  * Return string in slog format. Function takes arguments
92  * and returns string in slog format without printing and
93  * saveing in file. Return value is char pointer.
94  */
95 char* slog_sprintf(char *msg, ...);
96 
97 
98 /*
99  * slog - Log exiting process. Function takes arguments and saves
100  * log in file if LOGTOFILE flag is enabled from config. Otherwise
101  * it just prints log without saveing in file. Argument level is
102  * logging level and flag is slog flags defined in slog.h header.
103  */
104 void slog(int level, int flag, const char *msg, ...);
105 void slogv(int level, int flag, const char *msg, va_list args);
106 
107 /* For include header in CPP code */
108 #ifdef __cplusplus
109 }
110 #endif
111 
112 #endif