Objectively 1.0.0
Ultra-lightweight object oriented framework for GNU C.
Log.h
Go to the documentation of this file.
1/*
2 * Objectively: Ultra-lightweight object oriented framework for GNU C.
3 * Copyright (C) 2014 Jay Dolan <jay@jaydolan.com>
4 *
5 * This software is provided 'as-is', without any express or implied
6 * warranty. In no event will the authors be held liable for any damages
7 * arising from the use of this software.
8 *
9 * Permission is granted to anyone to use this software for any purpose,
10 * including commercial applications, and to alter it and redistribute it
11 * freely, subject to the following restrictions:
12 *
13 * 1. The origin of this software must not be misrepresented; you must not
14 * claim that you wrote the original software. If you use this software
15 * in a product, an acknowledgment in the product documentation would be
16 * appreciated but is not required.
17 *
18 * 2. Altered source versions must be plainly marked as such, and must not be
19 * misrepresented as being the original software.
20 *
21 * 3. This notice may not be removed or altered from any source distribution.
22 */
23
24#pragma once
25
26#include <stdio.h>
27
28#include <Objectively/Object.h>
29
40typedef enum {
48
52#define LOG_FORMAT_DEFAULT "%c %%n [%%l]: %%m"
53
54typedef struct Log Log;
55typedef struct LogInterface LogInterface;
56
61struct Log {
62
67
72 LogInterface *interface;
73
82 const char *format;
83
88 FILE *file;
89
94
98 char *name;
99};
100
104struct LogInterface {
105
109 ObjectInterface objectInterface;
110
118 void (*debug)(const Log *self, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
119
127 void (*error)(const Log *self, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
128
136 void (*fatal)(const Log *self, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
137
144 void (*flush)(const Log *self);
145
153 void (*info)(const Log *self, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
154
162 Log *(*init)(Log *self);
163
172 Log *(*initWithName)(Log *self, const char *name);
173
184 void (*log)(const Log *self, LogLevel level, const char *fmt, va_list args);
185
192 Log *(*sharedInstance)(void);
193
199 void (*trace)(const Log *self, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
200
206 void (*warn)(const Log *self, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
207};
208
static void trace(const Log *self, const char *fmt,...)
Definition: Log.c:227
static void flush(const Log *self)
Definition: Log.c:108
static void warn(const Log *self, const char *fmt,...)
Definition: Log.c:241
static void fatal(const Log *self, const char *fmt,...)
Definition: Log.c:94
static void error(const Log *self, const char *fmt,...)
Definition: Log.c:80
static void info(const Log *self, const char *fmt,...)
Definition: Log.c:118
static void debug(const Log *self, const char *fmt,...)
Definition: Log.c:66
LogLevel
Every Log has a threshold for generating messages.
Definition: Log.h:40
@ LogLevelFatal
Definition: Log.h:46
@ LogLevelError
Definition: Log.h:45
@ LogLevelTrace
Definition: Log.h:41
@ LogLevelWarn
Definition: Log.h:44
@ LogLevelDebug
Definition: Log.h:42
@ LogLevelInfo
Definition: Log.h:43
Object is the root Class of The Objectively Class hierarchy.
#define OBJECTIVELY_EXPORT
Definition: Types.h:36
The runtime representation of a Class.
Definition: Class.h:95
A Log4J-inspired log appender.
Definition: Log.h:61
const char * format
The format string, defaults to LOG_FORMAT_DEFAULT. This string is post-processed after date substitut...
Definition: Log.h:82
Class * _Log(void)
The Log archetype.
Definition: Log.c:285
Object object
The superclass.
Definition: Log.h:66
LogInterface * interface
The interface.
Definition: Log.h:72
FILE * file
The file descriptor (defaults to stdout).
Definition: Log.h:88
LogLevel level
The LogLevel of this Log.
Definition: Log.h:93
char * name
The name of this Log.
Definition: Log.h:98
Object is the root Class of The Objectively Class hierarchy.
Definition: Object.h:46