2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2016 Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
22 #include <folly/futures/Future.h>
23 #include <folly/json.h>
24 #include <folly/Range.h>
30 ///////////////////////////////////////////////////////////////////////////////
32 struct StructuredLogEntry
{
35 // Any previous value for the same key is silently overwritten.
36 void setInt(folly::StringPiece key
, int64_t value
);
37 void setStr(folly::StringPiece key
, folly::StringPiece value
);
38 void setSet(folly::StringPiece key
,
39 const std::set
<folly::StringPiece
>& values
);
40 void setVec(folly::StringPiece key
,
41 const std::vector
<folly::StringPiece
>& values
);
42 void setStackTrace(folly::StringPiece key
, const StackTrace
& st
);
45 bool force_init
{false};
46 folly::dynamic ints
, strs
, sets
, vecs
;
49 std::string
show(const StructuredLogEntry
&);
52 * Interface for recording structured data for relatively infrequent events.
54 namespace StructuredLog
{
55 using LogFn
= void (*)(const std::string
&,
56 const StructuredLogEntry
&);
57 using RecordGlobalsFn
= void (*)(StructuredLogEntry
&);
60 bool coinflip(uint32_t rate
);
61 void enable(LogFn log
, RecordGlobalsFn globals
);
62 void log(const std::string
&, const StructuredLogEntry
&);
63 void recordRequestGlobals(StructuredLogEntry
&);
66 ///////////////////////////////////////////////////////////////////////////////