Set proper executable bits
[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 <time.h>
23 #include <pthread.h>
24
25 #include <logcommon.h>
26 #include <queued_entry.h>
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 typedef enum {
33         FORMAT_OFF = 0,
34         FORMAT_BRIEF,
35         FORMAT_PROCESS,
36         FORMAT_TAG,
37         FORMAT_THREAD,
38         FORMAT_RAW,
39         FORMAT_TIME,
40         FORMAT_THREADTIME,
41         FORMAT_KERNELTIME,
42         FORMAT_LONG,
43 } log_print_format;
44
45 typedef struct log_format_t log_format;
46
47 typedef struct log_entry_t {
48         time_t tv_sec;
49         long tv_nsec;
50         log_priority priority;
51         pid_t pid;
52         pthread_t tid;
53         char * tag;
54         size_t messageLen;
55         char * message;
56 } log_entry;
57
58 log_format *log_format_new();
59
60 void log_format_free(log_format *p_format);
61
62 void log_set_print_format(log_format *p_format, log_print_format format);
63
64 /**
65  * Returns a deep copy of the passed object.
66  */
67 log_format *log_format_from_format(log_format *p_format);
68
69 /**
70  * Returns FORMAT_OFF on invalid string
71  */
72 log_print_format log_format_from_string(const char *s);
73
74 /**
75  * filterExpression: a single filter expression
76  * eg "AT:d"
77  *
78  * returns 0 on success and -1 on invalid expression
79  *
80  * Assumes single threaded execution
81  *
82  */
83
84 int log_add_filter_rule(log_format *p_format, const char *filterExpression);
85
86 /**
87  * filterString: a whitespace-separated set of filter expressions
88  * eg "AT:d *:i"
89  *
90  * returns 0 on success and -1 on invalid expression
91  *
92  * Assumes single threaded execution
93  *
94  */
95
96 int log_add_filter_string(log_format *p_format, const char *filterString);
97
98 /**
99  * returns 1 if this log line should be printed based on its priority
100  * and tag, and 0 if it should not
101  */
102 int log_should_print_line(
103                 log_format *p_format, const char *tag, log_priority pri);
104
105 /**
106  * Splits a wire-format buffer into an log_entry
107  * entry allocated by caller. Pointers will point directly into buf
108  *
109  * Returns 0 on success and -1 on invalid wire format (entry will be
110  * in unspecified state)
111  */
112 int log_process_log_buffer(struct logger_entry *entry_raw, log_entry *entry);
113
114 /**
115  * Formats a log message into a buffer
116  *
117  * Uses defaultBuffer if it can, otherwise malloc()'s a new buffer
118  * If return value != defaultBuffer, caller must call free()
119  * Returns NULL on malloc error
120  */
121
122 char *log_format_log_line(
123                 log_format *p_format,
124                 char *defaultBuffer,
125                 size_t defaultBufferSize,
126                 const log_entry *p_line,
127                 size_t *p_outLength);
128
129 /**
130  * Either print or do not print log line, based on filter
131  *
132  * Assumes single threaded execution
133  *
134  */
135 int log_print_log_line(
136                 log_format *p_format,
137                 int fd,
138                 const log_entry *entry);
139
140 log_priority filter_pri_for_tag(log_format *p_format, const char *tag);
141
142 #ifdef __cplusplus
143 }
144 #endif
145
146 #endif /*_LOGPRINT_H*/