Changeset 2880 for WAeUP_SysConf


Ignore:
Timestamp:
8 Dec 2007, 00:48:01 (17 years ago)
Author:
uli
Message:

Fixed INSERT mode. Added usage hints.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SysConf/logging/trunk/usr/local/lib/zevents.py

    r2879 r2880  
    2323##
    2424
     25##
     26## Usage: python zevents.py [-INSERT]
     27##
     28## Reads Zope event logs from stdin and turn it into PostGres compatible
     29## output on stdout.
     30##
     31## If no options are given, output is formatted as a COPY command, which is
     32## *much* (50 times or more) faster in PostGres.
     33##
     34## If -INSERT is given, output is formatted as a list of INSERT statements,
     35## which will need much more time and resources.
     36##
     37
    2538import sys
    2639import re
     
    3245##
    3346mode = "COPY"
     47
     48if '-INSERT' in sys.argv:
     49    mode = "INSERT"
    3450
    3551faillog = "/var/log/updatedblog/zevents-failed.log"
     
    6682    data = data.replace("\t", "    ")
    6783    return data
     84
     85def q(text):
     86    return text.replace("'","\\\'")
    6887
    6988def print_dataset(data, lnum, mode):
     
    107126        )
    108127    else:
    109         print "INSERT INTO \"ZEVENTS\" (\"ID\",\"DATESTR\",\"TIMESTR\",\"MSG_SRC\",\"MSG\",\"ERR_TYPE\",\"ERR_MSG\",\"TRACEBACK\",\"LOGLEVEL\") VALUES ('%07d','%s','%s','%s','%s','%s','%s','%s');" % (
    110             val['id'], val['date'], val['time'], val['msg_src'],
    111             val['msg_text'], val['err_type'], val['err_msg'], val['traceback'],
    112             val['loglevel']
     128        print "INSERT INTO \"ZEVENTS\" (\"ID\",\"DATESTR\",\"TIMESTR\",\"MSG_SRC\",\"MSG\",\"ERR_TYPE\",\"ERR_MSG\",\"TRACEBACK\",\"LOGLEVEL\") VALUES ('%07d','%s','%s','%s','%s','%s','%s','%s','%s');" % (
     129            val['id'], q(val['date']), q(val['time']), q(val['msg_src']),
     130            q(val['msg_text']), q(val['err_type']), q(val['err_msg']),
     131            q(val['traceback']), q(val['loglevel'])
    113132        )
    114133    return
Note: See TracChangeset for help on using the changeset viewer.