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 trace(const Log *self, const char *fmt,...)
static Log * initWithName(Log *self, const char *name)
static void destroy(Class *clazz)
static void flush(const Log *self)
static void warn(const Log *self, const char *fmt,...)
static void fatal(const Log *self, const char *fmt,...)
static void error(const Log *self, const char *fmt,...)
static void info(const Log *self, const char *fmt,...)
static void dealloc(Object *self)
static Log * init(Log *self)
static void _log(const Log *self, LogLevel level, const char *fmt, va_list args)
static void initialize(Class *clazz)
static Log * _sharedInstance
static Log * sharedInstance(void)
static void debug(const Log *self, const char *fmt,...)
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.
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.
const char * format
The format string, defaults to LOG_FORMAT_DEFAULT. This string is post-processed after date substitut...
FILE * file
The file descriptor (defaults to stdout).
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.
Object is the root Class of The Objectively Class hierarchy.