Module: Agoo::Log
- Defined in:
- ext/agoo/rlog.c
Class Method Summary collapse
-
.classic ⇒ Object
call-seq: classic().
-
.color(label) ⇒ Object
call-seq: color(label).
-
.configure(options) ⇒ Object
call-seq: configure(options).
-
.console=(on) ⇒ Object
call-seq: console=(on).
-
.debug(msg) ⇒ Object
call-seq: debug(msg).
-
.debug? ⇒ Boolean
call-seq: debug?().
-
.error(msg) ⇒ Object
call-seq: error(msg).
-
.error? ⇒ Boolean
call-seq: error?().
-
.flush(to) ⇒ Object
call-seq: flush.
-
.info(msg) ⇒ Object
call-seq: info(msg).
-
.info? ⇒ Boolean
call-seq: info?().
-
.json ⇒ Object
call-seq: json().
-
.log(label, msg) ⇒ Object
call-seq: log = msg.
-
.max_files=(rmax) ⇒ Object
call-seq: max_files(max).
-
.max_size=(rmax) ⇒ Object
call-seq: max_size(size).
-
.rotate ⇒ Object
call-seq: rotate().
-
.set_color(label, color) ⇒ Object
call-seq: set_color(label, color_symbol).
-
.set_state(label, state) ⇒ Object
call-seq: set_state(label, state).
-
.shutdown ⇒ Object
call-seq: shutdown().
-
.state(label) ⇒ Object
call-seq: state(label).
-
.warn(msg) ⇒ Object
call-seq: warn(msg).
-
.warn? ⇒ Boolean
call-seq: warn?().
Class Method Details
.classic ⇒ Object
call-seq: classic()
Set the log format to classic format.
366 367 368 369 370 |
# File 'ext/agoo/rlog.c', line 366 static VALUE rlog_classic(VALUE self) { agoo_log.classic = true; return Qnil; } |
.color(label) ⇒ Object
call-seq: color(label)
Returns the current color name as a Symbol for the specified label.
228 229 230 231 232 233 234 235 236 |
# File 'ext/agoo/rlog.c', line 228
static VALUE
rlog_color_get(VALUE self, VALUE label) {
agooLogCat cat = agoo_log_cat_find(StringValuePtr(label));
if (NULL == cat) {
return Qnil;
}
return ID2SYM(rb_intern(cat->color->name));
}
|
.configure(options) ⇒ Object
call-seq: configure(options)
Configures the logger
-
options [Hash] server options
-
:dir [String] directory to place log files in. If nil or empty then no log files are written.
-
:console [true|false] if true log entry are display on the console.
-
:classic [true|false] if true log entry follow a classic format. If false log entries are JSON.
-
:colorize [true|false] if true log entries are colorized.
-
:states [Hash] a map of logging categories and whether they should be on or off. Categories are:
-
:ERROR errors
-
:WARN warnings
-
:INFO infomational
-
:DEBUG debugging
-
:connect openning and closing of connections
-
:request requests
-
:response responses
-
:eval handler evaluationss
-
:push writes to WebSocket or SSE connection
-
-
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'ext/agoo/rlog.c', line 49
static VALUE
rlog_configure(VALUE self, VALUE options) {
if (Qnil != options) {
VALUE v;
if (Qnil != (v = rb_hash_lookup(options, ID2SYM(rb_intern("dir"))))) {
rb_check_type(v, T_STRING);
strncpy(agoo_log.dir, StringValuePtr(v), sizeof(agoo_log.dir));
agoo_log.dir[sizeof(agoo_log.dir) - 1] = '\0';
}
if (Qnil != (v = rb_hash_lookup(options, ID2SYM(rb_intern("max_files"))))) {
int max = FIX2INT(v);
if (1 <= max || max < 100) {
agoo_log.max_files = max;
} else {
rb_raise(rb_eArgError, "max_files must be between 1 and 100.");
}
}
if (Qnil != (v = rb_hash_lookup(options, ID2SYM(rb_intern("max_size"))))) {
int max = FIX2INT(v);
if (1 <= max) {
agoo_log.max_size = max;
} else {
rb_raise(rb_eArgError, "max_size must be 1 or more.");
}
}
if (Qnil != (v = rb_hash_lookup(options, ID2SYM(rb_intern("console"))))) {
agoo_log.console = (Qtrue == v);
}
if (Qnil != (v = rb_hash_lookup(options, ID2SYM(rb_intern("classic"))))) {
agoo_log.classic = (Qtrue == v);
}
if (Qnil != (v = rb_hash_lookup(options, ID2SYM(rb_intern("colorize"))))) {
agoo_log.colorize = (Qtrue == v);
}
if (Qnil != (v = rb_hash_lookup(options, ID2SYM(rb_intern("states"))))) {
if (T_HASH == rb_type(v)) {
agooLogCat cat = agoo_log.cats;
VALUE cv;
for (; NULL != cat; cat = cat->next) {
if (Qnil != (cv = rb_hash_lookup(v, ID2SYM(rb_intern(cat->label))))) {
if (Qtrue == cv) {
cat->on = true;
} else if (Qfalse == cv) {
cat->on = false;
}
}
}
} else {
rb_raise(rb_eArgError, "states must be a Hash.");
}
}
}
if (NULL != agoo_log.file) {
fclose(agoo_log.file);
agoo_log.file = NULL;
}
if ('\0' != *agoo_log.dir) {
if (0 != mkdir(agoo_log.dir, 0770) && EEXIST != errno) {
rb_raise(rb_eIOError, "Failed to create '%s'.", agoo_log.dir);
}
agoo_log_open_file();
}
return Qnil;
}
|
.console=(on) ⇒ Object
call-seq: console=(on)
If on then log output also goes to the console.
354 355 356 357 358 |
# File 'ext/agoo/rlog.c', line 354
static VALUE
rlog_console(VALUE self, VALUE on) {
agoo_log.console = (Qtrue == on);
return Qnil;
}
|
.debug(msg) ⇒ Object
call-seq: debug(msg)
Log a debug message.
216 217 218 219 220 |
# File 'ext/agoo/rlog.c', line 216
static VALUE
rlog_debug(VALUE self, VALUE msg) {
agoo_log_cat(&agoo_debug_cat, "%s", StringValuePtr(msg));
return Qnil;
}
|
.debug? ⇒ Boolean
call-seq: debug?()
Returns true is debug entries are being logged.
169 170 171 172 |
# File 'ext/agoo/rlog.c', line 169 static VALUE rlog_debugp(VALUE self) { return agoo_debug_cat.on ? Qtrue : Qfalse; } |
.error(msg) ⇒ Object
call-seq: error(msg)
Log an error message.
180 181 182 183 184 |
# File 'ext/agoo/rlog.c', line 180
static VALUE
rlog_error(VALUE self, VALUE msg) {
agoo_log_cat(&agoo_error_cat, "%s", StringValuePtr(msg));
return Qnil;
}
|
.error? ⇒ Boolean
call-seq: error?()
Returns true is errors are being logged.
136 137 138 139 |
# File 'ext/agoo/rlog.c', line 136 static VALUE rlog_errorp(VALUE self) { return agoo_error_cat.on ? Qtrue : Qfalse; } |
.flush(to) ⇒ Object
call-seq: flush
Flush the log queue and write all entries to disk or the console. The call waits for the flush to complete or the timeout to be exceeded.
326 327 328 329 330 331 332 333 334 |
# File 'ext/agoo/rlog.c', line 326
static VALUE
rlog_flush(VALUE self, VALUE to) {
double timeout = NUM2DBL(to);
if (!agoo_log_flush(timeout)) {
rb_raise(rb_eStandardError, "timed out waiting for log flush.");
}
return Qnil;
}
|
.info(msg) ⇒ Object
call-seq: info(msg)
Log an info message.
204 205 206 207 208 |
# File 'ext/agoo/rlog.c', line 204
static VALUE
rlog_info(VALUE self, VALUE msg) {
agoo_log_cat(&agoo_info_cat, "%s", StringValuePtr(msg));
return Qnil;
}
|
.info? ⇒ Boolean
call-seq: info?()
Returns true is info entries are being logged.
158 159 160 161 |
# File 'ext/agoo/rlog.c', line 158 static VALUE rlog_infop(VALUE self) { return agoo_info_cat.on ? Qtrue : Qfalse; } |
.json ⇒ Object
call-seq: json()
Set the log format to JSON format.
378 379 380 381 382 |
# File 'ext/agoo/rlog.c', line 378 static VALUE rlog_json(VALUE self) { agoo_log.classic = false; return Qnil; } |
.log(label, msg) ⇒ Object
call-seq: log = msg
Log a message in the specified category.
306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'ext/agoo/rlog.c', line 306
static VALUE
rlog_log(VALUE self, VALUE label, VALUE msg) {
const char *label_str = StringValuePtr(label);
agooLogCat cat = agoo_log_cat_find(label_str);
if (NULL == cat) {
rb_raise(rb_eArgError, "%s is not a valid category.", label_str);
}
agoo_log_cat(cat, "%s", StringValuePtr(msg));
return Qnil;
}
|
.max_files=(rmax) ⇒ Object
call-seq: max_files(max)
Maximum log files files is reset.
408 409 410 411 412 413 414 415 416 417 418 |
# File 'ext/agoo/rlog.c', line 408
static VALUE
rlog_max_files(VALUE self, VALUE rmax) {
int max = FIX2INT(rmax);
if (1 <= max || max < 100) {
agoo_log.max_files = max;
} else {
rb_raise(rb_eArgError, "max_files must be between 1 and 100.");
}
return Qnil;
}
|
.max_size=(rmax) ⇒ Object
call-seq: max_size(size)
Maximum log files size is reset.
390 391 392 393 394 395 396 397 398 399 400 |
# File 'ext/agoo/rlog.c', line 390
static VALUE
rlog_max_size(VALUE self, VALUE rmax) {
int max = FIX2INT(rmax);
if (1 <= max) {
agoo_log.max_size = max;
} else {
rb_raise(rb_eArgError, "max_size must be 1 or more.");
}
return Qnil;
}
|
.rotate ⇒ Object
call-seq: rotate()
Rotate the log files.
342 343 344 345 346 |
# File 'ext/agoo/rlog.c', line 342 static VALUE rlog_rotate(VALUE self) { agoo_log_rotate(); return Qnil; } |
.set_color(label, color) ⇒ Object
call-seq: set_color(label, color_symbol)
Sets color of the category associated with a label. Valid colors are :black, :red, :green, :yellow, :blue, :magenta, :cyan, :white, :gray, :dark_red, :dark_green, :brown, :dark_blue, :purple, and :dark_cyan.
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'ext/agoo/rlog.c', line 246
static VALUE
rlog_color_set(VALUE self, VALUE label, VALUE color) {
const char *label_str = StringValuePtr(label);
const char *color_name = StringValuePtr(color);
agooLogCat cat = agoo_log_cat_find(label_str);
agooColor c = find_color(color_name);
if (NULL == cat) {
rb_raise(rb_eArgError, "%s is not a valid category.", label_str);
}
if (NULL == c) {
rb_raise(rb_eArgError, "%s is not a valid color.", color_name);
}
cat->color = c;
return Qnil;
}
|
.set_state(label, state) ⇒ Object
call-seq: set_state(label, state)
Sets state of the category associated with a label.
287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'ext/agoo/rlog.c', line 287
static VALUE
rlog_on_set(VALUE self, VALUE label, VALUE state) {
const char *label_str = StringValuePtr(label);
agooLogCat cat = agoo_log_cat_find(label_str);
if (NULL == cat) {
rb_raise(rb_eArgError, "%s is not a valid category.", label_str);
}
cat->on = (Qtrue == state);
return cat->on ? Qtrue : Qfalse;
}
|
.shutdown ⇒ Object
call-seq: shutdown()
Shutdown the logger. Writes are flushed before shutting down.
124 125 126 127 128 |
# File 'ext/agoo/rlog.c', line 124 static VALUE rlog_shutdown(VALUE self) { agoo_log_close(); return Qnil; } |
.state(label) ⇒ Object
call-seq: state(label)
Returns the current state of the category identified by the specified label.
271 272 273 274 275 276 277 278 279 |
# File 'ext/agoo/rlog.c', line 271
static VALUE
rlog_on_get(VALUE self, VALUE label) {
agooLogCat cat = agoo_log_cat_find(StringValuePtr(label));
if (NULL == cat) {
return Qfalse;
}
return cat->on ? Qtrue : Qfalse;
}
|
.warn(msg) ⇒ Object
call-seq: warn(msg)
Log a warn message.
192 193 194 195 196 |
# File 'ext/agoo/rlog.c', line 192
static VALUE
rlog_warn(VALUE self, VALUE msg) {
agoo_log_cat(&agoo_warn_cat, "%s", StringValuePtr(msg));
return Qnil;
}
|
.warn? ⇒ Boolean
call-seq: warn?()
Returns true is warnings are being logged.
147 148 149 150 |
# File 'ext/agoo/rlog.c', line 147 static VALUE rlog_warnp(VALUE self) { return agoo_warn_cat.on ? Qtrue : Qfalse; } |