blob: cad7e367ad572be5af60c103ba55e1f57efa803c [file] [log] [blame]
anjana_sreekumar@infosys.com991c2062020-01-08 11:42:57 +05301/*
2 * Copyright (c) 2003-2018, Great Software Laboratory Pvt. Ltd.
3 * Copyright (c) 2017 Intel Corporation
4 * Copyright (c) 2019, Infosys Ltd.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#include <stdio.h>
20#include <stdlib.h>
21#include <stdarg.h>
22#include <string.h>
23#include <time.h>
24#include <stdbool.h>
25#include <sys/types.h>
26#include <unistd.h>
27#include "log.h"
28#include <sys/syscall.h>
29
30bool g_nolog = false;
31enum log_levels g_log_level = LOG_INFO;
32
33int pid = 0;
34char processName[255] = {0};
35
36static const char *log_level_name[] = { "INFO", "DEBUG", "WARN", "ERROR" };
37
38void log_message(int l, const char *file, int line, const char *fmt, ...)
39{
40 va_list arg;
41 if (g_nolog) return;
42 if(g_log_level > l) return;
43
44 FILE *fp = fopen("/tmp/mmelogs.txt", "a+");
45 if (fp == NULL)
46 {
47 printf("Could not open log file");
48 exit(0);
49 }
50
51 fprintf(fp,"%s(%d:%ld):%s-%s:%d:", processName, pid, syscall(SYS_gettid), log_level_name[l], file, line);
52 va_start(arg, fmt);
53// vfprintf(stderr, fmt, arg);
54 vfprintf(fp, fmt, arg);
55 va_end(arg);
56 fclose(fp);
57// fprintf(stderr, "\n");
58}
59