1 #ifndef I1541_LOG_H 2 #define I1541_LOG_H 3 4 /** Declarations for the Logging module 5 * @file 6 */ 7 8 /** @defgroup Logging Logging 9 * Library output facilities 10 * 11 * `#include <1541img/log.h>` 12 * @{ 13 * 14 * This module contains functions to control how lib1541img will output 15 * informative, diagnostic and error messages. 16 * 17 * If you don't call any of the functions from this module, lib1541img will 18 * stay completely silent. 19 * 20 */ 21 22 #include <stdio.h> 23 24 #include <1541img/decl.h> 25 26 /** The log level of a message 27 */ 28 typedef enum LogLevel 29 { 30 L_FATAL, /**< program execution can't continue */ 31 L_ERROR, /**< an error message, can't successfully complete */ 32 L_WARNING, /**< a warning message, something seems wrong */ 33 L_INFO, /**< an information message */ 34 L_DEBUG /**< a debugging message, very verbose */ 35 } LogLevel; 36 37 /** Delegate for writing log messages from the library. 38 * @param level the log level of the message 39 * @param message the actual message 40 * @param data some additional data you might need internally 41 */ 42 typedef void (*logwriter)(LogLevel level, const char *message, void *data); 43 44 /** Setup logging to a file. 45 * This will add a simple log writer appending to an opened file. You may 46 * supply one of the standard streams stdout or stderr here. For example, 47 * simple console output could be configured like this: 48 * 49 * setFileLogger(stderr); 50 * 51 * @param file the file to write messages to 52 */ 53 DECLEXPORT void setFileLogger(FILE *file); 54 55 /** Setup logging using your own function. 56 * @param writer your log writing function 57 * @param data some additional data to pass to your writing function 58 */ 59 DECLEXPORT void setCustomLogger(logwriter writer, void *data); 60 61 /** Configure the maximum log level. 62 * lib1541img will suppress any messages less severe than the level given 63 * here. By default, DEBUG messages will be suppressed. 64 * @param level the maximum level to generate messages for 65 */ 66 DECLEXPORT void setMaxLogLevel(LogLevel level); 67 68 /**@}*/ 69 70 #endif 71 72