Logger is a C library that implements a simple logging system for classic Macintosh programs. Logger is free software; see the LICENSE file for copyright/licensing --- # Install This library has been built and tested using THINK C v5.0 on a Macintosh SE. In order to install it, just import `logger.c` and `logger.h` to your project and include `logger.h` in your source files. The Logger library requires ANSI to be added to your project. --- # Usage ## Initializing the logger: For the logger to log to the console (through printf()), call the init_logger() function with a log level and `CONSOLE_OUT` as the output method. init_logger(ERROR_LEVEL, CONSOLE_OUT, NULL); For the logger to log to a file, call the init_logger() function with the FILE_OUT as the output method along with the path to the file to log to. init_logger(DEBUG_LEVEL, FILE_OUT, "file.log"); You can define paths as follow: * "file.log" - A simple file name relative to the project. * ":logs:file.log" - An path relative to the project. * "Macintosh HD:logs:file.log" - An absolute path. Tip: The log file can be stored on a network volume (from Netatalk) and loaded with `tail -f` on a modern machine so that logs are shown in real time. Note that if the log file doesn't exist, it is created but only if its containg folder exists. If the file cannot be created, the output method is set to NONE_OUT. The log file is cleared every time init_logger() is called. Log output methods are as follow: NONE_OUT = 0, CONSOLE_OUT = 1, FILE_OUT = 2, Log levels are as follow: NONE_LEVEL = 0, ERROR_LEVEL = 1, WARNING_LEVEL = 2, INFO_LEVEL = 3, DEBUG_LEVEL = 4, init_logger() initializes the global variable `logger`. ## Using the logger: You can log a new line by calling: logger.log(char* format, ...); You can format your log message with variables: int count = 10; char* what = "students"; logger.log("There are %d %s", count, what); --> Will output: "There are 10 students". You can also use the following methods to differentiate debug, warning and error messages from your log output. logger.debug(char* format, ...); logger.info(char* format, ...); logger.warn(char* format, ...); logger.error(char* format, ...); ## Customizing: You can override the logger.log() function to handle logs the way you want, like printing the message in a text area on the screen. void my_log(char* format, ...) { //Handle my log message. } After initializing with no output, just set logger.log. init_logger(DEBUG_LEVEL, NONE_OUT, NULL); logger.log = my_log;