本文整理汇总了C++中write_to_log函数的典型用法代码示例。如果您正苦于以下问题:C++ write_to_log函数的具体用法?C++ write_to_log怎么用?C++ write_to_log使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了write_to_log函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: prompt_onFriendRequest
static void prompt_onFriendRequest(ToxWindow *self, uint8_t *key, uint8_t *data, uint16_t length)
{
// make sure message data is null-terminated
data[length - 1] = 0;
PromptBuf *prt = self->promptbuf;
prep_prompt_win();
wprintw(self->window, "\n");
print_time(self->window);
uint8_t msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "Friend request with the message '%s'\n", data);
wprintw(self->window, "%s", msg);
write_to_log(msg, "", prt->log, true);
int n = add_friend_request(key);
if (n == -1) {
uint8_t *errmsg = "Friend request queue is full. Discarding request.\n";
wprintw(self->window, "%s", errmsg);
write_to_log(errmsg, "", prt->log, true);
return;
}
wprintw(self->window, "Type \"/accept %d\" to accept it.\n", n);
alert_window(self, WINDOW_ALERT_1, true);
}
示例2: reload_config
void reload_config()
{
free_cfg(0);
ini = iniparser_load(DEF_CFG);
if (ini==NULL) {
write_to_log(FATAL, "cannot parse file: %s\n", DEF_CFG);
goto err;
}
if (!section_list) {
section_list = malloc(sizeof(struct sectionList));
if(!section_list) {
write_to_log(FATAL, "%s - %d - %s", __func__, __LINE__, "Unable to allocate memory");
goto err;
}
}
if (_get_sections() != 0) {
write_to_log(FATAL, "%s - %d - %s", __func__, __LINE__, "Section List could not be filled");
goto err;
}
write_to_log(INFO, "%s", "Configuration reloaded without error");
return;
err:
exit(EXIT_FAILURE);
}
示例3: prompt_onConnectionChange
static void prompt_onConnectionChange(ToxWindow *self, Tox *m, int32_t friendnum , uint8_t status)
{
if (friendnum < 0)
return;
ChatContext *ctx = self->chatwin;
uint8_t nick[TOX_MAX_NAME_LENGTH] = {0};
int n_len = tox_get_name(m, friendnum, nick);
n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH - 1);
if (!nick[0]) {
snprintf(nick, sizeof(nick), "%s", UNKNOWN_NAME);
n_len = strlen(UNKNOWN_NAME);
}
nick[n_len] = '\0';
uint8_t timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
uint8_t *msg;
if (status == 1) {
msg = "has come online";
line_info_add(self, timefrmt, nick, NULL, msg, CONNECTION, 0, GREEN);
write_to_log(msg, nick, ctx->log, true);
alert_window(self, WINDOW_ALERT_2, false);
} else {
msg = "has gone offline";
line_info_add(self, timefrmt, nick, NULL, msg, CONNECTION, 0, RED);
write_to_log(msg, nick, ctx->log, true);
}
}
示例4: main
int main(void)
{
int fd;
pid_t child_pid;
child_pid = fork ();
if (child_pid != 0) {
//parent ID
exit(0); //the parent needs to die so the child can leave
}else{
//child process executing
setsid();
for (child_pid=getdtablesize();child_pid>=0;--child_pid) close(child_pid);
fd = open(LOCK_FILE,O_RDWR|O_CREAT,0777);
if (fd<0){
write_to_log(" :Fatal Error: couldnot read/create lock file. permission reasons");
exit(1); /* can not open */
}
if (lockf(fd,F_TLOCK,0) < 0){
write_to_log(" :Another Instance of Video Server is already running\n");
fprintf(stderr,"See *.log for details\n");
exit(0); /* can not lock */
}
initialize_server();
}
return 0;
}
示例5: prompt_onFriendRequest
static void prompt_onFriendRequest(ToxWindow *self, Tox *m, const uint8_t *key, const uint8_t *data,
uint16_t length)
{
ChatContext *ctx = self->chatwin;
uint8_t timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
uint8_t msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "Friend request with the message '%s'", data);
line_info_add(self, timefrmt, NULL, NULL, msg, SYS_MSG, 0, 0);
write_to_log(msg, "", ctx->log, true);
int n = add_friend_request(key);
if (n == -1) {
uint8_t *errmsg = "Friend request queue is full. Discarding request.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
write_to_log(errmsg, "", ctx->log, true);
return;
}
snprintf(msg, sizeof(msg), "Type \"/accept %d\" to accept it.", n);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
alert_window(self, WINDOW_ALERT_1, true);
}
示例6: modify_cfg
int modify_cfg(char *section, char *key, char *value)
{
char *query = malloc(strlen(section) + strlen(key) + strlen(":") + 1);
if (section == NULL) {
write_to_log(WARNING, "Unable to modify config, parameter is NULL - Section");
goto err;
} else if (key == NULL) {
write_to_log(WARNING, "Unable to modify config, parameter is NULL - Key");
goto err;
} else if (value == NULL) {
write_to_log(WARNING, "Unable to modify config, parameter is NULL - Value");
goto err;
}
if (!snprintf(query, (strlen(section) + strlen(key) + strlen(":") + 1), "%s:%s", section, key)) {
write_to_log(WARNING, "%s - %d - %s - %s:%s", __LINE__, __func__, "Unable to set config query for", section, key);
goto err;
}
if (iniparser_set(ini, query, value) != 0) {
write_to_log(WARNING, "Unable to modify config");
goto err;
}
free(query);
return 0;
err:
free(query);
return -1;
}
示例7: main
int main(int argc, char **argv) {
if (argc != 4 && argc != 6) {
print_usage_and_exit();
}
int mode = 0;
if (strcmp(argv[1], "-p1") == 0) {
mode = 1;
} else if (strcmp(argv[1], "-p2") == 0) {
mode = 2;
}
char *input, *inter, *output;
if (mode == 1) {
input = argv[2];
inter = argv[3];
output = NULL;
} else if (mode == 2) {
input = NULL;
inter = argv[2];
output = argv[3];
} else {
input = argv[1];
inter = argv[2];
output = argv[3];
}
if (argc == 6) {
if (strcmp(argv[4], "-log") == 0) {
set_log_file(argv[5]);
} else {
print_usage_and_exit();
}
}
int err = assemble(input, inter, output);
if (err) {
write_to_log("One or more errors encountered during assembly operation.\n");
} else {
write_to_log("Assembly operation completed successfully.\n");
}
if (is_log_file_set()) {
printf("Results saved to %s\n", argv[5]);
}
return err;
}
示例8: while
void FileHandler::write_suggestions()
{
std::string word = "";
std::string lowercase = "";
while(true)
{
if (input_file.eof())
{
break;
}
input_file >> word;
if (input_file.eof())
{
break;
}
std::cout << "word: " << word << std::endl;
for (unsigned int i = 0; i < word.size(); i++)
{
if ('A' <= word[i] && word[i] <= 'Z')
{
lowercase += (word[i]-'A'+'a');
}
else if ('a' <= word[i] && word[i] <= 'z')
{
lowercase += (word[i]);
}
}
std::cout << "lowercase: " << lowercase << std::endl;
vector<std::string> suggestions = spelling_checker->check_spelling(lowercase);
if (!suggestions.empty() && !suggestions.back().compare(lowercase)) // Si el vector no está vacío y no contiene a word
{
lowercase.clear();
continue;
}
else
{
std::reverse(suggestions.begin(), suggestions.end());
write_to_log(lowercase + ":");
while (!suggestions.empty())
{
write_to_log(" " + suggestions.back());
suggestions.pop_back();
}
write_to_log("\n");
}
lowercase.clear();
}
}
示例9: check_tcp_ports
int check_tcp_ports()
{
struct tcp_port* node = tcp_ports;
while (node) {
int sock;
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
fprintf(stderr, "Couldn't create socket.");
exit(1);
}
struct sockaddr_in host;
host.sin_family = AF_INET;
host.sin_port = htons(node->port);
host.sin_addr.s_addr = inet_addr("127.0.0.1");
DEBUG("connect()\n");
int ret;
ret = connect(sock, (struct sockaddr *) &host, sizeof(host));
DEBUG("ret: %d\n", ret);
close(sock);
if (ret == -1) {
if (node->fail_counter != -1) {
node->fail_counter++;
write_to_log("Port %d seems unreachable, fail counter is at %d.", node->port, node->fail_counter);
if (node->fail_counter >= 3)
return 1;
}
} else
node->fail_counter = 0;
node = node->next;
}
return 0;
}
示例10: init_shell
void init_shell(void){
cash_terminal = STDIN_FILENO;
cash_interactive = isatty(cash_terminal);
if(cash_interactive){
while(tcgetpgrp (cash_terminal) != (cash_pgid = getpgrp ()))
kill (- cash_pgid, SIGTTIN);
signal (SIGINT, SIG_IGN);
signal (SIGQUIT, SIG_IGN);
signal (SIGTSTP, SIG_IGN);
signal (SIGTTIN, SIG_IGN);
signal (SIGTTOU, SIG_IGN);
cash_pid = getpid();
cash_pgid = getpid();
if(setpgid(cash_pgid, cash_pgid) < 0){
if(logging)
write_to_log(SHELL_PANIC, "could not spawn interactive shell");
exit_clean(1, "could not spawn interactive shell\n");
}
else
tcsetpgrp(cash_terminal, cash_pgid);
tcgetattr(cash_terminal, &cash_tmodes);
}
}
示例11: parse_rc
void parse_rc(void){
char* buf = malloc(sizeof(char) * 4096);
int i = 0;
char* p;
if(env){
strcpy(buf, env->home);
strcat(buf, rc_filename);
} else{
free(buf);
return;
}
if(!(rc_file = fopen(buf, "r"))){
perror("rc file");
write_to_log(SHELL_OOPS,"rc file was not found or could not be opened");
free(buf);
return;
}
memset(buf, 0, 4096);
while(fgets(buf, 4096, rc_file)){
if( (p = strstr(buf, "PS1 = \"")) ){
p += strlen("PS1 = \"");
while(p[i++] != '\"')
continue;
i--;
if(!PS1)
PS1 = malloc(sizeof(char) * (i+1));
strncpy(PS1, p, i);
PS1[i] = '\0';
specified_PS1 = 1;
}
}
free(buf);
}
示例12: __write_to_log_init
static int __write_to_log_init(log_id_t log_id, struct iovec *vec, size_t nr)
{
DECLARE_SIGSET(sigflags);
lock(&sigflags);
if (write_to_log == __write_to_log_init) {
int ret;
ret = __write_to_log_initialize();
if (ret < 0) {
unlock(&sigflags);
#if (FAKE_LOG_DEVICE == 0)
if (pstore_fd >= 0) {
__write_to_log_daemon(log_id, vec, nr);
}
#endif
return ret;
}
write_to_log = __write_to_log_daemon;
}
unlock(&sigflags);
return write_to_log(log_id, vec, nr);
}
示例13: exit_clean
/*
* Here's our exit function. Just make sure everything
* is freed, and any open files are closed. Added exit
* message if you have anything to say, if you don't
* you can pass it NULL and nothing will be printed.
*/
void exit_clean(int ret_no, const char *exit_message){
/*This is a bit hacky, try to append_history.
*if that doesn't work, write history, which creates
*the file, then writes to it. Should suffice for now.
*/
if(history){
if(append_history(1000, history_filename) != 0)
if(write_history(history_filename) != 0){
write_to_log(SHELL_OOPS, "could not write history");
perror("history");
}
}
if(input)
free(input);
if(history_filename)
free(history_filename);
if(env)
free(env);
if(rc_file)
fclose(rc_file);
if(PS1 && specified_PS1 == 1)
free(PS1);
if(log_open)
fclose(log_file);
if(exit_message)
fprintf(stderr,"%s", exit_message);
exit(ret_no);
}
示例14: groupchat_onGroupAction
static void groupchat_onGroupAction(ToxWindow *self, Tox *m, int groupnum, int peernum, const char *action,
uint16_t len)
{
if (self->num != groupnum)
return;
ChatContext *ctx = self->chatwin;
char nick[TOX_MAX_NAME_LENGTH];
get_group_nick_truncate(m, nick, peernum, groupnum);
char selfnick[TOX_MAX_NAME_LENGTH];
tox_self_get_name(m, (uint8_t *) selfnick);
size_t n_len = tox_self_get_name_size(m);
selfnick[n_len] = '\0';
if (strcasestr(action, selfnick)) {
sound_notify(self, generic_message, NT_WNDALERT_0, NULL);
if (self->active_box != -1)
box_silent_notify2(self, NT_NOFOCUS, self->active_box, "* %s %s", nick, action );
else
box_silent_notify(self, NT_NOFOCUS, &self->active_box, self->name, "* %s %s", nick, action);
}
else {
sound_notify(self, silent, NT_WNDALERT_1, NULL);
}
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, nick, NULL, IN_ACTION, 0, 0, "%s", action);
write_to_log(action, nick, ctx->log, true);
}
示例15: groupchat_onGroupTitleChange
static void groupchat_onGroupTitleChange(ToxWindow *self, Tox *m, int groupnum, int peernum, const char *title,
uint8_t length)
{
ChatContext *ctx = self->chatwin;
if (self->num != groupnum)
return;
set_window_title(self, title, length);
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
/* don't announce title when we join the room */
if (!timed_out(groupchats[self->num].start_time, GROUP_EVENT_WAIT))
return;
char nick[TOX_MAX_NAME_LENGTH];
get_group_nick_truncate(m, nick, peernum, groupnum);
line_info_add(self, timefrmt, nick, NULL, NAME_CHANGE, 0, 0, " set the group title to: %s", title);
char tmp_event[MAX_STR_SIZE];
snprintf(tmp_event, sizeof(tmp_event), "set title to %s", title);
write_to_log(tmp_event, nick, ctx->log, true);
}