In the summary of CocoaLumberjack it is mentioned that "Lumberjack is Powerful", and then "Want more? Create your own loggers (it's easy) and send your log statements over the network."
So, I wonder how can we send log statements over the network through CocoaLumberjack?
Is there an existing interface to do this? Or must we do it by our own code?
Could somebody give me sample code to this?
To answer your question, there isn't anything built-in for sending logs over the network.
You can take the highroad and:
obtain the logs by creating a new logger (see how this guy created a new logger that redirects the logs to Crashlytics: https://github.com/TechSmith/CrashlyticsLumberjack)
OR
read the logs from a file logger and sending those over the network.
Use the DDFileLogger logFileManager to get the sortedLogFilePaths (list of paths to the log files). Those files are plain text and can be read like any other file.
Related
We are trying to switch completely from log4net to Serilog. However, this part of functionality seems to be missing. What I need is to be able to get location of log-files Inside a library class. This is important for our Desktop Click-Once application because that location is different on different OSes and for different users. When user needs access to the logs we can direct him to the proper folder.
Very similar question was asked here:
Read current Serilog's configuration
But I can't believe that there is no way to get this information from Serilog. I don't need to change that configuration - just read it. In log4net we could do:
log4net.LogManager.GetAllRepositories()
and then
repository.Root.Appenders.OfType<FileAppender>
Please tell me that there is some kind back-door to the current LoggerConfiguration or if there is some alternative way to get file-path of the current File-Sink.
Serilog does not expose the list of Sinks that have been configured, so your only option at the moment would be to use Reflection if you really want to get this information from the live Serilog configuration.
You can see an example on this answer:
Unit test Serilog configuration
That said, given all you want to do is to know the path where log files are being written, that's something you can easily store at the start of the application at the moment you set up your Serilog logging pipeline.
If you configure the file path in code, you can store that information in a static property somewhere your entire app can access. If you get your folder path from the appSettings.json or App.config, you can read the information from there.
If you have environment variables in your configuration you can get the same values that Serilog gets by expanding these environment variables e.g. Environment.ExpandEnvironmentVariables("%LogPath%\\AppName.log")
I need to understand how to enable logging using google ads api client library for php (https://github.com/googleads/google-ads-php/).
I need to see the raw json messages exchanged with Google for debugging purposes.
Even if I followed all the instruction and set up the logger properly I can not see anywhere the request/response json neither in stderr neither in file location.
I already looked at the documentation but I can not find any flag to enable logging. I set level to NOTICE then DEBUG but no informations are written.
I set the LOGGING configuration as per below:
[LOGGING]
; Optional logging settings.
logFilePath = "/tmp/log_google_api.log"
logLevel = "DEBUG"
I was expected to get the messages in std err, any suggests?
For debugging gRPC, you can set the environment variable for dumping gRPC logs. https://github.com/grpc/grpc/blob/master/doc/environment_variables.md
For example:
export GRPC_VERBOSITY=DEBUG
export GRPC_TRACE=http
As the https://github.com/neo4j-examples/neo4j-procedure-template/blob/3.3/src/main/java/example/FullTextIndex.java shows, the example shows a public Log log; field but barely use it.
In my case, I use this field to print some log but find it in nowhere, so where is it? And what's more, can I just print the log on the junit console?
Use log.info("message") in your code and go to Neo4j/Logs is in Logs folder neo4j.log file.
Answer by myself:
According to the source code, the logs for harness is saved in /tmp/xxxx/neo4j.log
And the neo4j.log is hard code, I cannot find a way to redirect it to the standard system.out.
Or I can just use System.out.print() in my code, but since this part is not a test code, use System.out.print() only for harness test is a bad idea.
I'll come back if I found a way to redirect the neo4j to System.out
I am working on a monitoring app and I have to pass in at startup some initial configuration which consists of a couple of lists of IP addresses. What's the OTP way to pass this data to the application - through the .app file or is there any other general accepted way?
Use an Erlang configuration file:
A configuration file contains values for configuration parameters for
the applications in the system. The erl command line argument -config
Name tells the system to use data in the system configuration file
Name.config.
Configuration parameter values in the configuration file will override
the values in the application resource files (see app(4)). The values
in the configuration file can be overridden by command line flags (see
erl(1)).
The value of a configuration parameter is retrieved by calling
application:get_env/1,2.
If you need to override them at runtime, you can use application:set_env/3, but with care.
you can handle configuration in several ways.
here a link to another stackoverflow topic
IMHO i suggest .app file, or you can use a configuration file (here another link to stackoverflow topic)
I would create a name gen_server process that has a list of ip addresses as it's state. In the init of the server a predefined list would be read from a file using file:consult and used as the initial state of the server. To get the list of ip addresses from this named gen_server, a handle_call(get_ip, _From, State) needs to be implemented.
This way you prevent shared global state, which gives you great Erlang karma, and have a better starting point for added functionality like runtime ip address changes.
Use a file in which you have your data as erlang terms. However you need to protect the file. Reading from the file at start up use: file:consult/1. If modification of the file will occur by the user or system administrator, use the following functions to protect or refuse access to the file:
-include_lib("kernel/include/file.hrl").
protect_file(File)->
{_,File_info} = file:read_file_info(File),
file:write_file_info(File,File_info#file_info{access = read,mode = 33060}).
unprotect_file(File)->
{_,File_info} = file:read_file_info(File),
file:write_file_info(File,File_info#file_info{access = read_write,mode = 33206}).
Use function protect_file/1 to make the file read-only. If you need to make the file writable then modify using unprotect_file/1. A file with erlang terms is easier because you do not need parsing.You could also write you configurations as JSON objects or XML data into a file. In summary, using a file for all you configs will be better managed by your application and those who interact with it. An example is the ejabberd.cfg file, the config file for ejabberd server. Its easiest with a file with erlang terms because you can comment here and there for the system administrator to see other available options about a certain configuration.
I want to write to/delete a file but sometimes I get a crash if the file is in use by another program. How do I check to see whether the file is opened by another process or I can open it for writing?
The problem is, that between the time you check to see if you could get exclusive access and opening the file, something else gets exclusive access to the file, and you get the exception anyway.
The only fool proof way to see if you can get an exclusive lock on a file is to try and get an exclusive lock on the file, if you get it you have it.
If not, you catch the exception, and either
Go do something else
Wait a while and try again
It's one of life’s situations where it's better to ask for forgiveness than permission :)
There is a new way to get the origin of file locking for Vista and up here:
http://www.remkoweijnen.nl/blog/2011/01/03/cannot-access-files-but-need-the-origin/
UserMode:
The best way to write to a locked file is to ask the user to close it in the other process. In batch processes you should ignore such a file and log the problem. Providing the name of the other process is a very good way to find a solution for the user.
Not sure in which programming language you'd like to check if you can write to a file. In Java, java.io.File.canWrite() can do the job for you.
General:
In UNIX-like OS, you can use the lsof command.
If you want to see which program holds a handle to your file, use the Process Monitor (download from MicroSoft).
This tool has a command line interface, so you could use your language's scripting interface (for example java.lang.Process) to run the tool and display a useful error message.
IsFileInUse as given in http://delphi.about.com/cs/adptips1999/a/bltip0999_3.htm