Example #1
0
yal_log_t *yal_log_init(const char *logdir_path,
        const char *appname,
        int pid) 
{
    int logfile_path_sz = sizeof(char) *
                (strlen(logdir_path) + 1 + strlen(appname) + 1 + 5 + 4 + 1); 

    yal_log_t *logger = malloc(sizeof(yal_log_t));
    if (logger)
    {
        logger->filepath = malloc(logfile_path_sz);
        if (logger->filepath)
            sprintf(logger->filepath,
                    "%s/%s-%05d.log",
                    logdir_path,
                    appname,
                    pid);

        if (logger->filepath) 
            logger->file = fopen(logger->filepath, "w");

        if (logger->filepath && logger->file)
            return logger;
        else
            delete_logger(logger);
    }
   
    printf("yal_log: Error: %s\n", strerror(errno));
    return NULL;
}
Example #2
0
void signal_cb(int sig)
{
    if (sig == SIGINT || sig == SIGTERM)
        run = 0;
    printf("total receive count: %d\n", count);
    int i = 0;
    for (; i <= thread_num; i++)
    {
        if (i == 0)
            config_destroy(keeper[i]->conf);
        delete_logger(keeper[i]->logger);
        zmq_close (keeper[i]->socket);
        zmq_ctx_destroy (keeper[i]->ctx);
        free(keeper[i]);
    }

}
Example #3
0
void yal_log_close(yal_log_t *logger)
{
    if (logger && logger->file)
        fclose(logger->file);
    delete_logger(logger);
}