Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
log.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "tonic/common/log.h"
6
7#include <cstdarg>
8#include <cstdio>
9#include <memory>
10
11namespace tonic {
12
13namespace {
14
15std::function<void(const char*)> log_handler;
16
17} // namespace
18
19void Log(const char* format, ...) {
20 va_list ap;
21 va_start(ap, format);
22 int result = vsnprintf(nullptr, 0, format, ap);
23 va_end(ap);
24
25 if (result < 0) {
26 return;
27 }
28
29 int size = result + 1;
30 std::unique_ptr<char[]> message = std::make_unique<char[]>(size);
31 va_start(ap, format);
32 result = vsnprintf(message.get(), size, format, ap);
33 va_end(ap);
34
35 if (result < 0) {
36 return;
37 }
38
39 if (log_handler) {
40 log_handler(message.get());
41 } else {
42 printf("%s\n", message.get());
43 }
44}
45
46void SetLogHandler(std::function<void(const char*)> handler) {
47 log_handler = handler;
48}
49
50} // namespace tonic
GAsyncResult * result
uint32_t uint32_t * format
Win32Message message
void SetLogHandler(std::function< void(const char *)> handler)
Definition log.cc:46
void Log(const char *format,...)
Definition log.cc:19