Skip to content

Commit

Permalink
file option for overwrite
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmens committed Dec 3, 2015
1 parent d45f054 commit d8bd651
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -558,11 +558,14 @@ Supposing we wish to archive all incoming messages to the branch `arch/#` to a f
```ini
[config:file]
append_newline = True
overwrite = False
targets = {
'log-me' : ['/data/arch']
}
```
If `append_newline` is True, a newline character is unconditionally appended to the string written to the file. If `overwrite` is True, the file is opened for truncation upon writing (i.e. the file will contain the last message only).
## `freeswitch`
Expand Down
6 changes: 5 additions & 1 deletion services/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ def plugin(srv, item):

srv.logging.debug("*** MODULE=%s: service=%s, target=%s", __file__, item.service, item.target)

mode = "a"

# item.config is brought in from the configuration file
config = item.config

Expand All @@ -23,9 +25,11 @@ def plugin(srv, item):

if type(config) == dict and 'append_newline' in config and config['append_newline']:
text = text + "\n"
if type(config) == dict and 'overwrite' in config and config['overwrite']:
mode = "w"

try:
f = open(filename, "a")
f = open(filename, mode)
f.write(text)
f.close()
except Exception, e:
Expand Down

0 comments on commit d8bd651

Please sign in to comment.