Exemple #1
0
LIB_EXPORT rc_t CC KStsFmtHandlerSet ( KFmtWriter formatter, KStsFmtFlags flags, void* data )
{
    if( formatter == NULL ) {
        return RC(rcRuntime, rcLog, rcLogging, rcFunction, rcNull);
    }
    G_sts_formatter.formatter = formatter;
    G_sts_formatter.data = data;
    KStsFmtFlagsSet(flags);
    return 0;
}
Exemple #2
0
LIB_EXPORT rc_t CC XMLLogger_Make2(const XMLLogger** self, KDirectory* dir, const char* logpath, const int fd)
{
    rc_t rc = 0;
    XMLLogger* obj;
    KDirectory* my_dir = NULL;

    const uint32_t lopt = klogFmtTimestamp | klogFmtSeverity |
                          klogFmtMessage | klogFmtAppName | klogFmtAppVersion | klogFmtReasonShort;

    const uint32_t sopt = kstsFmtTimestamp | kstsFmtMessage | kstsFmtAppName | kstsFmtAppVersion;

    KLogFmtFlagsSet(lopt);
    KLogLibFmtFlagsSet(lopt);
    KStsFmtFlagsSet(sopt);
    KStsLibFmtFlagsSet(sopt);

    obj = calloc(1, sizeof(*obj));
    if( obj == NULL ) {
        rc = RC(rcApp, rcLog, rcAllocating, rcMemory, rcExhausted);
    } else if( fd < 0 && dir == NULL && (rc = KDirectoryNativeDir(&my_dir)) != 0 ) {
    } else if( fd >= 0 && (rc = KFileMakeFDFileWrite(&obj->file.file, false, fd)) != 0 ) {
    } else if( logpath != NULL && fd < 0 && (rc = KDirectoryCreateFile(dir ? dir : my_dir, &obj->file.file, false, 0644, kcmInit, "%s", logpath)) != 0 ) {
    } else {
    
        obj->file.pos = 0;
        obj->log.file = &obj->file;
        obj->log.fmt.formatter = KLogFmtWriterGet();
        obj->log.fmt.data = KLogFmtDataGet();
        obj->log.wrt.writer = KLogWriterGet();
        obj->log.wrt.data = KLogDataGet();

        obj->loglib.file = &obj->file;
        obj->loglib.fmt.formatter = KLogLibFmtWriterGet();
        obj->loglib.fmt.data = KLogLibFmtDataGet();
        obj->loglib.wrt.writer = KLogLibWriterGet();
        obj->loglib.wrt.data = KLogLibDataGet();

        obj->sts.file = &obj->file;
        obj->sts.fmt.formatter = KStsFmtWriterGet();
        obj->sts.fmt.data = KStsFmtDataGet();
        obj->sts.wrt.writer = KStsWriterGet();
        obj->sts.wrt.data = KStsDataGet();

        obj->stslib.file = &obj->file;
        obj->stslib.fmt.formatter = KStsLibFmtWriterGet();
        obj->stslib.fmt.data = KStsLibFmtDataGet();
        obj->stslib.wrt.writer = KStsLibWriterGet();
        obj->stslib.wrt.data = KStsLibDataGet();

        if( (rc = KLogFmtHandlerSet(LoaderXMLFormatter, lopt, &obj->log)) == 0 &&
            (rc = KLogLibFmtHandlerSet(LoaderXMLFormatter, lopt, &obj->loglib)) == 0 &&
            (rc = KStsFmtHandlerSet(LoaderXMLFormatter, sopt, &obj->sts)) == 0 &&
            (rc = KStsLibFmtHandlerSet(LoaderXMLFormatter, sopt, &obj->stslib)) == 0 ) {
            /* make log valid XML */
            if( obj->file.file != NULL ) {
                size_t num_writ = 0;
                rc = KFileWrite(obj->file.file, obj->file.pos, "<Log>\n", 6, &num_writ);
                obj->file.pos += num_writ;
            }
        }
    }
    KDirectoryRelease(my_dir);
    if( rc == 0 ) {
        *self = obj;
        if( fd >= 0 ) {
            DBG(("XML Log file set to handle %d\n", fd));
        } else if( logpath != NULL) {
            DBG(("XML Log file set to %s\n", logpath));
        } 
    } else {
        XMLLogger_Release(obj);
        *self = NULL;
    }
    return rc;
}