072f12a240c36ee000066406595f9ecd47d82b87
[platform/core/system/dlog.git] / include / logprint.h
1 /*
2  * DLOG
3  * Copyright (c) 2005-2008, The Android Open Source Project
4  * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the License);
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 #ifndef _LOGPRINT_H
20 #define _LOGPRINT_H
21
22 #include <stdbool.h>
23 #include <time.h>
24 #include <pthread.h>
25
26 #include <dlogutil-internal.h>
27 #include <logcommon.h>
28 #include <ptrs_list.h>
29 #include <queued_entry.h>
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 typedef enum {
36         FORMAT_OFF = 0,
37         FORMAT_BRIEF,
38         FORMAT_PROCESS,
39         FORMAT_TAG,
40         FORMAT_THREAD,
41         FORMAT_RAW,
42         FORMAT_TIME,
43         FORMAT_THREADTIME,
44         FORMAT_KERNELTIME,
45         FORMAT_RECV_REALTIME,
46         FORMAT_RWTIME,
47         FORMAT_LONG,
48         FORMAT_JSON,
49 } log_print_format;
50
51 struct log_format {
52         log_print_format format;
53         bool color;
54 };
55
56 dlogutil_filter_options_s *log_filter_new();
57
58 void log_filter_free(dlogutil_filter_options_s *p_filter);
59
60 /**
61  * Returns a deep copy of the passed object.
62  */
63 dlogutil_filter_options_s *log_filter_from_filter(const dlogutil_filter_options_s *p_filter);
64
65 dlogutil_filter_options_s *log_filter_move(dlogutil_filter_options_s *p_filter);
66
67 /**
68  * Returns FORMAT_OFF on invalid string
69  */
70 log_print_format log_format_from_string(const char *s);
71
72 /**
73  * filterExpression: a single filter expression
74  * eg "AT:d"
75  *
76  * returns 0 on success and -1 on invalid expression
77  *
78  * Assumes single threaded execution
79  *
80  */
81
82 int log_add_filter_rule(dlogutil_filter_options_s *p_filter, const char *filterExpression);
83
84 void log_filter_clear(dlogutil_filter_options_s *p_filter);
85
86 struct tag_and_prio {
87         char *tag;
88         size_t tagLength;
89         log_priority pri;
90         bool exactPri;
91         bool prefix;
92 };
93
94 typedef struct FilterInfo_t {
95         enum {
96                 FILTER_TAG_AND_PRIO,
97                 FILTER_PID,
98                 FILTER_TID,
99         } type;
100         union {
101                 struct tag_and_prio tnp;
102                 pid_t pid;
103                 pid_t tid;
104         };
105 } FilterInfo;
106
107 list_head log_filter_get_list(dlogutil_filter_options_s *p_filter);
108
109 log_priority log_filter_get_global_priority(dlogutil_filter_options_s *p_filter, bool *is_exact);
110
111 bool log_filter_need_apply_default(dlogutil_filter_options_s *p_filter);
112
113 /**
114  * returns true if this log line should be printed based on its entry
115  * data (priority, tag, pid and tid), and false if it should not
116  */
117 bool log_should_print_line(
118                 dlogutil_filter_options_s *p_filter, const dlogutil_entry_s *entry);
119
120 /**
121  * Formats a log message into a buffer
122  *
123  * Uses defaultBuffer if it can, otherwise malloc()'s a new buffer
124  * If return value != defaultBuffer, caller must call free()
125  * Returns NULL on malloc error
126  */
127
128 char *log_format_log_line(
129                 const struct log_format p_format,
130                 char *defaultBuffer,
131                 size_t defaultBufferSize,
132                 const dlogutil_entry_s *p_line,
133                 size_t *p_outLength);
134
135 /**
136  * Either print or do not print log line, based on filter
137  *
138  * Assumes single threaded execution
139  *
140  */
141 int log_print_log_line(
142                 struct log_format p_format,
143                 int fd,
144                 const dlogutil_entry_s *entry);
145
146 dlogutil_sorting_order_e get_format_sorting(log_print_format format);
147
148 #ifdef __cplusplus
149 }
150 #endif
151
152 #endif /*_LOGPRINT_H*/