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 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_UTIL_STRUCT_LOG_H_
18 #define incl_HPHP_UTIL_STRUCT_LOG_H_
23 #include <folly/futures/Future.h>
24 #include <folly/json.h>
25 #include <folly/Range.h>
31 ///////////////////////////////////////////////////////////////////////////////
33 struct StructuredLogEntry
{
36 // Any previous value for the same key is silently overwritten.
37 void setInt(folly::StringPiece key
, int64_t value
);
38 void setStr(folly::StringPiece key
, folly::StringPiece value
);
39 void setSet(folly::StringPiece key
,
40 const std::set
<folly::StringPiece
>& values
);
41 void setVec(folly::StringPiece key
,
42 const std::vector
<folly::StringPiece
>& values
);
43 void setStackTrace(folly::StringPiece key
, const StackTrace
& st
);
46 bool force_init
{false};
47 folly::dynamic ints
, strs
, sets
, vecs
;
50 std::string
show(const StructuredLogEntry
&);
53 * Interface for recording structured data for relatively infrequent events.
55 namespace StructuredLog
{
56 using LogFn
= void (*)(const std::string
&,
57 const StructuredLogEntry
&);
58 using RecordGlobalsFn
= void (*)(StructuredLogEntry
&);
61 bool coinflip(uint32_t rate
);
62 void enable(LogFn log
, RecordGlobalsFn globals
);
63 void log(const std::string
&, const StructuredLogEntry
&);
64 void recordRequestGlobals(StructuredLogEntry
&);
67 ///////////////////////////////////////////////////////////////////////////////