12c593315Sopenharmony_ci/* 22c593315Sopenharmony_ci * nghttp2 - HTTP/2 C Library 32c593315Sopenharmony_ci * 42c593315Sopenharmony_ci * Copyright (c) 2014 Tatsuhiro Tsujikawa 52c593315Sopenharmony_ci * 62c593315Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining 72c593315Sopenharmony_ci * a copy of this software and associated documentation files (the 82c593315Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 92c593315Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 102c593315Sopenharmony_ci * distribute, sublicense, and/or sell copies of the Software, and to 112c593315Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 122c593315Sopenharmony_ci * the following conditions: 132c593315Sopenharmony_ci * 142c593315Sopenharmony_ci * The above copyright notice and this permission notice shall be 152c593315Sopenharmony_ci * included in all copies or substantial portions of the Software. 162c593315Sopenharmony_ci * 172c593315Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 182c593315Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 192c593315Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 202c593315Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 212c593315Sopenharmony_ci * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 222c593315Sopenharmony_ci * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 232c593315Sopenharmony_ci * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 242c593315Sopenharmony_ci */ 252c593315Sopenharmony_ci#ifndef SHRPX_LOG_CONFIG_H 262c593315Sopenharmony_ci#define SHRPX_LOG_CONFIG_H 272c593315Sopenharmony_ci 282c593315Sopenharmony_ci#include "shrpx.h" 292c593315Sopenharmony_ci 302c593315Sopenharmony_ci#include <sys/types.h> 312c593315Sopenharmony_ci 322c593315Sopenharmony_ci#include <chrono> 332c593315Sopenharmony_ci 342c593315Sopenharmony_ci#include "template.h" 352c593315Sopenharmony_ci 362c593315Sopenharmony_ciusing namespace nghttp2; 372c593315Sopenharmony_ci 382c593315Sopenharmony_cinamespace shrpx { 392c593315Sopenharmony_ci 402c593315Sopenharmony_cistruct Timestamp { 412c593315Sopenharmony_ci Timestamp(const std::chrono::system_clock::time_point &tp); 422c593315Sopenharmony_ci 432c593315Sopenharmony_ci std::array<char, sizeof("03/Jul/2014:00:19:38 +0900")> time_local_buf; 442c593315Sopenharmony_ci std::array<char, sizeof("2014-11-15T12:58:24.741+09:00")> time_iso8601_buf; 452c593315Sopenharmony_ci std::array<char, sizeof("Mon, 10 Oct 2016 10:25:58 GMT")> time_http_buf; 462c593315Sopenharmony_ci StringRef time_local; 472c593315Sopenharmony_ci StringRef time_iso8601; 482c593315Sopenharmony_ci StringRef time_http; 492c593315Sopenharmony_ci}; 502c593315Sopenharmony_ci 512c593315Sopenharmony_cistruct LogConfig { 522c593315Sopenharmony_ci std::chrono::system_clock::time_point time_str_updated; 532c593315Sopenharmony_ci std::shared_ptr<Timestamp> tstamp; 542c593315Sopenharmony_ci std::string thread_id; 552c593315Sopenharmony_ci pid_t pid; 562c593315Sopenharmony_ci int accesslog_fd; 572c593315Sopenharmony_ci int errorlog_fd; 582c593315Sopenharmony_ci // true if errorlog_fd is referring to a terminal. 592c593315Sopenharmony_ci bool errorlog_tty; 602c593315Sopenharmony_ci 612c593315Sopenharmony_ci LogConfig(); 622c593315Sopenharmony_ci // Updates time stamp if difference between time_str_updated and now 632c593315Sopenharmony_ci // is 1 or more milliseconds. 642c593315Sopenharmony_ci void update_tstamp_millis(const std::chrono::system_clock::time_point &now); 652c593315Sopenharmony_ci // Updates time stamp if difference between time_str_updated and 662c593315Sopenharmony_ci // now, converted to time_t, is 1 or more seconds. 672c593315Sopenharmony_ci void update_tstamp(const std::chrono::system_clock::time_point &now); 682c593315Sopenharmony_ci}; 692c593315Sopenharmony_ci 702c593315Sopenharmony_ci// We need LogConfig per thread to avoid data race around opening file 712c593315Sopenharmony_ci// descriptor for log files. 722c593315Sopenharmony_ciLogConfig *log_config(); 732c593315Sopenharmony_ci 742c593315Sopenharmony_ci// Deletes log_config 752c593315Sopenharmony_civoid delete_log_config(); 762c593315Sopenharmony_ci 772c593315Sopenharmony_ci} // namespace shrpx 782c593315Sopenharmony_ci 792c593315Sopenharmony_ci#endif // SHRPX_LOG_CONFIG_H 80