Skip to content

Commit

Permalink
Merge pull request #4 from alexandre-deceneux/create_update_in_place_…
Browse files Browse the repository at this point in the history
…method

Add the `update_in_place` method
  • Loading branch information
allan-simon committed Jun 16, 2017
2 parents ef2cab0 + 1cfe656 commit 9dec4b1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ You can use the new_with() function to create a first set of parameters to log.
logger = logger.new_with({"action": "get_logs"})
```

## Add a new set of parameters

You can use the update_in_place() function add a new set of parameters to the current logger instance.

```
logger.update_in_place({"resource_id": "0"})
```

## Log information

There are different kind of logs that will be written into syslog
Expand Down Expand Up @@ -79,6 +87,27 @@ def bar(logger):
# log app / stack / request_id / action
x_logger.info({"action": "do_something"})

def update_logger_default_set(logger):
"""
Update the logger instance by adding a new parameter set
"""
logger.update_in_place({"resource_id": "0"}


def baz(logger):
"""
Third method
"""
# log app / stack / step
x_logger.info({"step": "start"})

# Call the function that add "resource_id" to the logger parameter set
update_logger_default_set(logger)

# log app / stack / resource_id / step
x_logger.info({"step": "end"})

foo(logger)
bar(logger)
baz(logger)
```
7 changes: 6 additions & 1 deletion kibana_logger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ def new_with(self, more_preset):
new_preset = self._merge_with_preset(more_preset)
return self.__class__(new_preset)

def update_in_place(self, more_preset):
'''Add some presets to the current instance ones.
Use this method wisely as it alters the current instance
'''
self.preset.update(more_preset)

def _merge_with_preset(self, data):
'''merge preset with given data
'''
Expand Down Expand Up @@ -74,4 +80,3 @@ def critical(self, data):
'''
text = self._create_syslog_string(data)
syslog.syslog(syslog.LOG_CRIT, text)

0 comments on commit 9dec4b1

Please sign in to comment.