Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/scanoss.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

- name: Run SCANOSS Code Scan
id: scanoss-code-scan-step
uses: scanoss/code-scan-action@v1
uses: scanoss/code-scan-action@v1.3.1
with:
policies: copyleft, undeclared, depTrack
api.url: https://api.scanoss.com/scan/direct
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.scanoss
.env
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
repos:
- repo: https://github.com/scanoss/pre-commit-hooks
rev: v0.2.0
rev: v0.3.0
hooks:
- id: scanoss-check-undeclared-code
106 changes: 106 additions & 0 deletions copyleft_renamed.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@

#include <pthread.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>







#include "log.h"

static const char *level_names[] = {
"TRACE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL"};

// Default log level is INFO
static int LEVEL = LOG_INFO;

// Default log file is STDERR
static FILE *LOG_FILE = NULL;

char *format_timestamp()
{
// I. Format timestamp
// Always use UTC time
char *out = malloc(64);
time_t t = time(NULL);
struct tm *utc = gmtime(&t);
strftime(out, 64, "%d-%m-%y %H:%M:%S", utc);
return out;
}

/**
* Formats UTC timestamp in common log format.
*/
char *format_ts_common_log()
{
//%d/%b/%Y:%H:%M:%S %z
char *out = malloc(64);
time_t t = time(NULL);
struct tm *utc = gmtime(&t);
strftime(out, 64, "%d/%b/%Y:%H:%M:%S %z", utc);
return out;
}

void __logger(int level, const char *file, int line, const char *func, const char *format, ...)
{
if (level < LEVEL)
{
return;
}

if (LOG_FILE == NULL)
{
LOG_FILE = stderr;
}

char *buf = format_timestamp();
va_list args;

// II. Format log
fprintf(LOG_FILE, "%s %lu %-5s %s:%s:%d: ", buf, (unsigned long) pthread_self(), level_names[level], file, func, line);
va_start(args, format);
vfprintf(LOG_FILE, format, args);
va_end(args);
fprintf(LOG_FILE, "\n");
fflush(LOG_FILE);
free(buf);

// Exit with error if log level is FATAL
if (level == LOG_FATAL)
{
exit(EXIT_FAILURE);
}
}

bool log_level_is_enabled(int level)
{
return level >= LEVEL;
}

void log_set_level(int level)
{
LEVEL = level;
}

void log_set_file(char *filename)
{
LOG_FILE = fopen(filename, "a+");
if (LOG_FILE == NULL)
{
fprintf(stderr, "ERROR SETTING LOG FILE: %s\n", filename);
exit(EXIT_FAILURE);
}
}

void log_close_file()
{
fclose(LOG_FILE);
}
File renamed without changes.
Loading
Loading