How to configure logging of insert statements using pgAdmin? - java

I want to use pgAdmin to configure to log all sql insert statements. But how?
I found the Backend Configuration Editor and enabled log_statement=all. But how can I control the file to that the log statements are written? (eg: c\logs.txt)

log_destination = 'stderr,csvlog'
log_statement = 'all'
#see C:\Program Files\PostgreSQL\9.3\data\pg_log

See the manual. You probably want to set log_directory and log_filename.
You cannot set individual log destinations for particular categories of log line - say, log statements to one file, other logs to another file. This would be a nice feature; if you have time, consider raising the idea on pgsql-hackers and after discussion submitting a suitable patch.
Most people use csvlog, or use text logs with a log_line_prefix set, then filter the logs with simple tools like grep to extract the desired information.
For statement data collection, also have a look at the pg_stat_statements extension.

Related

p6spy, create a new log file (with timestamp) at each start

title say it everything. I want to log my sql queries but the problem is, at each program restart it append query in same file because I'm specifying the same in my spy.properties file:
driverlist=com.mysql.cj.jdbc.Driver
dateformat=yyyy-MM-dd HH:mm:ss.SSSS
appender=com.p6spy.engine.spy.appender.FileLogger
logfile=C:\\Users\\manis\\Documents\\log\\dblog\\spy.log
logMessageFormat=com.p6spy.engine.spy.appender.SingleLineFormat
I want log file to have name something like this: spy_TIMESTAMP.log
I m using JDBC for db connection.
P6Spy does not support that functionality out of the box, but one thing you could do is to override values from spy.properties passing system properties -Dp6spy.config.logfile=myuniquefile.log or from the code:
System.setProperty("p6spy.config.logfile", String.format("C:\\Users\\manis\\Documents\\log\\dblog\\spy-%s.log", System.currentTimeMillis()));
but it should happen before JDBC driver initialisation.

How to configure JBoss JsonFormatter for Filebeat (WildFly 14)

I have Filebeat pulling logs from stdout. I want to ensure my logs are outputted as JSON, so they can be properly parsed.
Thus far, here's what I've found:
org.jboss.logmanager.formatters doesn't have a JSON formatter
There's an "extension" module that provides a JsonFormatter class.
I can use it in my logging.properties by doing something like this:
handler.CONSOLE=org.jboss.logmanager.handlers.ConsoleHandler
handler.CONSOLE.properties=autoFlush,target
handler.CONSOLE.autoFlush=true
handler.CONSOLE.formatter=JSON-FORMATTER
handler.CONSOLE.target=SYSTEM_OUT
formatter.JSON-FORMATTER=org.jboss.logmanager.ext.formatters.JSONFormatter
I need to know:
Am I missing anything with this configuration?
How can I customise the JSON output (i.e. add or remove fields)?
There is a json-formatter in WildFly 14. I would not suggest editing the logging.properties. The following CLI commands are an example of configuring a json-formatter.
/subsystem=logging/json-formatter=json:add(exception-output-type=formatted, pretty-print=false, meta-data={label=value})
/subsystem=logging/console-handler=CONSOLE:write-attribute(name=named-formatter, value=json)
Note the meta-data attribute is just a key/value pair separated by commas.
How can I customise the JSON output (i.e. add or remove fields)?
You can really only add metadata or change field names. You can't remove fields though.

ThriftSecurityException (user:root, code:BAD_CREDENTIALS)

When I try to connect to accumulo from a java client, it is failing. I am using the 'root' user but have changed the password. I debugged my code, it is in fact getting the correct user name and password, the same I one I use to log into the shell with.
I read on some other sites that I have to set 'trace.user' and 'trace.password' in my accumulo-site.xml file, so I did that and restarted accumulo. Unfortunately it did not change a thing.
When I try to connect from java, these are the important lines from the stack:
Caused by: org.apache.accumulo.core.client.AccumuloSecurityException: Error BAD_CREDENTIALS for user root - Username or Password is Invalid
Caused by: ThriftSecurityException(user:root, code:BAD_CREDENTIALS)
From my accumulo console, I see this:
08 15:44:06,0544 tserver:michael-GA-890GPA-UD3H 4
ERROR
ThriftSecurityException(user:root, code:BAD_CREDENTIALS)
When I look through my accumulo logs I just see the same exception and its stack getting printed every second that goes by.
I went looking through the accumulo manual and couldn't find anything that I'm missing. A google search and SO search also did not help me.
Would somebody please tell me what I'm doing wrong?
Depending on the version you're using, you may also have trace.token.property.password defined in accumulo-site.xml which is the replacement for trace.password. >=1.6.0 introduced the trace.token.property.password property. If both that property and trace.password are present in the configuration, trace.token.property.password will take precedence over trace.password.
Look at the $ACCUMULO_LOG_DIR/tracer_$hostname.debug.log file, you'll likely have numerous exceptions in there.
The "proper" way (read as: how you'd want to do it in a production environment) to configure the tracer is to create the 'trace' table as 'root', create a 'trace' user, and give the 'trace' user READ, WRITE and ALTER_TABLE permissions on the 'trace' table. Then, update trace.user and trace.token.property.password in accumulo-site.xml.
Not sure if you still want the solution or not, what helped me is changing the value of trace.token.property.password to the correct password, i.e., the value of instance.secret for the trace.user 'root' in accumulo-site.xml file.
Or you could open the acccumulo shell using the 'root' user and create a new user inside the shell and then update the values of both the trace user and it's current password.

Liferay: Get URL in portal.normal.vm from properties file

I have problems to read info from properties file "liferay-portal-6.1.0/tomcat-7.0.23/lib/myweb-application.properties" in portal_normal.vm
myweb-application.properties:
redirect.docs.url = http://stackoverflow.com/questions/ask
"liferay-portal-6.1.0/tomcat-7.0.23/webapps/web-theme/templates/portal_normal.vm":
#set ($docsURL = $propsUtil.get("redirect.docs.url")) #language("foot.docs")
Get value of portal-ext.properties
eg. test.name="sachin"
${propsUtil.get("test.name")}
PropsUtil (or $propsUtil) accesses portal.properties, typically configured through portal-ext.properties. So unless you add your myweb-application.properties as an "external properties" file, PropsUtil won't find it.
One way to do this is to add this line to your portal-ext.properties:
include-and-override=/path/to/myweb-application.properties
but make sure it's not using the same keys as portal.properties for different purposes.

java.util.log , using 3 different logger instances/log files, getting .1 .2 etc

I'm trying to figure out why I'm generating multiple versions of my log files (.1, .2 ,etc). My project has a need for 3 separate loggers, I'm using java.util.log and setting up my loggers as follows:
logger = Logger.getLogger("Logger");
logger.addHandler(new FileHandler(logFileName));
statsLogger = Logger.getLogger("StatsLogger");
statsLogger.addHandler(new FileHandler(statsLogFileName));
alarmLogger = Logger.getLogger("AlarmLogger");
alarmLogger.addHandler(new FileHandler(alarmLogFileName));
my logging properties file:
handlers=java.util.logging.ConsoleHandler java.util.logging.FileHandler
java.util.logging.FileHandler.append=true
java.util.logging.FileHandler.level=INFO
java.util.logging.ConsoleHandler.level=INFO
java.util.logging.ConsoleHandler.formatter=com.package.LogFormatter
java.util.logging.FileHandler.formatter=com.package.LogFormatter
This seems to work, well as far as I can tell anyway... things seem to be getting logged to the correct log files. Any ideas on what could be causing this?
Thanks for any ideas
According to the FileHandler javadoc
http://docs.oracle.com/javase/1.4.2/docs/api/java/util/logging/FileHandler.html#FileHandler
Normally the "%u" unique field is set to 0. However, if the
FileHandler tries to open the filename and finds the file is currently
in use by another process it will increment the unique number field
and try again. This will be repeated until FileHandler finds a file
name that is not currently in use. If there is a conflict and no "%u"
field has been specified, it will be added at the end of the filename
after a dot. (This will be after any automatically added generation
number.)
Have you got multiple processes running that are using the same log configuration ? Also check that any old test processes are not showing up in windows process viewer or top.

Categories

Resources