@@ -60,15 +60,60 @@ To quickly test your setup, add a matcher that logs to the stdout:
60
60
Usage
61
61
-----
62
62
63
+ FluentSender Interface
64
+ ~~~~~~~~~~~~~~~~~~~~~~
65
+
66
+ `sender.FluentSender ` is a structured event logger for Fluentd.
67
+
68
+ By default, the logger assumes fluentd daemon is launched locally. You
69
+ can also specify remote logger by passing the options.
70
+
71
+ .. code :: python
72
+
73
+ from fluent import sender
74
+
75
+ # for local fluent
76
+ logger = sender.FluentSender(' app' )
77
+
78
+ # for remote fluent
79
+ logger = sender.FluentSender(' app' , host = ' host' , port = 24224 )
80
+
81
+ For sending event, call `emit ` method with your event. Following example will send the event to
82
+ fluentd, with tag 'app.follow' and the attributes 'from' and 'to'.
83
+
84
+ .. code :: python
85
+
86
+ # Use current time
87
+ logger.emit(' follow' , {' from' : ' userA' , ' to' : ' userB' })
88
+
89
+ # Specify optional time
90
+ cur_time = int (time.time())
91
+ logger.emit_with_time(' follow' , cur_time, {' from' : ' userA' , ' to' :' userB' })
92
+
93
+ You can detect an error via return value of `emit `. If an error happens in `emit `, `emit ` returns `False ` and get an error object using `last_error ` method.
94
+
95
+ .. code :: python
96
+
97
+ if not logger.emit(' follow' , {' from' : ' userA' , ' to' : ' userB' }):
98
+ print (logger.last_error)
99
+ logger.clear_last_error() # clear stored error after handled errors
100
+
101
+ If you want to shutdown the client, call `close() ` method.
102
+
103
+ .. code :: python
104
+
105
+ logger.close()
106
+
63
107
Event-Based Interface
64
108
~~~~~~~~~~~~~~~~~~~~~
65
109
66
- First, you need to call ``logger.setup() `` to create global logger
110
+ This API is a wrapper for `sender.FluentSender `.
111
+
112
+ First, you need to call ``sender.setup() `` to create global `sender.FluentSender ` logger
67
113
instance. This call needs to be called only once, at the beggining of
68
114
the application for example.
69
115
70
- By default, the logger assumes fluentd daemon is launched locally. You
71
- can also specify remote logger by passing the options.
116
+ Initialization code of Event-Based API is below:
72
117
73
118
.. code :: python
74
119
@@ -81,7 +126,7 @@ can also specify remote logger by passing the options.
81
126
sender.setup(' app' , host = ' host' , port = 24224 )
82
127
83
128
Then, please create the events like this. This will send the event to
84
- fluent , with tag 'app.follow' and the attributes 'from' and 'to'.
129
+ fluentd , with tag 'app.follow' and the attributes 'from' and 'to'.
85
130
86
131
.. code :: python
87
132
@@ -93,11 +138,14 @@ fluent, with tag 'app.follow' and the attributes 'from' and 'to'.
93
138
' to' : ' userB'
94
139
})
95
140
96
- If you want to shutdown the client, call `close() ` method.
141
+ `event.Event ` has one limitation which can't return success/failure result.
142
+
143
+ Other methods for Event-Based Interface.
97
144
98
145
.. code :: python
99
146
100
- sender.close()
147
+ sender.get_global_sender # get instance of global sender
148
+ sender.close # Call FluentSender#close
101
149
102
150
Handler for buffer overflow
103
151
~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -114,7 +162,7 @@ You can inject your own custom proc to handle buffer overflow in the event of co
114
162
for unpacked in unpacker:
115
163
print (unpacked)
116
164
117
- sender.setup (' app' , host = ' host' , port = 24224 , buffer_overflow_handler = handler)
165
+ logger = sender.FluentSender (' app' , host = ' host' , port = 24224 , buffer_overflow_handler = handler)
118
166
119
167
You should handle any exception in handler. fluent-logger ignores exceptions from ``buffer_overflow_handler ``.
120
168
0 commit comments