9ffc184d3091f6d09ae2d0255691fe9670d4dfa9
[platform/core/system/dlog.git] / include / log_file.h
1 /*
2  * DLOG
3  * Copyright (c) 2005-2008, The Android Open Source Project
4  * Copyright (c) 2012-2020 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 _LOG_FILE_H
20 #define _LOG_FILE_H
21
22 #include <logprint.h>
23 #include <queued_entry.h>
24
25 /* Logfile rotation */
26 #define DEFAULT_ROTATE_SIZE_KB 1024
27 #define DEFAULT_ROTATE_NUM_FILES 3
28
29 #define BtoKiB(x)       ((x) >> 10)
30
31 struct log_file;
32
33 struct log_file {
34         char *path;
35         int fd;
36         int should_close;
37         int size;
38         size_t rotate_size_kbytes;
39         size_t max_rotated;
40         struct log_format format;
41         bool isatty;
42         bool colors_auto;
43         int32_t prev_sec;  /* previously written entry's timestamp, seconds */
44         int32_t prev_nsec; /* previously written timestamp, nanoseconds */
45 };
46
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50
51 void logfile_init(struct log_file *l_file);
52 void logfile_move(struct log_file *to, struct log_file *from);
53 void logfile_free(struct log_file *l_file);
54 void logfile_set_fd(struct log_file *l_file, int fd, int should_close);
55 int logfile_set_path(struct log_file *l_file, const char *path);
56 int logfile_open(struct log_file *l_file);
57 int logfile_rotate_needed(struct log_file *l_file);
58 void logfile_do_rotate(struct log_file *file);
59 int logfile_write_with_rotation(const dlogutil_entry_s *e, struct log_file *file, dlogutil_sorting_order_e sort_by);
60
61 #ifdef __cplusplus
62 }
63 #endif
64
65 #endif /* _LOG_FILE_H */