Objectively 1.0.0
Ultra-lightweight object oriented framework for GNU C.
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Properties | Methods | Protected Attributes
Log Struct Reference

#include <Log.h>

Overview

A Log4J-inspired log appender.

Definition at line 61 of file Log.h.

Inheritance diagram for Log:
Object

Properties

FILE * file
 The file descriptor (defaults to stdout). More...
 
const char * format
 The format string, defaults to LOG_FORMAT_DEFAULT. This string is post-processed after date substitution is performed by strftime. The following additional tokens are supported: More...
 
LogLevel level
 The LogLevel of this Log. More...
 
char * name
 The name of this Log. More...
 
Object object
 The superclass. More...
 
- Properties inherited from Object
Classclazz
 Every instance of Object begins with a pointer to its Class. More...
 

Methods

Class_Log (void)
 The Log archetype. More...
 
void debug (const Log *self, const char *fmt,...)
 Log a debug message. More...
 
void error (const Log *self, const char *fmt,...)
 Log an error message. More...
 
void fatal (const Log *self, const char *fmt,...)
 Log a fatal message. More...
 
void flush (const Log *self)
 Flushes and pending output to this Log's file. More...
 
void info (const Log *self, const char *fmt,...)
 Log an info message. More...
 
Loginit (Log *self)
 Initializes this Log. More...
 
LoginitWithName (Log *self, const char *name)
 Initializes this Log with the specified name. More...
 
void log (const Log *self, LogLevel level, const char *fmt, va_list args)
 Write a message to the Log. More...
 
LogsharedInstance (void)
 
void trace (const Log *self, const char *fmt,...)
 Log a trace message. More...
 
void warn (const Log *self, const char *fmt,...)
 Log a warn message. More...
 
- Methods inherited from Object
Class_Object (void)
 The Object archetype. More...
 
Objectcopy (const Object *self)
 Creates a shallow copy of this Object. More...
 
void dealloc (Object *self)
 Frees all resources held by this Object. More...
 
Stringdescription (const Object *self)
 
int hash (const Object *self)
 
Objectinit (Object *self)
 Initializes this Object. More...
 
_Bool isEqual (const Object *self, const Object *other)
 Tests equality of the other Object. More...
 
_Bool isKindOfClass (const Object *self, const Class *clazz)
 Tests for Class hierarchy membership. More...
 

Protected Attributes

LogInterface * interface
 The interface. More...
 
- Protected Attributes inherited from Object
ObjectInterface * interface
 The interface. More...
 

Property Details

◆ file

FILE* Log::file

The file descriptor (defaults to stdout).

Remarks
Non-tty files are closed when the Log is deallocated.

Definition at line 88 of file Log.h.

◆ format

const char* Log::format

The format string, defaults to LOG_FORMAT_DEFAULT. This string is post-processed after date substitution is performed by strftime. The following additional tokens are supported:

  • %n - The Log name.
  • %l - The message level.
  • %m - The message.

Definition at line 82 of file Log.h.

◆ interface

LogInterface* Log::interface
protected

The interface.

Definition at line 72 of file Log.h.

◆ level

LogLevel Log::level

The LogLevel of this Log.

Definition at line 93 of file Log.h.

◆ name

char* Log::name

The name of this Log.

Definition at line 98 of file Log.h.

◆ object

Object Log::object

The superclass.

Definition at line 66 of file Log.h.

Method Details

◆ _Log()

Class * _Log ( void  )

The Log archetype.

Returns
The Log Class.

Definition at line 285 of file Log.c.

285 {
286 static Class *clazz;
287 static Once once;
288
289 do_once(&once, {
290 clazz = _initialize(&(const ClassDef) {
291 .name = "Log",
292 .superclass = _Object(),
293 .instanceSize = sizeof(Log),
294 .interfaceOffset = offsetof(Log, interface),
295 .interfaceSize = sizeof(LogInterface),
297 .destroy = destroy,
298 });
299 });
300
301 return clazz;
302}
Class * _initialize(const ClassDef *def)
Initializes the given Class.
Definition: Class.c:91
static void destroy(Class *clazz)
Definition: Log.c:276
static void initialize(Class *clazz)
Definition: Log.c:256
long Once
The Once type.
Definition: Once.h:37
#define do_once(once, block)
Executes the given block at most one time.
Definition: Once.h:43
ClassDefs are passed to _initialize via an archetype to initialize a Class.
Definition: Class.h:41
The runtime representation of a Class.
Definition: Class.h:95
A Log4J-inspired log appender.
Definition: Log.h:61
LogInterface * interface
The interface.
Definition: Log.h:72
Class * clazz
Every instance of Object begins with a pointer to its Class.
Definition: Object.h:51
Class * _Object(void)
The Object archetype.
Definition: Object.c:136

◆ debug()

void debug ( const Log self,
const char *  fmt,
  ... 
)

Log a debug message.

Parameters
selfThe Log.
fmtThe format string.

Definition at line 66 of file Log.c.

66 {
67
68 va_list args;
69 va_start(args, fmt);
70
71 $(self, log, LogLevelDebug, fmt, args);
72
73 va_end(args);
74}
@ LogLevelDebug
Definition: Log.h:42
void log(const Log *self, LogLevel level, const char *fmt, va_list args)
Write a message to the Log.

◆ error()

void(*) void error(const Log *self, const char *fmt,...) ( const Log self,
const char *  fmt,
  ... 
)

Log an error message.

Parameters
selfThe Log.
fmtThe format string.

Definition at line 80 of file Log.c.

80 {
81
82 va_list args;
83 va_start(args, fmt);
84
85 $(self, log, LogLevelError, fmt, args);
86
87 va_end(args);
88}
@ LogLevelError
Definition: Log.h:45

◆ fatal()

void(*) void fatal(const Log *self, const char *fmt,...) ( const Log self,
const char *  fmt,
  ... 
)

Log a fatal message.

Parameters
selfThe Log.
fmtThe format string.

Definition at line 94 of file Log.c.

94 {
95
96 va_list args;
97 va_start(args, fmt);
98
99 $(self, log, LogLevelFatal, fmt, args);
100
101 va_end(args);
102}
@ LogLevelFatal
Definition: Log.h:46

◆ flush()

void(*) void flush(const Log *self) ( const Log self)

Flushes and pending output to this Log's file.

Parameters
selfThe Log.

Definition at line 108 of file Log.c.

108 {
109
110 assert(self->file);
111 fflush(self->file);
112}
FILE * file
The file descriptor (defaults to stdout).
Definition: Log.h:88

◆ info()

void info ( const Log self,
const char *  fmt,
  ... 
)

Log an info message.

Parameters
selfThe Log.
fmtThe format string.

Definition at line 118 of file Log.c.

118 {
119
120 va_list args;
121 va_start(args, fmt);
122
123 $(self, log, LogLevelInfo, fmt, args);
124
125 va_end(args);
126}
@ LogLevelInfo
Definition: Log.h:43

◆ init()

void(*) Log * init(Log *self) ( Log self)

Initializes this Log.

Parameters
selfThe Log.
Returns
The initialized Log, or NULL on error.

Definition at line 132 of file Log.c.

132 {
133
134 return $(self, initWithName, NULL);
135}
Log * initWithName(Log *self, const char *name)
Initializes this Log with the specified name.
Definition: Log.c:141

◆ initWithName()

Log * initWithName ( Log self,
const char *  name 
)

Initializes this Log with the specified name.

Parameters
selfThe Log.
nameThe Log name.
Returns
The initialized Log, or NULL on error.

Definition at line 141 of file Log.c.

141 {
142
143 self = (Log *) super(Object, self, init);
144 if (self) {
145 self->name = strdup(name ?: "default");
146 self->level = LogLevelInfo;
148 self->file = stdout;
149 }
150
151 return self;
152}
#define super(type, obj, method,...)
#define LOG_FORMAT_DEFAULT
The default Log format.
Definition: Log.h:52
const char * format
The format string, defaults to LOG_FORMAT_DEFAULT. This string is post-processed after date substitut...
Definition: Log.h:82
Log * init(Log *self)
Initializes this Log.
Definition: Log.c:132
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

◆ log()

void log ( const Log self,
LogLevel  level,
const char *  fmt,
va_list  args 
)

Write a message to the Log.

Parameters
selfThe Log.
levelThe severity of the message, which must be greater than or equal to the configured level of this Log.
fmtThe format string.
argsThe format arguments.

◆ sharedInstance()

Log * sharedInstance ( void  )
Returns
The shared Log instance.

Definition at line 212 of file Log.c.

212 {
213
214 static Once once;
215
216 do_once(&once, {
218 });
219
220 return _sharedInstance;
221}
#define alloc(type)
Allocate and initialize and instance of type.
Definition: Class.h:159
static Log * _sharedInstance
Definition: Log.c:206

◆ trace()

void trace ( const Log self,
const char *  fmt,
  ... 
)

Log a trace message.

Definition at line 227 of file Log.c.

227 {
228
229 va_list args;
230 va_start(args, fmt);
231
232 $(self, log, LogLevelTrace, fmt, args);
233
234 va_end(args);
235}
@ LogLevelTrace
Definition: Log.h:41

◆ warn()

void(*) void warn(const Log *self, const char *fmt,...) ( const Log self,
const char *  fmt,
  ... 
)

Log a warn message.

Definition at line 241 of file Log.c.

241 {
242
243 va_list args;
244 va_start(args, fmt);
245
246 $(self, log, LogLevelWarn, fmt, args);
247
248 va_end(args);
249}
@ LogLevelWarn
Definition: Log.h:44

The documentation for this struct was generated from the following files: