1 /* 2 * nghttp2 - HTTP/2 C Library 3 * 4 * Copyright (c) 2014 Tatsuhiro Tsujikawa 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining 7 * a copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sublicense, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject to 12 * the following conditions: 13 * 14 * The above copyright notice and this permission notice shall be 15 * included in all copies or substantial portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 */ 25 #ifndef SHRPX_LOG_CONFIG_H 26 #define SHRPX_LOG_CONFIG_H 27 28 #include "shrpx.h" 29 30 #include <sys/types.h> 31 32 #include <chrono> 33 34 #include "template.h" 35 36 using namespace nghttp2; 37 38 namespace shrpx { 39 40 struct Timestamp { 41 Timestamp(const std::chrono::system_clock::time_point &tp); 42 43 std::array<char, sizeof("03/Jul/2014:00:19:38 +0900")> time_local_buf; 44 std::array<char, sizeof("2014-11-15T12:58:24.741+09:00")> time_iso8601_buf; 45 std::array<char, sizeof("Mon, 10 Oct 2016 10:25:58 GMT")> time_http_buf; 46 StringRef time_local; 47 StringRef time_iso8601; 48 StringRef time_http; 49 }; 50 51 struct LogConfig { 52 std::chrono::system_clock::time_point time_str_updated; 53 std::shared_ptr<Timestamp> tstamp; 54 std::string thread_id; 55 pid_t pid; 56 int accesslog_fd; 57 int errorlog_fd; 58 // true if errorlog_fd is referring to a terminal. 59 bool errorlog_tty; 60 61 LogConfig(); 62 // Updates time stamp if difference between time_str_updated and now 63 // is 1 or more milliseconds. 64 void update_tstamp_millis(const std::chrono::system_clock::time_point &now); 65 // Updates time stamp if difference between time_str_updated and 66 // now, converted to time_t, is 1 or more seconds. 67 void update_tstamp(const std::chrono::system_clock::time_point &now); 68 }; 69 70 // We need LogConfig per thread to avoid data race around opening file 71 // descriptor for log files. 72 LogConfig *log_config(); 73 74 // Deletes log_config 75 void delete_log_config(); 76 77 } // namespace shrpx 78 79 #endif // SHRPX_LOG_CONFIG_H 80