| 1 |
/* logger.h |
| 2 |
* |
| 3 |
* Copyright 2026 Francois Techene |
| 4 |
* |
| 5 |
* Permission is hereby granted, free of charge, to any person obtaining |
| 6 |
* a copy of this software and associated documentation files (the |
| 7 |
* "Software"), to deal in the Software without restriction, including |
| 8 |
* without limitation the rights to use, copy, modify, merge, publish, |
| 9 |
* distribute, sublicense, and/or sell copies of the Software, and to |
| 10 |
* permit persons to whom the Software is furnished to do so, subject to |
| 11 |
* the following conditions: |
| 12 |
* |
| 13 |
* The above copyright notice and this permission notice shall be |
| 14 |
* included in all copies or substantial portions of the Software. |
| 15 |
* |
| 16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 17 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 18 |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 19 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY |
| 20 |
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 21 |
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 22 |
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 23 |
* |
| 24 |
* Except as contained in this notice, the name(s) of the above copyright |
| 25 |
* holders shall not be used in advertising or otherwise to promote the sale, |
| 26 |
* use or other dealings in this Software without prior written |
| 27 |
* authorization. |
| 28 |
*/ |
| 29 |
|
| 30 |
#ifndef LOGGER_H |
| 31 |
#define LOGGER_H |
| 32 |
|
| 33 |
//////////////////////////////////////////////// |
| 34 |
// Logger setup |
| 35 |
// |
| 36 |
#define USE_LOGGER // Comment to disable logs |
| 37 |
|
| 38 |
#define LOG_LEVEL DEBUG_LEVEL // NONE_LEVEL, ERROR_LEVEL, WARNING_LEVEL, INFO_LEVEL, DEBUG_LEVEL |
| 39 |
#define LOG_METHOD CONSOLE_OUT // NONE_OUT, CONSOLE_OUT, FILE_OUT |
| 40 |
#define LOG_FILE "::logs:output.log" // Change to the path to your log file |
| 41 |
// requires LOG_METHOD set to FILE_OUT |
| 42 |
#define CONSOLE_LINES 4 |
| 43 |
|
| 44 |
//////////////////////////////////////////////// |
| 45 |
|
| 46 |
typedef enum { |
| 47 |
NONE_LEVEL = 0, |
| 48 |
ERROR_LEVEL, |
| 49 |
WARNING_LEVEL, |
| 50 |
INFO_LEVEL, |
| 51 |
DEBUG_LEVEL |
| 52 |
} LogLevel; |
| 53 |
|
| 54 |
typedef enum { |
| 55 |
NONE_OUT = 0, |
| 56 |
CONSOLE_OUT, |
| 57 |
FILE_OUT |
| 58 |
|
| 59 |
} LogOutputMethod; |
| 60 |
|
| 61 |
|
| 62 |
#ifdef USE_LOGGER // Only load if required. |
| 63 |
|
| 64 |
typedef struct _LogConsole { |
| 65 |
|
| 66 |
WindowPtr window; |
| 67 |
TEHandle textArea; |
| 68 |
|
| 69 |
ControlHandle vScroll; |
| 70 |
|
| 71 |
Rect bounds; |
| 72 |
Rect origBounds; |
| 73 |
Rect growBounds; |
| 74 |
Rect prevBounds; |
| 75 |
Rect titleBar; |
| 76 |
Rect bottomBar; |
| 77 |
Rect view; |
| 78 |
|
| 79 |
Rect lowerBtn; |
| 80 |
Rect clearBtn; |
| 81 |
Rect closeBtn; |
| 82 |
Rect zoomBtn; |
| 83 |
Rect growBtn; |
| 84 |
|
| 85 |
int width; |
| 86 |
int height; |
| 87 |
int lineHeight; |
| 88 |
int contentHeight; |
| 89 |
int nbLines; |
| 90 |
int scrollPos; |
| 91 |
int maxScrollPos; |
| 92 |
int nbOutputLines; |
| 93 |
|
| 94 |
} LogConsole; |
| 95 |
|
| 96 |
#endif |
| 97 |
|
| 98 |
typedef struct _Logger { |
| 99 |
|
| 100 |
void (*print) (char* format, ...); |
| 101 |
void (*log) (char* format, ...); |
| 102 |
void (*debug) (char* format, ...); |
| 103 |
void (*info) (char* format, ...); |
| 104 |
void (*warn) (char* format, ...); |
| 105 |
void (*error) (char* format, ...); |
| 106 |
Boolean (*onEvent) (EventRecord event); |
| 107 |
|
| 108 |
#ifdef USE_LOGGER // Only load if required. |
| 109 |
LogConsole console; |
| 110 |
|
| 111 |
char* filePath; |
| 112 |
int outputMethod; |
| 113 |
int logLevel; |
| 114 |
|
| 115 |
char* newLine; |
| 116 |
#endif |
| 117 |
|
| 118 |
} Logger; |
| 119 |
|
| 120 |
extern Logger logger; |
| 121 |
|
| 122 |
void InitLogger(LogLevel level, |
| 123 |
LogOutputMethod out, |
| 124 |
char* file_path); |
| 125 |
|
| 126 |
Boolean DoLogEvent(EventRecord event); |
| 127 |
|
| 128 |
#endif |