/src/trafficserver/include/proxy/logging/LogUtils.h
Line | Count | Source |
1 | | /** @file |
2 | | |
3 | | A brief file description |
4 | | |
5 | | @section license License |
6 | | |
7 | | Licensed to the Apache Software Foundation (ASF) under one |
8 | | or more contributor license agreements. See the NOTICE file |
9 | | distributed with this work for additional information |
10 | | regarding copyright ownership. The ASF licenses this file |
11 | | to you under the Apache License, Version 2.0 (the |
12 | | "License"); you may not use this file except in compliance |
13 | | with the License. You may obtain a copy of the License at |
14 | | |
15 | | http://www.apache.org/licenses/LICENSE-2.0 |
16 | | |
17 | | Unless required by applicable law or agreed to in writing, software |
18 | | distributed under the License is distributed on an "AS IS" BASIS, |
19 | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
20 | | See the License for the specific language governing permissions and |
21 | | limitations under the License. |
22 | | */ |
23 | | #pragma once |
24 | | |
25 | | #include <ctime> |
26 | | |
27 | | #include "tscore/ink_platform.h" |
28 | | #include "tscore/Arena.h" |
29 | | #include <swoc/TextView.h> |
30 | | |
31 | | class MIMEHdr; |
32 | | |
33 | | namespace LogUtils |
34 | | { |
35 | | enum AlarmType { |
36 | | LOG_ALARM_ERROR = 0, |
37 | | LOG_ALARM_WARNING, |
38 | | LOG_ALARM_N_TYPES, |
39 | | }; |
40 | | |
41 | | static inline long |
42 | | timestamp() |
43 | 0 | { |
44 | 0 | return (long)time(nullptr); |
45 | 0 | } Unexecuted instantiation: HttpSM.cc:LogUtils::timestamp() Unexecuted instantiation: HttpTransact.cc:LogUtils::timestamp() Unexecuted instantiation: HttpBodyFactory.cc:LogUtils::timestamp() Unexecuted instantiation: ProxyTransaction.cc:LogUtils::timestamp() Unexecuted instantiation: Transform.cc:LogUtils::timestamp() Unexecuted instantiation: Log.cc:LogUtils::timestamp() Unexecuted instantiation: LogAccess.cc:LogUtils::timestamp() Unexecuted instantiation: LogBuffer.cc:LogUtils::timestamp() Unexecuted instantiation: LogConfig.cc:LogUtils::timestamp() Unexecuted instantiation: LogField.cc:LogUtils::timestamp() Unexecuted instantiation: LogFieldAliasMap.cc:LogUtils::timestamp() Unexecuted instantiation: LogFile.cc:LogUtils::timestamp() Unexecuted instantiation: LogFilter.cc:LogUtils::timestamp() Unexecuted instantiation: LogFormat.cc:LogUtils::timestamp() Unexecuted instantiation: LogFieldFallback.cc:LogUtils::timestamp() Unexecuted instantiation: LogObject.cc:LogUtils::timestamp() Unexecuted instantiation: TransactionLogData.cc:LogUtils::timestamp() Unexecuted instantiation: LogUtils.cc:LogUtils::timestamp() Unexecuted instantiation: RolledLogDeleter.cc:LogUtils::timestamp() Unexecuted instantiation: YamlLogConfig.cc:LogUtils::timestamp() Unexecuted instantiation: YamlLogConfigDecoders.cc:LogUtils::timestamp() |
46 | | |
47 | | int timestamp_to_str(long timestamp, char *buf, int size); |
48 | | char *timestamp_to_netscape_str(long timestamp); |
49 | | char *timestamp_to_date_str(long timestamp); |
50 | | char *timestamp_to_time_str(long timestamp); |
51 | | unsigned ip_from_host(char *host); |
52 | | void strip_trailing_newline(char *buf); |
53 | | char *int64_to_str(char *buf, unsigned int buf_size, int64_t val, unsigned int *total_chars, unsigned int req_width = 0, |
54 | | char pad_char = '0'); |
55 | | void remove_content_type_attributes(char *type_str, int *type_len); |
56 | | int timestamp_to_hex_str(unsigned timestamp, char *str, size_t len, size_t *n_chars = nullptr); |
57 | | int seconds_to_next_roll(time_t time_now, int rolling_offset, int rolling_interval); |
58 | | int file_is_writeable(const char *full_filename, off_t *size_bytes = nullptr, bool *has_size_limit = nullptr, |
59 | | uint64_t *current_size_limit_bytes = nullptr); |
60 | | |
61 | | /** Given a rolled file, determine the unrolled filename. |
62 | | * |
63 | | * For example, given this: |
64 | | * diags.log.20191114.21h43m16s-20191114.21h43m17s.old |
65 | | * |
66 | | * Return this: |
67 | | * diags.log |
68 | | * |
69 | | * @param[in] rolled_filename The rolled filename from which to derive the |
70 | | * unrolled filename. |
71 | | * |
72 | | * @return The unrolled filename if it looked like a rolled log file or the |
73 | | * input filename if it didn't. |
74 | | */ |
75 | | swoc::TextView get_unrolled_filename(swoc::TextView rolled_filename); |
76 | | |
77 | | // Marshals header tags and values together, with a single terminating nul character. Returns buffer space required. 'buf' points |
78 | | // to where to put the marshaled data. If 'buf' is null, no data is marshaled, but the function returns the amount of space that |
79 | | // would have been used. |
80 | | int marshalMimeHdr(MIMEHdr *hdr, char *buf); |
81 | | |
82 | | // Unmarshelled/printable format is {{{tag1}:{value1}}{{tag2}:{value2}} ... } |
83 | | // |
84 | | // Returns -1 if data corruption is detected, otherwise the actual amount of data put into the 'dest' buffer. '*buf' is advanced |
85 | | // to byte after the last byte consumed. |
86 | | int unmarshalMimeHdr(char **buf, char *dest, int destLength); |
87 | | |
88 | | }; // namespace LogUtils |