Log timestamp of an exception in Play? - scala

I have some play code that calls some spark functions. Sometimes things break and I want a timestamp associated to the event. I currently get the error messages printed to STDOUT without a timestamp and am wondering if there's a way to configure the logger.xml to associate timestamps with these??

Providing your logger.xml file would have been helpful but anyways look for the "pattern" element for your STDOUT in the logger.xml file and change it by prepending the %d{ISO8601}
Check the logback configuration documentation for more information.
Logback Configuration

Related

How can i get the current log file name on runtime from tinylog

i am using tinylog 2 and i want to load the current log file content to show it in my gui.
My tinylog.properties looks something like this:
writer=rolling file
writer.file=project_{date: yyyy-MM-dd}.log
So my problem is: How can i get the current filename of the logger file ?
i can resolve it with hard coded java String formatter, but when someone change the properties file it doesn't fit.
Is there a way to get the current resolved logfile name from Tinylog?
Thanks
tinylog 2 does not provide any specific API for receiving the file name. However, feel free to file a feature request on GitHub. As the main contributor of tinylog, I could imagine to implement such feature for tinylog 2 or 3. Especially, I'm thinking about a listener that could automatically inform you about a rollover event and provide the new file name.

Discord.py mod log setup

I was wondering how one could make a command that sets up a mod log for a certain server, or start logging in one that already exists. This will probably require a database or JSON, anything is fine, as long as I can get it to work. Any help would be appreciated.
The way I would do this is with a .txt file that would contain all of the logs. I would add a line every time an event within the guild occurred, you could configure this to whatever events you wanted.
import datetime
#client.event
async def on_member_join(member):
with open("logs.txt", "a") as logsFile:
logsFile.write("\n[{}] {} just joined the server".format(datetime.datetime.now(),
member.name))
If you are currently using the logging module for discord.py or any other libraries, you can also use it for logging your own messages, either using the same or a separate logger.

Logstash scala log parsing

I've got a problem with logstash. I use logback, logstash, kibana and elasticsearch (docker as logstash input source)
The problem is I have no idea how can I write a correct config file for logstash to get some interesting information.
The single scala log looks like this:
[INFO] [05/06/2016 13:58:31.789] [integration-akka.actor.default-dispatcher-14] [akka://integration/user/InstanceSupervisor/methodRouter/outDispatcher] sending msg: PublishMessage(instance,vouchers,Map(filePath -> /home/mateusz/JETBLUETESTING.csv, importedFiles -> Map(JETBLUETESTING.csv -> Map(status -> DoneStatus, processed -> 1, rows -> 5))),#contentHeader(content-type=application/octet-stream, content-encoding=null, headers=null, delivery-mode=2, priority=0, correlation-id=null, reply-to=null, expiration=null, message-id=null, timestamp=null, type=null, user-id=null, app-id=null, cluster-id=null)
I'd like to get something like tag [INFO], timestamp and of course the whole log in a single kibana result.
As for now i don't event know how exactly the log looks like (because its parsed by logback). Any information you can provide me would be greatly appreciated, because im stuck on this problem for few days.
When learning logstash it's best to find a debugger to help experiment (grok) with patterns. The standard appears to be hosted here. The site allows you to post a snippet from your logs, and then allows you to experiment with either pre-defined or custom patterns. The pre-defined patterns can be found here.
I had the same issue recently when trying to find out what logback was sending to logstash. I found that logback was able to convert the logs to json.A snippet I found useful is:
filter{
json{
source => "message"
}
}
Which I found in this related SO post
Once you can see the logs, it makes it much easier to experiment with patterns.
Hope this is useful.

Perl parsing a log4j log [duplicate]

We have several applications that use log4j for logging. I need to get a log4j parser working so we can combine multiple log files and run automated analysis on them. I'm not looking to reinvent the wheel, so can someone point me to a decent pre-existing parser? I do have the log4j conversion pattern if that helps.
If not, I'll have to roll our own.
I didn't realize that Log4J ships with an XML appender.
Solution was: specify an XML appender in the logging configuration file, include that output XML file as an entity into a well formed XML file, then parse the XML using your favorite technique.
The other methods had the following limitations:
Apache Chainsaw - not automated enough
jdbc - poor performance in a high performance distributed app
You can use OtrosLogViewer with batch processing. You have to:
Define you log format, you can use Log4j pattern layout parser or Log4j XmlLayout
Create java class that implements LogDataParsedListener. Method public void logDataParsed(LogData data, BatchProcessingContext context) will be called on every parsed log event.
Create jar
Run OtrosLogViewer with specifying your log processing jar, LogDataParsedListener implementation and log files.
What you are looking for is called SawMill, or something like it.
Log4j log files aren't really suitable for parsing, they're too complex and unstructured. There are third party tools that can do it, I believe (e.g. Sawmill).
If you need to perform automated, custom analysis of the logs, you should consider logging to a database, and analysing that. JDBC ships with the JdbcAppender which appends all messages to a database of your choice, but it has performance implications, and it's a bit flaky. There are other, similar, alternatives on the interweb, though (like this one).
You -can- use Log4j's Chainsaw V2 to process the various log files and collect them into one table, and either output those events as xml or use Chainsaw's built-in expression-based filtering, searching & colorizing support to slice & dice the logs.
Steps:
- Start Chainsaw V2
- Create a chainsaw configuration file by copying the example configuration file available from the Welcome tab - define one LogFilePatternReceiver 'plugin' entry for each log file that you want to process
- Start Chainsaw with that configuration
- Each log file will end up as a separate tab in the UI
- Pause the chainsaw-log tab and clear the events from that tab
- Create a new tab which aggregates the events from the various tabs by going to the 'view, crate custom expression logpanel' menu item and enter 'level >= DEBUG' in the box. It will create a new tab containing events from all of the tabs with level >= debug (which is why you cleared the chainsaw-log tab).
You can get an overview of the expression syntax used to filter, colorize and search from the tutorial (available from the Help menu).
If you don't want to use Chainsaw, you can do something similar - start a simple app that doesn't log but loads a log4j.xml config file with the 'plugin' entries you defined for the Chainsaw configuration, but also define a FileAppender with an xmllayout - all of the events received by the 'receivers' will be sent to the single appender.

Cruise Control .net Changing Log File appereance

i would like to change the apperance of the log file, generated by ccnet. It is useful, if the error messages are separated from the original Log Messages, but in order to debug, it is a bit tricky to see, when the error really happened. Our powershell skript runs for 6-8 hours and creates about 38k lines in the log file, so i would really apprechiate a solution, how i could list the errors with the other lines in the log files. Additionally it would be cool, if all the errors would still appear separatedly.
So far i have not found a lot documentary that explained how to change the log file output...
Simon
Not sure how this is logged, but in the end, logs produced during the build are put into the build-log file, that you will find in artifacts folder.
Then this logs are transposed into html output using xsl transforms. If none of the built-in reports is useful to you, you can create a custom xsl and plug it in, see the dashboard.config file, the following section allows for adding additional xsl transforms:
<buildReportBuildPlugin>
<xslReportBuildPlugin description="MSBuild Log" actionName="MSBuildBuildReport" xslFileName="xsl\MSBuild4Log.xsl"/>
...
If you know what the error messages are going to be you can parse them with an xsl file and generate some html that will show up in the build emails. The following goes in ccservice.exe.config.
<xslFiles>
<file name="c:\path\to\custom_errors.xsl"/>
</xslFiles>
custom_errors.xsl is an xsl file that finds the error messages in the raw build log xml and then generates html from them. This html will show up in the build emails. You have to create custom_errors.xsl. It's a significant amount of work to get working the first time especially if you're new to xml/xsl/html/css. If you undertake this I suggest doing all the testing outside of ccnet using a xsl transformer and inputting a sample ccnet build log. ccnet uses a css file to style the html so be aware of that. You can edit this too.
Note you have to restart the ccnet service after editing ccservice.exe.config.