void log_delete(const char *fname, int mode) { static struct { union file_extras ex[4]; /* just in case... */ struct file_struct file; } x; /* Zero-initialized due to static declaration. */ int len = strlen(fname); const char *fmt; x.file.mode = mode; if (am_server && protocol_version >= 29 && len < MAXPATHLEN) { if (S_ISDIR(mode)) len++; /* directories include trailing null */ send_msg(MSG_DELETED, fname, len, am_generator); } else if (!INFO_GTE(DEL, 1) && !stdout_format) ; else { fmt = stdout_format_has_o_or_i ? stdout_format : "deleting %n"; log_formatted(FCLIENT, fmt, "del.", &x.file, fname, ITEM_DELETED, NULL); } if (!logfile_name || dry_run || !logfile_format) return; fmt = logfile_format_has_o_or_i ? logfile_format : "deleting %n"; log_formatted(FLOG, fmt, "del.", &x.file, fname, ITEM_DELETED, NULL); }
/* Log the transfer of a file. If the code is FCLIENT, the output just goes * to stdout. If it is FLOG, it just goes to the log file. Otherwise we * output to both. */ void log_item(enum logcode code, struct file_struct *file, int iflags, const char *hlink) { const char *s_or_r = am_sender ? "send" : "recv"; if (code != FLOG && stdout_format && !am_server) log_formatted(FCLIENT, stdout_format, s_or_r, file, NULL, iflags, hlink); if (code != FCLIENT && logfile_format && *logfile_format) log_formatted(FLOG, logfile_format, s_or_r, file, NULL, iflags, hlink); }
int main() { assert(daemon_flag == false); log(INFO, "Info log message."); log(SCRIPT, "Script log message."); log(NOTICE, "Notice log message."); log(WARNING, "Warning log message."); log(SCRIPT_ERROR, "Script Error log message."); log(CRITICAL, "Critical log message."); log_formatted(INFO, "Info message with no \\n"); log_formatted(INFO, "Info message with a \\n\n"); log_formatted(INFO, "Info message with a \\n \n and text on another line"); log_formatted(INFO, "Info message with two \\n\n on two lines\n"); errno = 0; logSysError(INFO); logSysError(SCRIPT); logSysError(NOTICE); logSysError(WARNING); logSysError(SCRIPT_ERROR); logSysError(CRITICAL); errno = -1; logSysError(INFO); logSysError(SCRIPT); logSysError(NOTICE); logSysError(WARNING); logSysError(SCRIPT_ERROR); logSysError(CRITICAL); errno = EINVAL; logSysError(INFO); logSysError(SCRIPT); logSysError(NOTICE); logSysError(WARNING); logSysError(SCRIPT_ERROR); logSysError(CRITICAL); assert(testEventLog("/dev/null")); logEvent(START, "Test start event log message"); logEvent(STOP, "Test stop event log message"); logEvent(CONNECT, "Test connect event log message"); logEvent(DISCONNECT, "Test disconnect event log message"); logEvent(LOGIN, "Test login event log message"); logEvent(LOGOUT, "Test logout event log message"); logEvent(TAKE_CHAR, "Test take character event log message"); logEvent(DROP_CHAR, "Test drop character event log message"); logEvent(EXPORT_ENT, "Test export entity event log message"); logEvent(IMPORT_ENT, "Test import entity event log message"); logEvent(POSSESS_CHAR, "Test possess character event log message"); return 0; }
/*------------------------------------------------------------------------------ | main +-----------------------------------------------------------------------------*/ int main(int argc, char** argv) { #if defined(QT_QML_LIB) && defined(QT_QUICK_LIB) QGuiApplication a(argc, argv); #endif #if 0 QElapsedTimer timer; timer.start(); // Test with lc_logging. for (int i = 0; i < 100000; i++) log_verbose("Test: %d.", i); qDebug("Result lc_logging: %lld.", timer.elapsed()); // Test with printf. timer.restart(); for (int i = 0; i < 100000; i++) { fprintf(stdout, "- DEBUG:%s: Test: %d.\n", lc_current_time().c_str(), i); fflush(stdout); } qDebug("Result printf: %lld.", timer.elapsed()); // Test with qDebug. timer.restart(); for (int i = 0; i < 100000; i++) { qDebug("- DEBUG:%s: Test: %d.\n", lc_current_time().c_str(), i); fflush(stderr); } qDebug("Result qDebug: %lld.", timer.elapsed()); #endif #ifdef __GNUC__ LOG_CRITICAL("MyTag", "Oooops!"); #endif log_info("Info log."); log_info_t("MyTag", "Info log."); test_args("Testing %d va_args functions.", 2); log_debug("Some message for debugging..."); log_disabled("A disabled log!!!!!!!!!!! You won't see this."); log_critical("Print int: %d.", 5); log_critical_t("MyTag", "Print int: %d.", 5); log_critical_t("MyTag", "Print with tag only."); /*lc_formatted_printf(stdout, LC_LOG_ATTR_UNDERLINE, LC_LOG_COL_MAGENTA, "Underlined %s! ;-)\n", "magenta");*/ log_formatted(LC_LOG_ATTR_UNDERLINE, LC_LOG_COL_YELLOW, "Formatted text."); log_formatted(LC_LOG_COL_YELLOW, "Formatted text with %s.", "param"); #ifndef __ANDROID__ test_func(); #endif // Using streams. { LC_LogDef logger(NULL, LC_LOG_ATTR_RESET, LC_LOG_COL_BLUE); logger.stream() << "Blue log using stream. " << "Params can be added like " << 1234 << "."; LC_LogDef l(NULL); Q_UNUSED(l); } { LC_Log<LC_Output2Std> logger(LC_LOG_DEBUG); logger.stream() << "Debug log with stream."; } { LC_Log<LC_Output2Std> logger(LC_LOG_WARN); logger.stream() << "Warning log with stream."; } { LC_Log<LC_Output2Std> logger(LC_LOG_CRITICAL); logger.stream() << "Critical log with stream."; } #if defined(QT_QML_LIB) && defined(QT_QUICK_LIB) QQuickView view; LC_QMLLogger::registerObject(view.rootContext()); view.setSource(QUrl("qrc:///main.qml")); #endif assert(log_verbose("") == true); assert(log_info("") == true); assert(log_warn("") == false); assert(log_err("") == false); assert(log_critical("") == false); return 0; }