summaryrefslogtreecommitdiffstats
path: root/common/Logging.cpp
blob: 4ba3d7a26722522c35839d7f1fc2c13ba4e2b761 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
 * File:	Logging.cpp
 *
 * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
 * See included license file for license details.
 */

#include "Logging.h"
#include <stdarg.h>
#include <stdio.h>
#include "smart_ptr.h"

// init global logger to null
Logger * Log::s_logger = NULL;

void Logger::log(const char * fmt, ...)
{
	va_list args;
	va_start(args, fmt);
	log(m_level, fmt, args);
	va_end(args);
}

void Logger::log(log_level_t level, const char * fmt, ...)
{
	va_list args;
	va_start(args, fmt);
	log(level, fmt, args);
	va_end(args);
}

void Logger::log(const char * fmt, va_list args)
{
	log(m_level, fmt, args);
}

//! Allocates a temporary 1KB buffer which is used to hold the
//! formatted string.
void Logger::log(log_level_t level, const char * fmt, va_list args)
{
	smart_array_ptr<char> buffer = new char[1024];
	vsprintf(buffer, fmt, args);
	if (level <= m_filter)
	{
		_log(buffer);
	}
}

void Log::log(const char * fmt, ...)
{
	if (s_logger)
	{
		va_list args;
		va_start(args, fmt);
		s_logger->log(fmt, args);
		va_end(args);
	}
}

void Log::log(const std::string & msg)
{
	if (s_logger)
	{
		s_logger->log(msg);
	}
}

void Log::log(Logger::log_level_t level, const char * fmt, ...)
{
	if (s_logger)
	{
		va_list args;
		va_start(args, fmt);
		s_logger->log(level, fmt, args);
		va_end(args);
	}
}

void Log::log(Logger::log_level_t level, const std::string & msg)
{
	if (s_logger)
	{
		s_logger->log(level, msg);
	}
}

void StdoutLogger::_log(const char * msg)
{
	printf("%s", msg);
}