Skip to content

Instantly share code, notes, and snippets.

@benediktg
Last active April 11, 2016 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benediktg/39ef9fbe0be8ae671d345d1fa4c0c781 to your computer and use it in GitHub Desktop.
Save benediktg/39ef9fbe0be8ae671d345d1fa4c0c781 to your computer and use it in GitHub Desktop.
Owncloud log formatting with vim

This is meant as a help if you want to have better readable Owncloud log entries. First navigate to the directory of your owncloud.log and download the vimcommands.txt down below with

wget https://gist.githubusercontent.com/benediktg/39ef9fbe0be8ae671d345d1fa4c0c781/raw/vimcommands.txt

Then execute

vim -s vimcommands.txt -u NONE - < owncloud.log

for the whole file or

tail -n1 owncloud.log | vim -s vimcommands.txt -u NONE -

for just the last entry.

After that you should see a kind of properly indented JSON file. In a final step note that you have to quit vim with :q! ;-)

:%s/\\\\\\\//\//g
:%s/\\\\\\\\/\\/g
:%s/\\\\n/\r/gI
:%s/\\"/"/g
:%s/"#0/"\r#0/g
:%s/Array\zs\\n(\\n\ze/ (\r\t/gI
:%s/\\n/\r\t/gI
:%s/","/",\r\t"/g
:%s/,"/,\r\t"/g
:%s/{"/{\r\t"/g
:%s/"}/"\r}/g
:%s/^#/\t\t#/g
:%s/\\\//\//g
:%s/\\\\/\\/g
:%s/)\n\t)/))/g
:%s/\:\zs \ze{\n/\r\t/g
:syntax enable
:set syntax=json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment