50 if (!isatty(fileno(this->file))) {
51 const int err = fclose(this->file);
66static void debug(
const Log *self,
const char *fmt, ...) {
80static void error(
const Log *self,
const char *fmt, ...) {
94static void fatal(
const Log *self,
const char *fmt, ...) {
118static void info(
const Log *self,
const char *fmt, ...) {
145 self->
name = strdup(name ?:
"default");
160 const char *levels[] = {
"TRACE",
"DEBUG",
"INFO",
"WARN",
"ERROR",
"FATAL" };
163 if (level < self->level) {
169 const time_t
date = time(NULL);
170 const struct tm *localDate = localtime(&
date);
173 strftime(buffer,
sizeof(buffer), self->
format, localDate);
181 if (*(c + 1) ==
'n') {
183 }
else if (*(c + 1) ==
'l') {
184 fputs(levels[level], self->
file);
185 }
else if (*(c + 1) ==
'm') {
186 vfprintf(self->
file, fmt, args);
198 fputc(*c, self->
file);
202 fputc(
'\n', self->
file);
227static void trace(
const Log *self,
const char *fmt, ...) {
241static void warn(
const Log *self,
const char *fmt, ...) {
251#pragma mark - Class lifecycle
293 .instanceSize =
sizeof(
Log),
294 .interfaceOffset = offsetof(
Log, interface),
295 .interfaceSize =
sizeof(LogInterface),
ident release(ident obj)
Atomically decrement the given Object's reference count. If the resulting reference count is 0,...
Class * _initialize(const ClassDef *def)
Initializes the given Class.
#define alloc(type)
Allocate and initialize and instance of type.
#define super(type, obj, method,...)
static void destroy(Class *clazz)
static void _log(const Log *self, LogLevel level, const char *fmt, va_list args)
static void initialize(Class *clazz)
static Log * _sharedInstance
A Log4J-inspired log appender.
#define LOG_FORMAT_DEFAULT
The default Log format.
LogLevel
Every Log has a threshold for generating messages.
#define do_once(once, block)
Executes the given block at most one time.
ClassDefs are passed to _initialize via an archetype to initialize a Class.
The runtime representation of a Class.
ident interface
The interface of the Class.
Condition * init(Condition *self)
Initializes this Condition.
Date * date(void)
Returns a new Date with the current Time.
A Log4J-inspired log appender.
Log * initWithName(Log *self, const char *name)
Initializes this Log with the specified name.
void warn(const Log *self, const char *fmt,...)
Log a warn message.
void info(const Log *self, const char *fmt,...)
Log an info message.
const char * format
The format string, defaults to LOG_FORMAT_DEFAULT. This string is post-processed after date substitut...
Log * sharedInstance(void)
void flush(const Log *self)
Flushes and pending output to this Log's file.
void trace(const Log *self, const char *fmt,...)
Log a trace message.
Class * _Log(void)
The Log archetype.
FILE * file
The file descriptor (defaults to stdout).
void fatal(const Log *self, const char *fmt,...)
Log a fatal message.
void log(const Log *self, LogLevel level, const char *fmt, va_list args)
Write a message to the Log.
LogLevel level
The LogLevel of this Log.
char * name
The name of this Log.
void debug(const Log *self, const char *fmt,...)
Log a debug message.
void error(const Log *self, const char *fmt,...)
Log an error message.
Object is the root Class of The Objectively Class hierarchy.
Class * _Object(void)
The Object archetype.
void dealloc(Object *self)
Frees all resources held by this Object.