blob: c65165f39116d2db8eb59169948fda80acff2a88 [file] [log] [blame]
Zack Williamsf1b50982018-08-26 16:35:49 -07001#!/usr/bin/env python
2
3# Copyright 2018-present Open Networking Foundation
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17import multistructlog
18import time
19
20# config of logging
21logconfig = {
22 "version": 1,
23 "handlers": {
24 "console": {
25 "class": "logging.StreamHandler"
26 },
27 "kafka": {
28 "class": "kafkaloghandler.kafkaloghandler.KafkaLogHandler",
29 "bootstrap_servers": ["test-kafka:9092"],
30 "topic": "testtopic"
31 },
32 },
33
34 "loggers": {
35 "multistructlog": {
36 "handlers": ["console", "kafka"],
37 "level": "DEBUG"
38 }
39 },
40}
41
42logger = multistructlog.create_logger(logconfig)
43
44logger.error('Test error message')
45
46extra_data = {
47 "key1": "value1",
48 "key2": "value2",
49}
50
51logger.info('Test info message with extra data', extra=extra_data)
52
53index = 0
54while True:
55 logger.info('Info message - loop count: %s' % index)
56 index += 1
57 time.sleep(10)