log.c (2327B)
1/* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20#include "config.h" 21#include "guaclog.h" 22#include "log.h" 23 24#include <guacamole/client.h> 25#include <guacamole/error.h> 26 27#include <stdarg.h> 28#include <stdio.h> 29 30int guaclog_log_level = GUACLOG_DEFAULT_LOG_LEVEL; 31 32void vguaclog_log(guac_client_log_level level, const char* format, 33 va_list args) { 34 35 const char* priority_name; 36 char message[2048]; 37 38 /* Don't bother if the log level is too high */ 39 if (level > guaclog_log_level) 40 return; 41 42 /* Copy log message into buffer */ 43 vsnprintf(message, sizeof(message), format, args); 44 45 /* Convert log level to human-readable name */ 46 switch (level) { 47 48 /* Error log level */ 49 case GUAC_LOG_ERROR: 50 priority_name = "ERROR"; 51 break; 52 53 /* Warning log level */ 54 case GUAC_LOG_WARNING: 55 priority_name = "WARNING"; 56 break; 57 58 /* Informational log level */ 59 case GUAC_LOG_INFO: 60 priority_name = "INFO"; 61 break; 62 63 /* Debug log level */ 64 case GUAC_LOG_DEBUG: 65 priority_name = "DEBUG"; 66 break; 67 68 /* Any unknown/undefined log level */ 69 default: 70 priority_name = "UNKNOWN"; 71 break; 72 } 73 74 /* Log to STDERR */ 75 fprintf(stderr, GUACLOG_LOG_NAME ": %s: %s\n", priority_name, message); 76 77} 78 79void guaclog_log(guac_client_log_level level, const char* format, ...) { 80 va_list args; 81 va_start(args, format); 82 vguaclog_log(level, format, args); 83 va_end(args); 84} 85