Skip to content

Commit 9ba6991

Browse files
authored
Merge pull request #120 from hereblur/master
Add possibility to set up custom log prefix
2 parents 7f9faf7 + 09524ce commit 9ba6991

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
gin [![wercker status](https://app.wercker.com/status/f413ccbd85cfc4a58a37f03dd7aaa87e "wercker status")](https://app.wercker.com/project/bykey/f413ccbd85cfc4a58a37f03dd7aaa87e)
22
========
33

4-
`gin` is a simple command line utility for live-reloading Go web applications.
5-
Just run `gin` in your app directory and your web app will be served with
6-
`gin` as a proxy. `gin` will automatically recompile your code when it
7-
detects a change. Your app will be restarted the next time it receives an
4+
`gin` is a simple command line utility for live-reloading Go web applications.
5+
Just run `gin` in your app directory and your web app will be served with
6+
`gin` as a proxy. `gin` will automatically recompile your code when it
7+
detects a change. Your app will be restarted the next time it receives an
88
HTTP request.
99

10-
`gin` adheres to the "silence is golden" principle, so it will only complain
10+
`gin` adheres to the "silence is golden" principle, so it will only complain
1111
if there was a compiler error or if you succesfully compile after an error.
1212

1313
## Installation
1414

15-
Assuming you have a working Go environment and `GOPATH/bin` is in your
15+
Assuming you have a working Go environment and `GOPATH/bin` is in your
1616
`PATH`, `gin` is a breeze to install:
1717

1818
```shell
@@ -24,7 +24,7 @@ Then verify that `gin` was installed correctly:
2424
```shell
2525
gin -h
2626
```
27-
## Basic usage
27+
## Basic usage
2828
```shell
2929
gin run main.go
3030
```
@@ -43,18 +43,19 @@ Options
4343
--buildArgs value Additional go build arguments
4444
--certFile value TLS Certificate
4545
--keyFile value TLS Certificate Key
46+
--logPrefix value Setup custom log prefix
4647
--help, -h show help
4748
--version, -v print the version
4849
```
4950

5051
## Supporting Gin in Your Web app
51-
`gin` assumes that your web app binds itself to the `PORT` environment
52-
variable so it can properly proxy requests to your app. Web frameworks
53-
like [Martini](http://github.com/codegangsta/martini) do this out of
52+
`gin` assumes that your web app binds itself to the `PORT` environment
53+
variable so it can properly proxy requests to your app. Web frameworks
54+
like [Martini](http://github.com/codegangsta/martini) do this out of
5455
the box.
5556

5657
## Using flags?
5758
When you normally start your server with [flags](https://godoc.org/flag)
58-
if you want to override any of them when running `gin` we suggest you
59+
if you want to override any of them when running `gin` we suggest you
5960
instead use [github.com/namsral/flag](https://github.com/namsral/flag)
6061
as explained in [this post](http://stackoverflow.com/questions/24873883/organizing-environment-variables-golang/28160665#28160665)

main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ func main() {
106106
EnvVar: "GIN_KEY_FILE",
107107
Usage: "TLS Certificate Key",
108108
},
109+
cli.StringFlag{
110+
Name: "logPrefix",
111+
EnvVar: "GIN_LOG_PREFIX",
112+
Usage: "Log prefix",
113+
Value: "gin",
114+
},
109115
}
110116
app.Commands = []cli.Command{
111117
{
@@ -133,6 +139,9 @@ func MainAction(c *cli.Context) {
133139
immediate = c.GlobalBool("immediate")
134140
keyFile := c.GlobalString("keyFile")
135141
certFile := c.GlobalString("certFile")
142+
logPrefix := c.GlobalString("logPrefix")
143+
144+
logger.SetPrefix(fmt.Sprintf("[%s] ", logPrefix))
136145

137146
// Bootstrap the environment
138147
envy.Bootstrap()
@@ -191,6 +200,9 @@ func MainAction(c *cli.Context) {
191200
}
192201

193202
func EnvAction(c *cli.Context) {
203+
logPrefix := c.GlobalString("logPrefix")
204+
logger.SetPrefix(fmt.Sprintf("[%s] ", logPrefix))
205+
194206
// Bootstrap the environment
195207
env, err := envy.Bootstrap()
196208
if err != nil {

0 commit comments

Comments
 (0)