GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — async-profiler/src/log.cpp at v4.2 · async-profiler/async-profiler Expand file tree/ Copy pathlog.cppMore file actions 147 lines (123 loc) · 3.24 KB / Copy pathlog.cppFile metadata and controls147 lines (123 loc) · 3.24 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 /* * Copyright The async-profiler authors * SPDX-License-Identifier: Apache-2.0 */ #include <fcntl.h> #include <string.h> #include <unistd.h> #include "flightRecorder.h" #include "log.h" #include "profiler.h" const char* const Log::LEVEL_NAME[] = { "TRACE", "DEBUG", "INFO", "WARN", "ERROR", "NONE" }; Mutex Log::_lock; int Log::_fd = STDOUT_FILENO; LogLevel Log::_level = LOG_INFO; void Log::open(Arguments& args) { open(args._log, args._loglevel); if (args._unknown_arg != NULL) { warn("Unknown argument: %s", args._unknown_arg); } } void Log::open(const char* file_name, const char* level) { LogLevel l = LOG_INFO; if (level != NULL) { for (int i = LOG_TRACE; i <= LOG_NONE; i++) { if (strcasecmp(LEVEL_NAME[i], level) == 0) { l = (LogLevel)i; break; } } } MutexLocker ml(_lock); _level = l; if (_fd > STDERR_FILENO) { ::close(_fd); } if (file_name == NULL || strcmp(file_name, "stdout") == 0) { _fd = STDOUT_FILENO; } else if (strcmp(file_name, "stderr") == 0) { _fd = STDERR_FILENO; } else if ((_fd = creat(file_name, 0660)) < 0) { _fd = STDOUT_FILENO; warn("Could not open log file: %s", file_name); } } void Log::close() { MutexLocker ml(_lock); if (_fd > STDERR_FILENO) { ::close(_fd); _fd = STDOUT_FILENO; } } void Log::writeRaw(LogLevel level, const char* msg, size_t len) { MutexLocker ml(_lock); if (level < _level) { return; } while (len > 0) { ssize_t bytes = ::write(_fd, msg, len); if (bytes <= 0) { break; } msg += (size_t)bytes; len -= (size_t)bytes; } } void Log::log(LogLevel level, const char* msg, va_list args) { if (level < _level && level < FlightRecorder::MIN_LOG_LEVEL) { // Nothing to do return; } char buf[1024]; // Format log message: [LEVEL] Message\n size_t prefix_len = snprintf(buf, sizeof(buf), "[%s] ", LEVEL_NAME[level]); size_t msg_len = vsnprintf(buf + prefix_len, sizeof(buf) - 1 - prefix_len, msg, args); if (msg_len > sizeof(buf) - 1 - prefix_len) { msg_len = sizeof(buf) - 1 - prefix_len; } buf[prefix_len + msg_len] = '\n'; if (level < LOG_ERROR && level >= FlightRecorder::MIN_LOG_LEVEL) { Profiler::instance()->writeLog(level, buf + prefix_len, msg_len); } // Write a message with a prefix to a file if (level >= _level) { writeRaw(level, buf, prefix_len + msg_len + 1); } } void Log::trace(const char* msg, ...) { va_list args; va_start(args, msg); log(LOG_TRACE, msg, args); va_end(args); } void Log::debug(const char* msg, ...) { va_list args; va_start(args, msg); log(LOG_DEBUG, msg, args); va_end(args); } void Log::info(const char* msg, ...) { va_list args; va_start(args, msg); log(LOG_INFO, msg, args); va_end(args); } void Log::warn(const char* msg, ...) { va_list args; va_start(args, msg); log(LOG_WARN, msg, args); va_end(args); } void Log::error(const char* msg, ...) { va_list args; va_start(args, msg); log(LOG_ERROR, msg, args); va_end(args); } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |