PARCLogReporter * parcLogReporterTextStdout_Create(void) { PARCFileOutputStream *fileOutput = parcFileOutputStream_Create(dup(STDOUT_FILENO)); PARCOutputStream *out = parcFileOutputStream_AsOutputStream(fileOutput); parcFileOutputStream_Release(&fileOutput); PARCLogReporter *result = parcLogReporter_Create(&parcLogReporterTextStdout_Acquire, parcLogReporterTextStdout_Release, parcLogReporterTextStdout_Report, parcOutputStream_Acquire(out)); parcOutputStream_Release(&out); return result; }
static PARCLog * _parc_logger_create(const char *name) { PARCFileOutputStream *fileOutput = parcFileOutputStream_Create(dup(STDOUT_FILENO)); PARCOutputStream *output = parcFileOutputStream_AsOutputStream(fileOutput); parcFileOutputStream_Release(&fileOutput); PARCLogReporter *reporter = parcLogReporterFile_Create(output); parcOutputStream_Release(&output); PARCLog *log = parcLog_Create("localhost", "athenaTransport", name, reporter); parcLogReporter_Release(&reporter); parcLog_SetLevel(log, PARCLogLevel_Info); return log; }
static PARCLog * _athena_logger_create(void) { PARCFileOutputStream *fileOutput = parcFileOutputStream_Create(dup(STDOUT_FILENO)); PARCOutputStream *output = parcFileOutputStream_AsOutputStream(fileOutput); parcFileOutputStream_Release(&fileOutput); PARCLogReporter *reporter = parcLogReporterFile_Create(output); parcOutputStream_Release(&output); PARCLog *log = parcLog_Create("localhost", "athena", NULL, reporter); parcLogReporter_Release(&reporter); parcLog_SetLevel(log, PARCLogLevel_Info); return log; }
LONGBOW_TEST_CASE(CreateDestroy, parcLog_Create) { PARCFileOutputStream *fileOutput = parcFileOutputStream_Create(dup(STDOUT_FILENO)); PARCOutputStream *output = parcFileOutputStream_AsOutputStream(fileOutput); parcFileOutputStream_Release(&fileOutput); PARCLogReporter *reporter = parcLogReporterFile_Create(output); parcOutputStream_Release(&output); PARCLog *log = parcLog_Create("localhost", "test_parc_Log", NULL, reporter); parcLogReporter_Release(&reporter); assertTrue(parcLogLevel_Equals(parcLog_GetLevel(log), PARCLogLevel_Off), "Expected initial log level to be OFF"); parcLog_Release(&log); }
static MetisLogger * _createLogfile(const char *logfile) { int logfd = open(logfile, O_WRONLY | O_APPEND | O_CREAT, S_IWUSR | S_IRUSR); if (logfd < 0) { fprintf(stderr, "Error opening %s for writing: (%d) %s\n", logfile, errno, strerror(errno)); exit(EXIT_FAILURE); } chmod(logfile, S_IRWXU); PARCFileOutputStream *fos = parcFileOutputStream_Create(logfd); PARCOutputStream *pos = parcFileOutputStream_AsOutputStream(fos); PARCLogReporter *reporter = parcLogReporterFile_Create(pos); MetisLogger *logger = metisLogger_Create(reporter, parcClock_Wallclock()); parcOutputStream_Release(&pos); parcLogReporter_Release(&reporter); return logger; }