Logging and filtering using log4cxx - c++

I am working on the application where I need logging and filtering feature.
I am using c++. I came to know about the log4cxx support logging.
I am getting difficulty in filtering .
I have five fields
MAcID
Date and time
Command type
Status
Text Msg
I need to store these 5 fields in the log file and filter it as well based on below filtering option. Logging and filtering will be done at run time itself. Once the file size reaches 10 MiB, it will start rewriting the file from the beginning.
Filtering Options
1. MAcID
2. date and time
Filtering can done by filtering either one or both.
Result should return all the field in the log file .
Is it possible to store more than one field in the log file using log4CXX?
How to filter the information based on above mentioned criteria?
Do I need to write my own filter class inheriting from existing filter classes?
Do I need to write customise logger class to store 5 field in the log file?

I faced once a similar problem than points 1 and 4. I read log4cxx code and I found a possible solution. A job mate tested the solution and progressed it. His conclusions can be found here.
We asked in the log4cxx mailing list if it was the right solution and this is the answer we got. I hope that helps.

I don't think that log4cxx is the right tools for your task, and I am not really sure if this can be done at all with log4cxx.
You can start with a custom appender and your own log level and your own filter.
Do get it running you need to set a log level do determine which filter field should be used and when ever you change the filter you need to clear the Filters and set a new one.
Then you can extract the log string, search for your filter and let it decide if you want to output the log message or not.

Related

Google Analytics Filter Set of Pages

I need to create a filter on Google Analytics to include only a set of pages, for example, the view will have a filter to collect data only from
www.example.com/page1.html
www.example.com/page2.html
www.example.com/page3.html
I am trying to achieve this by using a Custom Filter to Include - > Request URI and using a Regex on the Filter Pattern.
My problem is that the Regex exceeds the 255 character limitation, even after I tried to optimice the regex to be a small as possible.
Creating more than one Include Filter does not work because this way no data would be collected, so I am wondering how could I achieve this? Thank you
This is the original regex
/es/investigacion/lace\.html|/en/research/lace\.html|/es/investigacion/lace/programa-maestrias\.html|/es/investigacion/lace/alumni/latin-american-forum-entrepreneurs\.html|/es/investigacion/lace/alumni/fondo-angel-investment\.html|/es/investigacion/lace/alumni\.html|/es/investigacion/lace/fondo-inversion\.html|/es/investigacion/lace/investigacion\.html|/es/investigacion/lace/acerca-del-centro\.html|/es/investigacion/lace/alumni/estudiantes-del-pais\.html|/en/research/investigation\.html|/en/research/about-the-center\.html|/es/investigacion/lace/alumni/mentoring\.html|/es/investigacion/lace/alumni/reatu-entrepreneur-award\.html|/en/research/lace/master-program\.html|/en/research/lace/alumni\.html|/en/research/investment-fund\.html
Edit: first try to compress the regex
/es/investigacion/lace/(programa-maestrias|alumni|investigacion|programa-maestrias|alumni/latin-american-forum-entrepreneurs|alumni/fondo-angel-investment|fondo-inversion|investigacion|acerca-del-centro|alumni/estudiantes-del-pais|alumni/mentoring|alumni/incae-entrepreneur-award)\.html|
Edit: the reason for this is because I need to create a new user profile on GA, and this new profile will have access to the information of a set of URLs only; so what occurred to me is create a new View that only captures the information of this set of URLs, and then assign the profile to this view with "Read/Analyze" permissons.
There are definitely more ways to optimise the regex. For example, since all string options end with .html, you could do something like this:
/(es/investigacion/lace|en/research/lace)\.html
by taking the .html out.
You could also take out
/es/investigacion/lace
and weave in the variable part of that using |'s, eg.
/es/investigacion/lace/(programa-maestrias|alumni|investigacion)\.html
But try a few of those optimisation techniques and you should be able to fit more in.

WebRatio - fill list with custom query

I just started to use WebRatio and I am facing a simple problem, with easy solution if I was not using this fabulous framework .... I was asked to do some sort of glosary app, and what I am trying to do right now is a simple index where appears all letters from A-Z and how many entries starting with each letter there are in my database, quite simple.
I aleady started a database with my entity: name, description and last_modified. I had been looking for some information on how to do this but I found nothing. So what I am trying to do is to fill a list with a custom query that I made (it works good on my sql editor) but I am not able to list the results in a WebRatio list. I tried to use a "query" object linked to a "simpleList" object but when I run the app it gives me error: "Expected at least one element .. inside " I would appreciate any help or resource that explains how to do this.
Thanks in advance
You shouldn't link the query unit with list because the list will make it's own database query. Instead you should specify outputs for query unit and write your custom style template for query unit to visualize the results as html. Or also (not recommended) you can link the results of query unit with a script unit and output desired html within a script unit.

How to get the upgrade code using the MsiGetProductInfo and MsiOpenDatabase?

I have read a few posts on StackOverflow itself about getting the UpgradeCode using 2 queries. First, use MsiGetProductInfo to get the database path (how?!) to open the database which will contain the UpgradeCode. Please provide the API call to fetch the database path! Urgent.
Call MsiEnumProducts to find the package code if you only know the name, then call MsiGetProductInfo with the product code to get INSTALLPROPERTY_LOCALPACKAGE property (i.e. the "database"/msi file), open the database, find UpgradeCode in the property table, done. That answers your question - but I'm not sure why you would need this in such a manner.

Mediawiki mass user delete/merge/block

I have 500 or so spambots and about 5 actual registered users on my wiki. I have used nuke to delete their pages but they just keep reposting. I have spambot registration under control using reCaptcha. Now, I just need a way to delete/block/merge about 500 users at once.
You could just delete the accounts from the user table manually, or at least disable their authentication info with a query such as:
UPDATE /*_*/user SET
user_password = '',
user_newpassword = '',
user_email = '',
user_token = ''
WHERE
/* condition to select the users you want to nuke */
(Replace /*_*/ with your $wgDBprefix, if any. Oh, and do make a backup first.)
Wiping out the user_password and user_newpassword fields prevents the user from logging in. Also wiping out user_email prevents them from requesting a new password via email, and wiping out user_token drops any active sessions they may have.
Update: Since I first posted this, I've had further experience of cleaning up large numbers of spam users and content from a MediaWiki installation. I've documented the method I used (which basically involves first deleting the users from the database, then wiping out up all the now-orphaned revisions, and finally running rebuildall.php to fix the link tables) in this answer on Webmasters Stack Exchange.
Alternatively, you might also find Extension:RegexBlock useful:
"RegexBlock is an extension that adds special page with the interface for blocking, viewing and unblocking user names and IP addresses using regular expressions."
There are risks involved in applying the solution in the accepted answer. The approach may damage your database! It incompletely removes users, doing nothing to preserve referential integrity, and will almost certainly cause display errors.
Here a much better solution is presented (a prerequisite is that you have installed the User merge extension):
I have a little awkward way to accomplish the bulk merge through a
work-around. Hope someone would find it useful! (Must have a little
string concatenation skills in spreadsheets; or one may use a python
or similar script; or use a text editor with bulk replacement
features)
Prepare a list of all SPAMuserIDs, store them in a spreadsheet or textfile. The list may be
prepared from the user creation logs. If you do have the
dB access, the Wiki_user table can be imported into a local list.
The post method used for submitting the Merge & Delete User form (by clicking the button) should be converted to a get method. This
will get us a long URL. See the second comment (by Matthew Simoneau)
dated 13/Jan/2009) at
http://www.mathworks.com/matlabcentral/newsreader/view_thread/242300
for the method.
The resulting URL string should be something like below:
http: //(Your Wiki domain)/Special:UserMerge?olduser=(OldUserNameHere)&newuser=(NewUserNameHere)&deleteuser=1&token=0d30d8b4033a9a523b9574ccf73abad8%2B\
Now, divide this URL into four sections:
A: http: //(Your Wiki domain)/Special:UserMerge?olduser=
B: (OldUserNameHere)
C: &newuser=(NewUserNameHere)&deleteuser=1
D: &token=0d30d8b4033a9a523b9574ccf73abad8%2B\
Now using a text editor or spreadsheet, prefix each spam userIDs with part A and Suffix each with Part C and D. Part C will include the
NewUser(which is a specially created single dummy userID). The Part D,
the Token string is a session-dependent token that will be changed per
user per session. So you will need to get a new token every time a new
session/batch of work is required.
With the above step, you should get a long list of URLs, each good to do a Merge&Delete operation for one user. We can now create a
simple HTML file, view it and use a batch downloader like DownThemAll
in Firefox.
Add two more pieces " Linktext" to each line at
beginning and end. Also add at top and at
bottom and save the file as (for eg:) userlist.html
Open the file in Firefox, use DownThemAll add-on and download all the files! Effectively, you are visiting the Merge&Delete page for
each user and clicking the button!
Although this might look a lengthy and tricky job at first, once you
follow this method, you can remove tens of thousands of users without
much manual efforts.
You can verify if the operation is going well by opening some of the
downloaded html files (or by looking through the recent changes in
another window).
One advantage is that it does not directly edit the
MySQL pages. Nor does it require direct database access.
I did a bit of rewriting to the quoted text, since the original text contains some flaws.

Create/Edit MS Word & Word Perfect docs in Django?

Is it possible to create and/or edit MS Word and Word Perfect documents with django? I'd like to be able to allow the user to fill out a form and have the form fields inserted into an MS Word/Word Perfect document. Or, the form fields are used to create a new MS Word/Word Perfect document. The user can then send that document via email to others who may not have access to the django web-app.
I have a client who needs this functionality and I'd like to keep it all within the web-app.
Any ideas?
Thanks!
For MS Word, you could use docx-mailmerge. Run the following commands to install lxml(dependecy required by docx-mailmerge) and docx-mailmerge
conda install lxml
pip install docx-mailmerge
In order for docx-mailmerge to work correctly, you need to create a standard Word document and define the appropriate merge fields. The examples below are for Word 2010. Other versions of Word should be similar. It actually took me a while to figure out this process but once you do it a couple of times, it is pretty simple.
Start Word and create the basic document structure. Then place the cursor in the location where the merged data should be inserted and choose Insert -> Quick Parts -> Field..:
Word Quick Parts
From the Field dialog box, select the “MergeField” option from the Field Names list. In the Field Name, enter the name you want for the field. In this case, we are using Business Name.
Word Add Field
Once you click ok, you should see something like this: <> in the Word document. You can go ahead and create the document with all the needed fields.
from __future__ import print_function
from mailmerge import MailMerge
from datetime import date
template = "Practical-Business-Python.docx"
document = MailMerge(template)
document.merge(
status='Gold',
city='Springfield',
phone_number='800-555-5555',
Business='Cool Shoes',
zip='55555',
purchases='$500,000',
shipping_limit='$500',
state='MO',
address='1234 Main Street',
date='{:%d-%b-%Y}'.format(date.today()),
discount='5%',
recipient='Mr. Jones')
document.write('test-output.docx')
More at http://pbpython.com/python-word-template.html
I do not know how to do exactly what you ask for, but I would suggest that you also look into creating PDFs with Django. If you only want to send information in a particular format then PFD might be better because it is more portable across platforms. You may also want to look at this documentation for how to send emails from Django.