ssh

Dependents:   OS

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers log.h Source File

log.h

00001 /* log.h
00002  *
00003  * Copyright (C) 2014-2016 wolfSSL Inc.
00004  *
00005  * This file is part of wolfSSH.
00006  *
00007  * wolfSSH is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 3 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * wolfSSH is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with wolfSSH.  If not, see <http://www.gnu.org/licenses/>.
00019  */
00020 
00021 
00022 /*
00023  * The log module contains the interface to the logging function. When
00024  * debugging is enabled and turned on, the logger will output to STDOUT.
00025  * A custom logging callback may be installed.
00026  */
00027 
00028 
00029 #pragma once
00030 
00031 #include <wolfssh/settings.h>
00032 
00033 #ifdef __cplusplus
00034 extern "C" {
00035 #endif
00036 
00037 
00038 enum wolfSSH_LogLevel {
00039     WS_LOG_USER  = 5,
00040     WS_LOG_ERROR = 4,
00041     WS_LOG_WARN  = 3,
00042     WS_LOG_INFO  = 2,
00043     WS_LOG_DEBUG = 1,
00044     WS_LOG_DEFAULT = WS_LOG_DEBUG
00045 };
00046 
00047 
00048 typedef void (*wolfSSH_LoggingCb)(enum wolfSSH_LogLevel,
00049                                   const char *const logMsg);
00050 WOLFSSH_API void wolfSSH_SetLoggingCb(wolfSSH_LoggingCb logF);
00051 WOLFSSH_API int wolfSSH_LogEnabled(void);
00052 
00053 
00054 #ifdef __GNUC__
00055     #define FMTCHECK __attribute__((format(printf,2,3)))
00056 #else
00057     #define FMTCHECK
00058 #endif /* __GNUC__ */
00059 
00060 
00061 WOLFSSH_API void wolfSSH_Log(enum wolfSSH_LogLevel,
00062                              const char *const, ...) FMTCHECK;
00063 
00064 #define WLOG(...) do { \
00065                       if (wolfSSH_LogEnabled()) \
00066                           wolfSSH_Log(__VA_ARGS__); \
00067                   } while (0)
00068 
00069 
00070 #ifdef __cplusplus
00071 }
00072 #endif
00073