blob: 4462eca6eef74c3a7e32124ede06031bf0782f12 [file] [log] [blame]
Tianjie Xue113e4d2016-10-21 17:46:13 -07001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jerry Zhangcadf4ed2018-05-02 16:56:00 -070017#ifndef _LOGGING_H
18#define _LOGGING_H
Tianjie Xue113e4d2016-10-21 17:46:13 -070019
Tao Bao245c5222017-10-18 11:06:36 -070020#include <stddef.h>
xunchang2239b9e2019-04-15 15:24:24 -070021#include <sys/stat.h>
Tao Bao245c5222017-10-18 11:06:36 -070022#include <sys/types.h>
Tianjie Xue113e4d2016-10-21 17:46:13 -070023
Jerry Zhangcadf4ed2018-05-02 16:56:00 -070024#include <string>
xunchang2239b9e2019-04-15 15:24:24 -070025#include <vector>
Jerry Zhangcadf4ed2018-05-02 16:56:00 -070026
Tao Bao245c5222017-10-18 11:06:36 -070027#include <log/log_id.h>
Tianjie Xue113e4d2016-10-21 17:46:13 -070028
Tao Bao245c5222017-10-18 11:06:36 -070029static constexpr int KEEP_LOG_COUNT = 10;
Tianjie Xue113e4d2016-10-21 17:46:13 -070030
xunchang316e9712019-04-12 16:22:15 -070031struct selabel_handle;
32
xunchang2239b9e2019-04-15 15:24:24 -070033struct saved_log_file {
34 std::string name;
35 struct stat sb;
36 std::string data;
37};
38
39void SetLoggingSehandle(selabel_handle* handle);
40
Tao Bao245c5222017-10-18 11:06:36 -070041ssize_t logbasename(log_id_t id, char prio, const char* filename, const char* buf, size_t len,
42 void* arg);
Tianjie Xue113e4d2016-10-21 17:46:13 -070043
Tao Bao245c5222017-10-18 11:06:36 -070044ssize_t logrotate(log_id_t id, char prio, const char* filename, const char* buf, size_t len,
45 void* arg);
Tianjie Xue113e4d2016-10-21 17:46:13 -070046
47// Rename last_log -> last_log.1 -> last_log.2 -> ... -> last_log.$max.
48// Similarly rename last_kmsg -> last_kmsg.1 -> ... -> last_kmsg.$max.
49// Overwrite any existing last_log.$max and last_kmsg.$max.
50void rotate_logs(const char* last_log_file, const char* last_kmsg_file);
51
Jerry Zhangcadf4ed2018-05-02 16:56:00 -070052// In turn fflush(3)'s, fsync(3)'s and fclose(3)'s the given stream.
53void check_and_fclose(FILE* fp, const std::string& name);
54
55void copy_log_file_to_pmsg(const std::string& source, const std::string& destination);
Tianjie Xu164c60a2019-05-15 13:59:39 -070056void copy_logs(bool save_current_log);
Jerry Zhangcadf4ed2018-05-02 16:56:00 -070057void reset_tmplog_offset();
58
59void save_kernel_log(const char* destination);
60
xunchang2239b9e2019-04-15 15:24:24 -070061std::vector<saved_log_file> ReadLogFilesToMemory();
62
63bool RestoreLogFilesAfterFormat(const std::vector<saved_log_file>& log_files);
64
Jerry Zhangcadf4ed2018-05-02 16:56:00 -070065#endif //_LOGGING_H