]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - tools/elftosb/common/Logging.cpp
merged tx6dl-devel into denx master branch
[karo-tx-uboot.git] / tools / elftosb / common / Logging.cpp
1 /*
2  * File:        Logging.cpp
3  *
4  * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5  * See included license file for license details.
6  */
7
8 #include "Logging.h"
9 #include <stdarg.h>
10 #include <stdio.h>
11 #include "smart_ptr.h"
12
13 // init global logger to null
14 Logger * Log::s_logger = NULL;
15
16 void Logger::log(const char * fmt, ...)
17 {
18         va_list args;
19         va_start(args, fmt);
20         log(m_level, fmt, args);
21         va_end(args);
22 }
23
24 void Logger::log(log_level_t level, const char * fmt, ...)
25 {
26         va_list args;
27         va_start(args, fmt);
28         log(level, fmt, args);
29         va_end(args);
30 }
31
32 void Logger::log(const char * fmt, va_list args)
33 {
34         log(m_level, fmt, args);
35 }
36
37 //! Allocates a temporary 1KB buffer which is used to hold the
38 //! formatted string.
39 void Logger::log(log_level_t level, const char * fmt, va_list args)
40 {
41         smart_array_ptr<char> buffer = new char[1024];
42         vsprintf(buffer, fmt, args);
43         if (level <= m_filter)
44         {
45                 _log(buffer);
46         }
47 }
48
49 void Log::log(const char * fmt, ...)
50 {
51         if (s_logger)
52         {
53                 va_list args;
54                 va_start(args, fmt);
55                 s_logger->log(fmt, args);
56                 va_end(args);
57         }
58 }
59
60 void Log::log(const std::string & msg)
61 {
62         if (s_logger)
63         {
64                 s_logger->log(msg);
65         }
66 }
67
68 void Log::log(Logger::log_level_t level, const char * fmt, ...)
69 {
70         if (s_logger)
71         {
72                 va_list args;
73                 va_start(args, fmt);
74                 s_logger->log(level, fmt, args);
75                 va_end(args);
76         }
77 }
78
79 void Log::log(Logger::log_level_t level, const std::string & msg)
80 {
81         if (s_logger)
82         {
83                 s_logger->log(level, msg);
84         }
85 }
86
87 void StdoutLogger::_log(const char * msg)
88 {
89         printf(msg);
90 }
91