void shlog_write(shbuf_t *buff, int level, int err_code, char *log_str) { static char log_path[PATH_MAX+1]; char line[640]; char *beg_line; size_t mem_size; if (!buff) return; if (!*log_path) { char *label; shpeer_t peer; memcpy(&peer, ashpeer(), sizeof(peer)); label = (!*peer.label ? PACKAGE_NAME : peer.label); sprintf(log_path, "%s%s.log", shlog_path(label), label); } if (*log_path && !_shlog_file) { _shlog_file = fopen(log_path, "ab"); } beg_line = shbuf_data(buff) + shbuf_size(buff); sprintf(line, "%s", shstrtime(shtime(), "[%x %T] ")); shbuf_catstr(buff, line); if (level == SHLOG_ERROR) { shbuf_catstr(buff, "error"); } else if (level == SHLOG_WARNING) { shbuf_catstr(buff, "warning"); } else { shbuf_catstr(buff, "info"); } if (err_code) { memset(line, 0, sizeof(line)); snprintf(line, sizeof(line) - 1, ": %s [code %d]", strerror(-(err_code)), (err_code)); shbuf_catstr(buff, line); } if (log_str) { shbuf_catstr(buff, ": "); shbuf_catstr(buff, log_str); } mem_size = shlog_mem_size(); if (mem_size > 100000) { sprintf(line, " (mem:%dm)", (mem_size / 1000)); shbuf_catstr(buff, line); } shbuf_catstr(buff, "\n"); }
static int _lfunc_sexe_strftime(lua_State *L) { double f = luaL_checknumber(L, 1); const char *fmt = luaL_checkstring(L, 2); shtime_t t = SHTIME_UNDEFINED; shnum_set(f, &t); lua_pushstring(L, (char *)shstrtime(t, fmt)); return 1; /* 'timeu' */ }
void info_table_add_row(info_table_t *table, char *row_name, shtime_t stamp) { info_table_row_t *row; int idx; /* allocate a new row */ row = (info_table_row_t *)calloc(1, sizeof(info_table_row_t)); if (table->row) table->row->next = row; table->row = row; if (!table->row_head) table->row_head = row; idx = info_table_column(table, "TYPE"); if (idx != -1) table->row->col[idx] = strdup(row_name); if (stamp) { idx = info_table_column(table, "TIME"); if (idx != -1) table->row->col[idx] = strdup(shstrtime(stamp, NULL)); } }